System.Runtime.InteropServices.COMException (0x800A03EC): This command is unavailable because the license to use this application has expired.

Visual Studio182
hi,

One of my client got error while Exporting data from datatable to excel

sheet.He got error Like

this"System.Runtime.InteropServices.COMException (0x800A03EC): This

command is unavailable because the license to use this application has

expired." He told me that his linense was not expired and also he try

same after installed again office



I was used Com Component for exporting data to excel :microsoft office

9.0 through add refereance -com





and function from where Actually Excel Export is Like this





======

Public Sub Export2Excel(ByVal dt As DataTable, ByVal strPath As String)

Dim objXL As Excel.Application

Dim objWBS As Excel.Workbooks

Dim objWB As Excel.Workbook

Dim objWS As Excel.Worksheet

Dim colIndex As Integer

Dim rowIndex As Integer

Dim col As DataColumn

Dim mRow As DataRow

're-set pb so it displays correctly if called again

Try

If File.Exists(strPath) Then

File.Delete(strPath)

End If

Try

'get a running instance of Excel - this minimizes the

number of instances of Excel in memory!

objXL = CType(GetObject(, "Excel.Application"),

Excel.Application)

Catch ex As Exception

'create a new instance of Excel if there isn't one

running.

objXL = New Excel.Application

End Try

objWBS = objXL.Workbooks

objWB = objWBS.Add

objWS = CType(objWB.Worksheets(1), Excel.Worksheet)

'write column headers to Excel's first row from the dt.

For Each col In dt.Columns

colIndex += 1

objWS.Cells(1, colIndex) = col.ColumnName

Next col

'Bold and widen all the column headings

objWS.Range("A1:X1").Font.Bold = True

objWS.Columns.ColumnWidth = 10.5

'make some columns wider than the others

objWS.Range("A1:Q1").Font.Bold = True

objWS.Range("A:A").ColumnWidth = 17

objWS.Range("C:C").ColumnWidth = 39

objWS.Range("E:F").ColumnWidth = 20

objWS.Range("L:O").ColumnWidth = 20

objWS.Range("T:T").ColumnWidth = 13

'rename the sheet to the file name w/o extension

objWS.Name = Path.GetFileName(strPath)

'write data starting on row with column headers because the

first step is to increment to the next row.

rowIndex = 1

For Each mRow In dt.Rows



rowIndex += 1

colIndex = 0

For Each col In dt.Columns

colIndex += 1

'force to text data by adding a leading apostrophe

objWS.Cells(rowIndex, colIndex) =

mRow(col.ColumnName).ToString

Next col

Next mRow

'make all rows same height

objWS.Range("A1:A" & CStr(dt.Rows.Count)).RowHeight = 12.75

objWB.SaveAs(strPath)

objWB.Close()



System.Runtime.InteropServices.Marshal.ReleaseComObject(objWS)



System.Runtime.InteropServices.Marshal.ReleaseComObject(objWB)



System.Runtime.InteropServices.Marshal.ReleaseComObject(objWBS)

objXL.Quit()



System.Runtime.InteropServices.Marshal.ReleaseComObject(objXL)

Catch exc As Exception

Throw

Finally

objWS = Nothing

objWB = Nothing

objWBS = Nothing

objXL = Nothing

End Try

End Sub

=====


-