Refactor Data Center: "EXCEL export exception", refactor data center export excel
An exception occurred when the data center was restructured and the EXCEL export function was completed.
When you run the statement to export an EXCEL file:
<span style="font-family:KaiTi_GB2312;font-size:24px;">xlApp.Cells(rowindex, colindex) = row(col.ColumnName)</span>
Exception:
Here, I would like to share with you the reason and solution. Please give me more advice!
Cause:This exception occurs when the program runs the call transfer address conflict.
Solution: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' export field names in the dview didim As Integer For m = 0 To DataGridView1.ColumnCount-1 MyExcel. cells (1, m + 1) = Me. dataGridView1.Columns (m ). headerText Next m' add data Dim I As Integer For I = 0 To DataGridView1.RowCount-1 Dim j As Integer For j = 0 To DataGridView1.ColumnCount-1 If Me To the excel table. dataGridView1 (j, I ). valueIs System. DBNull. value Then MyExcel. cells (I + 2, j + 1) = "" Else MyExcel. cells (I + 2, j + 1) = maid (j, I ). value. toString End If Next j Next I </span>