Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
System.Runtime.InteropServices.COMException (0x800A03EC)
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.ReleaseComO bject(objWS) System.Runtime.InteropServices.Marshal.ReleaseComO bject(objWB) System.Runtime.InteropServices.Marshal.ReleaseComO bject(objWBS) objXL.Quit() System.Runtime.InteropServices.Marshal.ReleaseComO bject(objXL) Catch exc As Exception Throw Finally objWS = Nothing objWB = Nothing objWBS = Nothing objXL = Nothing End Try End Sub ===== |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Chart.Export throws COMException (0x800A03EC) | Charts and Charting in Excel | |||
System.Runtime.InteropServices.COMException (0x80020005) in excel 2k7, but worked well in 2k3 | Excel Programming | |||
I get COMException while exporting chart on IIS 6.0. | Charts and Charting in Excel | |||
Excel SaveCopyAs COMException 0x800A03EC | Excel Programming | |||
Chart.Export throws COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC. | Excel Programming |