我用着visual studio 2013 ultimate.
我想update datagridview 里的data去已经存在的excel file.
因为会持续性的update,所以不可以固定rows 和 columns.
- If My.Computer.FileSystem.FileExists("d:\test1.xlsx") Then
- Try
- Dim xls As New Excel.Application
- Dim Wbook As Excel.Workbook
- Dim Wsheet As Excel.Worksheet
- xls.Workbooks.Open("d:\test1.xlsx")
- Wbook = xls.ActiveWorkbook
- Wsheet = Wbook.ActiveSheet
- Dim i As Integer = 0
- If lastrow >= 10 Then
- Dim curRow As Integer = lastrow + 1
- For rowlength As Integer = 0 To DataGridView1.Rows.Count - 1
- For columnlength As Integer = 0 To DataGridView1.Columns.Count - 1
- Wsheet.Cells(curRow, columnlength + 1).Value =
- DataGridView1.Rows(rowlength).Cells(columnlength).Value
- Next
- Next
- End If
- Wbook.Save()
- xls.closed()
- Catch ex As Exception
- MsgBox(ex.ToString)
- End Try





