Worksheet and cell design
On this page
Excel.ApplyWorksheetDesign sets widths, frozen panes, filters and print options on a completed XLSX. Complete writing and dispose the writer before calling it.
using TExcel;
Excel.SaveAs("report.xlsx", new[] { new { Code = "P-001", Name = "Inlet pump" } });
Excel.ApplyWorksheetDesign("report.xlsx", new ExcelWorksheetDesign
{
WorksheetIndex = 1,
FrozenRowCount = 1,
FrozenColumnCount = 1,
AutoFilter = true,
RepeatHeaderRow = true,
FitToPageWidth = true,
Landscape = true,
Columns =
[
new() { WidthPixels = 160 },
new() { WidthPixels = 240, WrapText = true }
],
CellFills = [new() { RowNumber = 2, ColumnNumber = 1, Color = "#FFF1CC" }]
});Parameters
| Parameter | Contract |
|---|---|
WorksheetIndex | One-based worksheet index, default 1 |
Columns | Positional width, number format and wrapping settings |
WidthPixels | Width in pixels, converted to OpenXML column units |
NumberFormat | Numeric display format; original values remain unchanged |
WrapText | Wrap to column width and expand actual row height |
FrozenRowCount, FrozenColumnCount | Consecutive rows from the top and columns from the left |
AutoFilter | Filter the actual data rectangle using the first row as headers |
RepeatHeaderRow | Repeat the first row when printing |
FitToPageWidth, Landscape | Fit to one printed page width and use landscape orientation |
CellFills | One-based absolute row/column coordinates and #RRGGBB colors |
Stream requirements
The stream overload requires a complete XLSX and a readable, writable, seekable stream. The caller owns stream disposal.
using var content = new FileStream("report.xlsx", FileMode.Open, FileAccess.ReadWrite);
Excel.ApplyWorksheetDesign(content, new ExcelWorksheetDesign { FrozenRowCount = 1 });Display formatting does not change stored text identifiers or calculate formulas.