Dim workbook As Infragistics.Documents.Excel.Workbook = _ Infragistics.Documents.Excel.Workbook.Load("C:\ExistingWorkbook.xlsx") workbook.Worksheets.Item(0).Rows.Item(0).Cells.Item(0).Value = 19 workbook.Save("C:\ModifiedWorkbook.xlsx")
In addition to writing out Microsoft® Excel® files, the Infragistics.Documents.Excel assembly can also read them. When an Excel file is read with the static Load method, a Workbook object is created and its entire object model is populated with all supported information from the file.
If you are loading a workbook of a particular format and you would like to save it as another format, you can use the SetCurrentFormat method of the Infragistics.Documents.Excel.Workbook class. Also, the CurrentFormat property can be used to get the current workbook format.
For more information on project dependencies and references when loading and saving to the xlsx format, please review the topic Office® 2007 xlsx file generation references and dependencies.
The following code demonstrates how to read in an existing XLSX workbook, make a change, and write the workbook to a new file:
In Visual Basic:
Dim workbook As Infragistics.Documents.Excel.Workbook = _ Infragistics.Documents.Excel.Workbook.Load("C:\ExistingWorkbook.xlsx") workbook.Worksheets.Item(0).Rows.Item(0).Cells.Item(0).Value = 19 workbook.Save("C:\ModifiedWorkbook.xlsx")
In C#:
Infragistics.Documents.Excel.Workbook workbook = Infragistics.Documents.Excel.Workbook.Load( "C:\\ExistingWorkbook.xlsx" ); workbook.Worksheets[0].Rows[0].Cells[0].Value = 19; workbook.Save( "C:\\ModifiedWorkbook.xlsx" );