Skip to Content
TExcelWorksheet and cell design

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

ParameterContract
WorksheetIndexOne-based worksheet index, default 1
ColumnsPositional width, number format and wrapping settings
WidthPixelsWidth in pixels, converted to OpenXML column units
NumberFormatNumeric display format; original values remain unchanged
WrapTextWrap to column width and expand actual row height
FrozenRowCount, FrozenColumnCountConsecutive rows from the top and columns from the left
AutoFilterFilter the actual data rectangle using the first row as headers
RepeatHeaderRowRepeat the first row when printing
FitToPageWidth, LandscapeFit to one printed page width and use landscape orientation
CellFillsOne-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.