Table of Contents

Class RowWriter

Namespace
SheetStream
Assembly
SheetStream.dll

Writes the cells of the current row, left to right. One instance exists per worksheet and is reused for every row, so writing a cell allocates nothing beyond what the XML writer buffers.

public sealed class RowWriter
Inheritance
RowWriter
Inherited Members

Remarks

Every Write* method returns the writer so calls can be chained: sheet.Row().WriteCell("Total").WriteCell(1234.5, money). Cells are placed at consecutive columns starting at A; use Skip(int) to leave gaps.

Properties

NextColumn

1-based index the next cell will be written to.

public int NextColumn { get; }

Property Value

int

RowIndex

1-based index of the row being written.

public int RowIndex { get; }

Property Value

int

Methods

Skip(int)

Leaves count columns empty.

public RowWriter Skip(int count = 1)

Parameters

count int

Returns

RowWriter

WriteCell(bool, CellStyle?)

Writes a boolean cell (shown as TRUE / FALSE).

public RowWriter WriteCell(bool value, CellStyle? style = null)

Parameters

value bool
style CellStyle

Returns

RowWriter

WriteCell(DateTime, CellStyle?)

Writes a date cell. Excel stores dates as serial numbers, so the value is written as ToOADate() and, when no style is given, formatted with a built-in date or date-time format depending on whether the value has a time component.

public RowWriter WriteCell(DateTime value, CellStyle? style = null)

Parameters

value DateTime
style CellStyle

Returns

RowWriter

WriteCell(DateTimeOffset, CellStyle?)

Writes the local date-time of a DateTimeOffset; the offset itself is not stored (Excel has no time zones).

public RowWriter WriteCell(DateTimeOffset value, CellStyle? style = null)

Parameters

value DateTimeOffset
style CellStyle

Returns

RowWriter

WriteCell(decimal, CellStyle?)

Writes a numeric cell. Excel keeps 15 significant digits.

public RowWriter WriteCell(decimal value, CellStyle? style = null)

Parameters

value decimal
style CellStyle

Returns

RowWriter

WriteCell(double, CellStyle?)

Writes a numeric cell. NaN and infinities become the #NUM! error, which is what Excel shows for them.

public RowWriter WriteCell(double value, CellStyle? style = null)

Parameters

value double
style CellStyle

Returns

RowWriter

WriteCell(int, CellStyle?)

Writes a numeric cell.

public RowWriter WriteCell(int value, CellStyle? style = null)

Parameters

value int
style CellStyle

Returns

RowWriter

WriteCell(long, CellStyle?)

Writes a numeric cell. Values beyond 2^53 lose precision in Excel, which stores all numbers as doubles.

public RowWriter WriteCell(long value, CellStyle? style = null)

Parameters

value long
style CellStyle

Returns

RowWriter

WriteCell(object?, CellStyle?)

Writes a value of runtime-determined type, dispatching to the typed overloads. Numbers, booleans, dates, time spans, strings and rich text are written natively; anything else is written as its invariant string representation. null and DBNull leave the column empty.

public RowWriter WriteCell(object? value, CellStyle? style = null)

Parameters

value object
style CellStyle

Returns

RowWriter

WriteCell(float, CellStyle?)

Writes a numeric cell.

public RowWriter WriteCell(float value, CellStyle? style = null)

Parameters

value float
style CellStyle

Returns

RowWriter

WriteCell(string?, CellStyle?)

Writes a text cell. null leaves the column empty. By default the text goes through the shared string table; see UseSharedStrings.

public RowWriter WriteCell(string? value, CellStyle? style = null)

Parameters

value string
style CellStyle

Returns

RowWriter

WriteCell(TimeSpan, CellStyle?)

Writes a duration as a fraction of days with the [h]:mm:ss format unless a style is given.

public RowWriter WriteCell(TimeSpan value, CellStyle? style = null)

Parameters

value TimeSpan
style CellStyle

Returns

RowWriter

WriteCells(CellStyle?, IEnumerable<object?>)

Writes several cells from left to right, all with the same style.

public RowWriter WriteCells(CellStyle? style, IEnumerable<object?> values)

Parameters

style CellStyle
values IEnumerable<object>

Returns

RowWriter

WriteCells(params object?[])

Writes several cells from left to right using WriteCell(object?, CellStyle?).

public RowWriter WriteCells(params object?[] values)

Parameters

values object[]

Returns

RowWriter

WriteEmpty(CellStyle?)

Writes a cell that has a style but no value (useful for coloured filler cells).

public RowWriter WriteEmpty(CellStyle? style = null)

Parameters

style CellStyle

Returns

RowWriter

WriteFormula(string, CellStyle?)

Writes a formula cell, e.g. "SUM(C2:C101)". A leading = is removed. By default no cached result is stored; the workbook asks Excel to recalculate on open, so the value appears when the file is opened in Excel. With CacheFormulaResults(bool) enabled, simple aggregates over cells already written get their result stored too, so tools that do not calculate (viewers, ExcelReader, other libraries) show it. Pass the value yourself with the other overloads when you already know it.

public RowWriter WriteFormula(string formula, CellStyle? style = null)

Parameters

formula string
style CellStyle

Returns

RowWriter

WriteFormula(string, bool, CellStyle?)

Writes a formula with a precomputed boolean result.

public RowWriter WriteFormula(string formula, bool cachedValue, CellStyle? style = null)

Parameters

formula string
cachedValue bool
style CellStyle

Returns

RowWriter

WriteFormula(string, double, CellStyle?)

Writes a formula with a precomputed numeric result that non-calculating readers will see.

public RowWriter WriteFormula(string formula, double cachedValue, CellStyle? style = null)

Parameters

formula string
cachedValue double
style CellStyle

Returns

RowWriter

WriteFormula(string, string, CellStyle?)

Writes a formula with a precomputed text result.

public RowWriter WriteFormula(string formula, string cachedValue, CellStyle? style = null)

Parameters

formula string
cachedValue string
style CellStyle

Returns

RowWriter

Writes a text cell that links to a web page, file or e-mail address (mailto:). The built-in Hyperlink style is used unless another style is given.

public RowWriter WriteHyperlink(string text, string url, CellStyle? style = null, string? tooltip = null)

Parameters

text string
url string
style CellStyle
tooltip string

Returns

RowWriter

WriteInlineString(string?, CellStyle?)

Writes a text cell inline in the sheet instead of through the shared string table. Use for values that are unlikely to repeat (free text, GUIDs) to keep the table small.

public RowWriter WriteInlineString(string? value, CellStyle? style = null)

Parameters

value string
style CellStyle

Returns

RowWriter

Writes a text cell that jumps to a place in this workbook, e.g. "'Summary'!A1".

public RowWriter WriteInternalLink(string text, string location, CellStyle? style = null, string? tooltip = null)

Parameters

text string
location string
style CellStyle
tooltip string

Returns

RowWriter

WriteRichText(params RichText[])

Writes a rich-text cell made of differently formatted runs.

public RowWriter WriteRichText(params RichText[] runs)

Parameters

runs RichText[]

Returns

RowWriter

Examples

row.WriteRichText("Total: ", new RichText("overdue") { Bold = true, Color = "#C00000" });

WriteRichText(CellStyle?, params RichText[])

Writes a rich-text cell with a cell style (alignment, fill, borders) around the runs.

public RowWriter WriteRichText(CellStyle? style, params RichText[] runs)

Parameters

style CellStyle
runs RichText[]

Returns

RowWriter