Spreadsheet.saveText Method
Saves CSV, XML or JSON text with flat settings. Omits a generated CSV BOM; UTF-8 byte limits/events still include it. Does not change the workbook or options.
Owner: Spreadsheet. Package: @txtextcontrol/tx-sheet-control-server. Version: 2.0.0.
Syntax
saveText(streamType: StreamType.CSV | StreamType.XML | StreamType.JSON, options?: SaveOptions): Promise<string>
Parameters
| Parameter | Type | Optional | Description |
|---|---|---|---|
streamType | StreamType.CSV | StreamType.XML | StreamType.JSON | No | The supported input or output format. PDF is output-only. |
options | SaveOptions | undefined | Yes | Supported settings for this operation; omitted settings retain documented defaults. |
Return Value
Promise<string>.
Examples
Load customer orders, calculate and format a total, then return CSV text for an HTTP response or integration. XML and JSON use the same saveText contract. A generated CSV BOM is omitted from strings.
import type { ServerSheetControl } from '@txtextcontrol/tx-sheet-control-server';
import { StreamType } from '@txtextcontrol/tx-sheet-control-server';
async function exportCustomerText(control: ServerSheetControl) {
await control.load('Customer;Amount\nMüller;125,5', StreamType.CSV, {
sheetName: 'Orders',
delimiter: ';',
decimalSeparator: ',',
});
const sheet = control.workbook.sheets.get('Orders');
sheet.range('A1:C1').setValues([['Customer', 'Amount', 'Total']]);
sheet.cell('C2').setFormula('=B2*1.19');
sheet.range('A1:C1').format({ bold: true, fillColor: '#e5eef4' });
sheet.range('B2:C2').format({ numberFormatCode: '#,##0.00' });
return await control.saveText(StreamType.CSV, { delimiter: ';', decimalSeparator: ',', range: 'A1:C2' });
}
Remarks
Use this member on an object from the current document. Reacquire document-bound handles after replacement/deletion. Validate arguments against the declared types and documented bounds; handle exceptions or rejected promises.