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
writerTextWriterWhere the text goes. It is not closed.
optionsXlsxCsvOptionsHow 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
writeris 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
streamStreamWhere the bytes go. It is not closed.
optionsXlsxCsvOptionsHow 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
streamis 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.