Refactor Data Center: "EXCEL export exception", Refactor data center export excel

Source: Internet
Author: User

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>



 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.