[]
        
(Showing Draft Content)

Import and Export Excel Templates

This section summarizes how GcExcel.NET handles the import and export of Excel files containing templates (.xltx file).

GcExcel.NET allows users to load and save spreadsheets containing templates without any hassles. Excel templates are pre-designed spreadsheets that help to create spreadsheets with the same layout, formatting, and formulas without having to recreate the basic elements each time, thereby saving significant amounts of time while working with spreadsheets. Now, users can load such spreadsheets in GcExcel directly as Xltx files, modify them easily and quickly, and then save them back.

GcExcel.NET also provides various import and export options, which can be accessed from the properties present in XltxOpenOptions and XltxSaveOptions classes. For more information about import and export options provided by GcExcel, see Import and Export Excel Options.

When the OpenFileFormat is Xltx, templates will be imported. When the SaveFileFormat is Xltx, templates will be exported.

Refer to the following example code in order to import and export Xltx document from the file name.

// Create a new workbook.
var workbook = new GrapeCity.Documents.Excel.Workbook();

// Open xltx file.
workbook.Open(Path.Combine("Resources", "excel-loan-calculator.xltx"), OpenFileFormat.Xltx);

// Save workbook as xltx file.
workbook.Save("Exported.xltx", SaveFileFormat.Xltx);

Refer to the following example code in order to import and export Xltx document from a file stream.

// Create a new file stream to open a file.
using FileStream openFile = new FileStream(Path.Combine("Resources", "excel-loan-calculator.xltx"), FileMode.OpenOrCreate, FileAccess.Read);

// Create a new workbook.
var streamworkbook = new GrapeCity.Documents.Excel.Workbook();

// Open xltx file.
streamworkbook.Open(openFile, OpenFileFormat.Xltx);

// Create a new file stream to save a file.
using FileStream saveFile = new FileStream("Exported-Stream.xltx", FileMode.OpenOrCreate, FileAccess.ReadWrite);
            
// Save workbook as xltx file.
streamworkbook.Save(saveFile, SaveFileFormat.Xltx);