-
Notifications
You must be signed in to change notification settings - Fork 302
Save as template(.xltx, .xltm)
EPPlus can save packages as an Excel template instead of an standard workbook.
An excel template(.xltx) is a template for new workbooks. When opening the template workbook, Excel creates a new copied workbook from the template while the original .xltx file remains unchanged.
Lets show an example. Set the SaveAsTemplate property on the package
using (var package = new ExcelPackage())
{
package.SaveAsTemplate = true;
package.SaveAs(new FileInfo(@"c:\workbooks\InvoiceTemplate.xltx"));
}Or supply it through the save options:
package.SaveAs(new FileInfo(@"c:\workbooks\InvoiceTemplate.xltx"), o => o.SaveAsTemplate = true);The options overload is available on Save, SaveAs (file path, FileInfo and Stream) and their async equivalents.
SaveAsTemplate is false by default, also when the loaded file is a template. Loading an .xltx and saving it again therefore produces a standard workbook, which mirrors how Excel handles templates. Set SaveAsTemplate to true if you want to keep the template format:
using (var package = new ExcelPackage(new FileInfo(@"c:\temp\InvoiceTemplate.xltx")))
{
package.SaveAsTemplate = true; // keep it a template
package.Save();
}SaveAsTemplate controls the content type inside the package; the file name is up to you. Use a matching extension (.xltx / .xltm) so that Excel and other tools handle the file as expected.
EPPlus Software AB - https://epplussoftware.com
- What is new in EPPlus 5+
- Breaking Changes in EPPlus 5
- Breaking Changes in EPPlus 6
- Breaking Changes in EPPlus 7
- Breaking Changes in EPPlus 8
- Addressing a worksheet
- Dimension/Used range
- Copying ranges/sheets
- Insert/Delete
- Filling ranges
- Sorting ranges
- Taking and skipping columns/rows
- Data validation
- Comments
- Freeze and Split Panes
- Header and Footer
- Hyperlinks
- Autofit columns
- Grouping and Ungrouping Rows and Columns
- Formatting and styling
- The ExcelRange.Text property
- Conditional formatting
- Using Themes
- Working with custom named table- or slicer- styles
-
Formula Calculation
- Security considerations
- Circular references
- Referencing tables in formulas
- Supported Functions
- Dynamic array formulas
- Legacy array formulas
- Lambda functions
- Regression analysis functions
- Custom functions for calculations
- Function prefixes
- Precision as Displayed
- Cancelling a calculation
- Trim reference operator
- Working with filters
- Working with slicers
- Working with External Workbooks