The Infragistics Excel library enables you to define template files in three file formats. The three template formats are the Excel Template format (with extension XLTX), the Excel Macro-Enabled Template format (with extension XLTM), and the Excel 97-2003 Template format (with extension XLT). You can save and load files in these formats.
The pick:[win-forms=" WorkbookFormat"] pick:[asp-net=" WorkbookFormat"] pick:[win-forms-old=" WorkbookFormat"] pick:[aspnet-old=" WorkbookFormat"] enumeration has the values Excel2007Template, Excel2007MacroEnabledTemplate, and Excel97To2003Template that correspond to the XLTX, XLTM, and XLT formats. The pick:[win-forms=" CurrentFormat"] pick:[asp-net=" CurrentFormat"] pick:[win-forms-old=" CurrentFormat"] pick:[aspnet-old=" CurrentFormat"] property can be used to get the current format of the file. When loading a file if the extension is unknown, the contents of the file will be parsed to dynamically determine the correct format.
The following code illustrates saving an Excel file in the Excel2007Template format using the pick:[win-forms=" Save"] pick:[asp-net=" Save"] pick:[win-forms-old=" Save"] pick:[aspnet-old=" Save"] method.
In Visual Basic:
' Create a workbook and set its format to Excel2007Template Dim newWorkBook As Infragistics.Documents.Excel.Workbook = New Workbook(WorkbookFormat.Excel2007Template) ' Add a worksheet to the workbook Dim worksheet1 As Infragistics.Documents.Excel.Worksheet = newWorkBook.Worksheets.Add("Sheet1") ' Format a cell in the worksheet worksheet1.Rows(1).Cells(1).CellFormat.FillPatternBackgroundColor = Color.Red ' Save the workbook newWorkBook.Save("C:\ExcelBookTemplate.xltx")
In C#:
// Create a workbook and set its format to Excel2007Template Infragistics.Documents.Excel.Workbook newWorkBook = new Workbook(WorkbookFormat.Excel2007Template); // Add a worksheet to the workbook Infragistics.Documents.Excel.Worksheet worksheet1 = newWorkBook.Worksheets.Add("Sheet1"); // Format a cell in the worksheet worksheet1.Rows[1].Cells[1].CellFormat.FillPatternBackgroundColor = Color.Red; // Save the workbook newWorkBook.Save("C:\\ExcelBookTemplate.xltx");
The following code shows you how to modify the format of an Existing Excel file using the pick:[win-forms=" SetCurrentFormat"] pick:[asp-net=" SetCurrentFormat"] pick:[win-forms-old=" SetCurrentFormat"] pick:[aspnet-old=" SetCurrentFormat"] method.
In Visual Basic:
' Load an Existing Excel file Dim workbook As Infragistics.Documents.Excel.Workbook = Infragistics.Documents.Excel.Workbook.Load("C:\Book1.xlsx") ' Change the format to Excel2007Template workbook.SetCurrentFormat(WorkbookFormat.Excel2007Template) ' Save the file in the modified format workbook.Save("C:\ModifiedBook1.xltx")
In C#:
// Load an Existing Excel file Infragistics.Documents.Excel.Workbook workbook = Infragistics.Documents.Excel.Workbook.Load("C:\\Book1.xlsx"); // Change the format to Excel2007Template workbook.SetCurrentFormat(WorkbookFormat.Excel2007Template); // Save the file in the modified format workbook.Save("C:\\ModifiedBook1.xltx");