In the refactoring room, an exception occurred while completing the Excel export function.
When you run the statement to export Excel:
<span style= "FONT-FAMILY:KAITI_GB2312;FONT-SIZE:24PX;" >xlapp.cells (rowindex, Colindex) = row (col. ColumnName) </span>
when theShow Exceptions:
for this reason, the special search solution, here with you to share, also please master more advice Ah!
Cause: This exception occurs because the program conflicts when it runs the call delivery address.
Workaround: replace the source code with the code.
<span style= "FONT-FAMILY:KAITI_GB2312;FONT-SIZE:24PX;" >dim Myexcel as NewMicrosoft.Office.Interop.Excel.Application () MyExcel.Application.Workbooks.Add (True) myexcel.visible = True ' To export the field names in DataGridView Dim m as Integer for m = 0 to datagridview1.columncount-1< C5/>myexcel.cells (1, m + 1) = Me.DataGridView1.Columns (M). HeaderText Next m ' Add data to Excel Table Dim i As Integer for i = 0 to Datagridview1.rowcount-1 Dim J As Int Eger for j = 0 to Datagridview1.columncount-1 If Me.datagridview1 (J, i). Valueis System.DBNull.Value then myexcel.cells (i + 2, j + 1) = "" " Else myexcel.cells (i + 2, j + 1) = DataGrid View1 (J, i). Value.tostring End If next J Next i</span>
Reconstruct the computer room "Export Excel Exception"