Node.js
Node.js applications process workbooks with the server package of TX Sheet Control, @txtextcontrol/tx-sheet-control-server. Its ServerSheetControl works without a browser: it loads a file, changes cells and saves the result as bytes, which your application writes to a file or sends in an HTTP response.
Set TX_SHEET_LICENSE to the contents of your license file, tx-sheet-control.license, which the Text Control Account issues for your Trial, Developer or OEM serial number, before running the examples. The server reads this environment setting when the explicit license option is omitted.
Install the Package
Install @txtextcontrol/tx-sheet-control-server for Node.js processing; Install the npm Packages shows how to install the supplied npm archive into a Node.js 22 or newer project. The package independently includes workbook operations, XLSX, TXWB and PDF, calculation, fonts and deployment resources. TXWB is the native workbook format of TX Sheet Control. The public browser editor package is not required.
Use ES modules, or the equivalent package exports with CommonJS require.
Convert an XLSX File to PDF
The following ES module loads sales.xlsx, writes two values and saves the workbook as sales.pdf. Sample Documents offers a sales spreadsheet named sales.xlsx to try it with.
import { readFile, writeFile } from 'node:fs/promises';
import { ServerSheetControl, StreamType } from '@txtextcontrol/tx-sheet-control-server';
const control = new ServerSheetControl({ locale: 'en-US', timeZone: 'UTC' });
try {
await control.load(new Uint8Array(await readFile('sales.xlsx')), StreamType.SpreadsheetML);
const sheet = control.workbook.sheets.at(0);
sheet.cell('D2').setValue(12);
sheet.cell('E2').setValue(19.5);
await writeFile('sales.pdf', await control.save(StreamType.PDF));
} finally {
control.destroy();
}
The code works as follows:
readFileandwriteFilefromnode:fs/promisesread the input file and write the output file. ServerSheetControl and StreamType come from the server package.new ServerSheetControl()creates the control with the options localeen-USand timeZoneUTC, properties of the ServerSheetControlOptions interface.- load loads the bytes of
sales.xlsxasStreamType.SpreadsheetML, the XLSX format, and replaces the document atomically. - workbook, sheets and at return the first worksheet.
- cell and setValue write the literal values 12 and 19.5 into D2 and E2.
- save returns the workbook as PDF bytes, and
writeFilewrites them tosales.pdf. - destroy in the
finallyblock releases the control, also when an error occurs.
Workbook APIs use worksheet and range concepts without a DOM. Saving returns bytes; writing storage files or HTTP responses belongs to the application.
Create a New Document
For a new document, get the first worksheet from control.workbook.sheets.at(0), fill rectangular ranges with range and setValues, set formulas with setFormula and save. Create a Workbook in the .NET tutorial shows these steps in C#.
Configure Fonts
- Default fonts. The included fonts work with the package defaults.
- A custom font folder. Configure fontDirectory only for a deliberate custom folder, and keep the required regular, bold and italic faces in it.
- The font catalog. Call
getFontCatalog()to inspect the deployed fonts andrefreshFonts()to refresh them after changes. getFontCatalog and refreshFonts both return the catalog as a promise.
Handle Lifetime and Failures
- Release the control. Await
loadandsave, and release the control infinally, including after errors, as the code above does. - Limit concurrency. Bound concurrent jobs according to the actual documents and the available memory.
- Check imports. Inspect import warnings, and do not assume that every specialized Excel object is editable.
- Keep dashboards in TXWB. Use TXWB for dashboards and reusable report metadata.
Next Steps
- Node.js Server Applications: deploy the complete installed package with its fonts and resources.
- Lifetime and Concurrency: release controls, reuse them for unrelated requests and bound parallel jobs.
- Node.js Server: look up the classes and methods of
@txtextcontrol/tx-sheet-control-server. - Loading and Saving Workbooks: choose the stream type for XLSX, TXWB, PDF, CSV, XML and JSON.