Table of Contents

Method ToCsv

Namespace
DocWright.Spreadsheet
Assembly
DocWright.Spreadsheet.dll

ToCsv(TextWriter, XlsxCsvOptions?)

Writes the sheet as delimited text (CSV).

public void ToCsv(TextWriter writer, XlsxCsvOptions? options = null)

Parameters

writer TextWriter

Where the text goes. It is not closed.

options XlsxCsvOptions

How to write, or null for the defaults, which are what Excel's own CSV save gives.

Remarks

Measured against Excel's save: the range is the sheet's used range (it does not start at A1 when the cells do not), every row is as wide as the range, a row that holds nothing is a row of delimiters, and a sheet that holds nothing is one empty row. A hidden row is written. Of a merged range only the first cell holds anything. A formula cell is written as the result the file stores, an error as its text.

Each cell is DisplayText, which is the text a column wide enough shows. Excel writes the same whatever the column's width (measured): a number its column shows as #### or shortens is written in full.

A cell's text is written as it is: text that begins with = is a formula to the spreadsheet that opens the CSV. See GuardFormulas.

Exceptions

ArgumentNullException

writer is null.

ArgumentException

The delimiter is a quote or a line break, or the line end is not one of the three.

InvalidOperationException

The sheet is not a worksheet.

ResourceLimitExceededException

The range covers more cells than MaxCells.

InvalidDocumentException

The sheet's part is malformed.

ToCsv(Stream, XlsxCsvOptions?)

Writes the sheet as delimited text (CSV) in UTF-8.

public void ToCsv(Stream stream, XlsxCsvOptions? options = null)

Parameters

stream Stream

Where the bytes go. It is not closed.

options XlsxCsvOptions

How to write, or null for the defaults: with them the bytes are those of Excel's "CSV UTF-8" save, byte order mark included.

Remarks

Exceptions

ArgumentNullException

stream is null.

ArgumentException

The delimiter is a quote or a line break, or the line end is not one of the three.

InvalidOperationException

The sheet is not a worksheet.

ResourceLimitExceededException

The range covers more cells than MaxCells.

InvalidDocumentException

The sheet's part is malformed.