Reconstruct the computer room "Export Excel Exception"

Source: Internet
Author: User

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"

Related Article

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.