Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
530
Error trying to Load Excel Template
posted

 I'm trying to use Infragistics to create an Excel file from another Excel file with the following code:

Dim wb As New  Infragistics.Excel.Workbook
wb.Load(
"c:\exceltemplate.xls")  

Dim ws As Infragistics.Excel.Worksheet = wb.Worksheets("sheet1")  

Dim rowIndex As Integer = 1  

For Each drow As DataRow In dt.Rows 

Dim row As  Infragistics.Excel.WorksheetRow = ws.Rows.Item(rowIndex)

rowIndex = rowIndex + 1

 

For columnIndex As Integer = 0 To  drow.ItemArray.Length - 1

row.Cells.Item(columnIndex).Value = drow.ItemArray(columnIndex)

 

Next 

Next

 

 

wb.Save("c:\exceltest.xls")

The file c:\exceltemplate.xls has 1 sheet called "sheet1" with some column headers in it. It errors on the line "Dim ws As Infragistics.Excel.Worksheet = wb.Worksheets("sheet1")" because wb has no worksheets in it so the load appears to be doing nothing.  Am I doing something wrong?

Thanks