oralb5
09-22-2004, 01:28 PM
I am exporting a datagrid/datasource from my application using the code below. However, the user will be allowed to determine the number of records to select so I was wondering if anybody knew of a way to insert blank rows into a spreadsheet before I proceed with the export of the data.
Any ideas/suggestions would be appreciated. Thanks.
Dim excelApp As Excel.Application
Try
excelApp = GetObject(, "Excel.Application")
Catch ex As Exception
excelApp = New Excel.Application
End Try
Dim excelBook As Excel.Workbook = excelApp.Workbooks.Open(s)
Dim excelWorksheet As Excel.Worksheet = CType(excelBook.Worksheets(1), Excel.Worksheet)
With excelWorksheet
Dim dr As DataRow
Dim dc As DataColumn
z = -1
For Each dc In d.Tables(grid.DataSource.ToString).Columns
z += 1
i = 3
For Each dr In d.Tables(grid.DataSource.ToString).Rows
.Range(Chr(66 + z) & i.ToString).Value = dr(z)
i += 1
If i = 20 Then Exit For
Next
Next
End With
excelApp.Visible = True
excelWorksheet = Nothing
excelBook = Nothing
excelApp = Nothing
GC.Collect()
Any ideas/suggestions would be appreciated. Thanks.
Dim excelApp As Excel.Application
Try
excelApp = GetObject(, "Excel.Application")
Catch ex As Exception
excelApp = New Excel.Application
End Try
Dim excelBook As Excel.Workbook = excelApp.Workbooks.Open(s)
Dim excelWorksheet As Excel.Worksheet = CType(excelBook.Worksheets(1), Excel.Worksheet)
With excelWorksheet
Dim dr As DataRow
Dim dc As DataColumn
z = -1
For Each dc In d.Tables(grid.DataSource.ToString).Columns
z += 1
i = 3
For Each dr In d.Tables(grid.DataSource.ToString).Rows
.Range(Chr(66 + z) & i.ToString).Value = dr(z)
i += 1
If i = 20 Then Exit For
Next
Next
End With
excelApp.Visible = True
excelWorksheet = Nothing
excelBook = Nothing
excelApp = Nothing
GC.Collect()