How to Create an ODS File in JavaScript
Create an ODS workbook in JavaScript with text, numbers, formulas, and currency formatting. Download it, reopen it in TX Sheet Control, and check its standard spreadsheet content in LibreOffice Calc.

Create an OpenDocument Spreadsheet file directly in JavaScript. The example builds a project budget with text, numeric inputs, formulas, and cell formatting, then downloads and reopens the resulting ODS workbook.
Part 6 of the JavaScript Spreadsheet Essentials series.
Run the JavaScript Sample
This example uses TX Sheet Control 2.0.0 with plain JavaScript. Download the complete sample and output files (ZIP). Extract it and open its sample folder.
Copy the complete browser folder from your TX Sheet Control download into sample/public/sheet, retaining its fonts, languages, and notices. Put your signed tx-sheet-control.license beside server.mjs. Use Node.js 22 or later to run the included local host:
npm start
Open http://127.0.0.1:5085. The host serves the files; workbook editing and conversion run in the browser. The HTML supplies the editor host and loads /sheet/tx-sheet-control.min.js followed by app.js.
The shared common.js module creates the editor, awaits its fonts and initial readiness, manages progress messages, and delivers byte downloads:
export const { Spreadsheet, StreamType } = TXTextControl.TXSheetControl;
export const status = document.getElementById('status');
export async function createEditor() {
const response = await fetch('/license', {cache:'no-store'});
if (!response.ok) throw new Error('Configure tx-sheet-control.license before starting the sample.');
const editor = new Spreadsheet(document.getElementById('sheet'), {
license: (await response.text()).trim(),
fontCatalogURL: '/sheet/fonts/catalog.json',
fontBaseURL: '/sheet/fonts/', locale:'en-US', currency:'USD'
});
await editor.ready;
return editor;
}
export function download(bytes, name, mime) {
const url = URL.createObjectURL(new Blob([bytes], {type:mime}));
const link = document.createElement('a');
link.href=url; link.download=name;
document.body.append(link); link.click(); link.remove();
setTimeout(()=>URL.revokeObjectURL(url),5000);
}
export function showWarnings(warnings) {
const list=document.getElementById('diagnostics');
list.replaceChildren();
const messages=warnings.length ? warnings.map(w=>typeof w==='string' ? w : w.message ?? JSON.stringify(w))
: ['No conversion warnings.'];
for(const message of messages) {
const item=document.createElement('li'); item.textContent=message; list.append(item);
}
}
export async function busy(message, action) {
const buttons=[...document.querySelectorAll('button,input[type=file]')];
buttons.forEach(button=>button.disabled=true);
status.textContent=message;
try { return await action(); }
catch(error) { status.textContent=error.message; throw error; }
finally { buttons.forEach(button=>button.disabled=false); }
}
Create the Budget Worksheet
The report contains four services: Consulting, Training, Support, and Hosting. Each row has hours, a rate, and an amount formula. Their line amounts are $500, $350, $270, and $180, for a total of $1,300.
Use worksheet-bound cell and range handles to create the content. setValues() writes typed data, while setFormula() supplies the calculated Amount column and grand total:
export function build(workbook) {
const sheet=workbook.sheets.at(0);
sheet.rename('Project Budget');
sheet.cell('A1').setText('NORTHSTAR / OPEN BUDGET');
sheet.range('A1:D1').merge();
sheet.range('A3:D7').setValues([
['Service','Hours','Rate','Amount'],
['Consulting',4,125,null],['Training',2,175,null],
['Support',6,45,null],['Hosting',12,15,null]
]);
for(let row=4;row<=7;row++)sheet.cell(`D${row}`).setFormula(`=B${row}*C${row}`);
sheet.cell('A9').setText('TOTAL');
sheet.cell('D9').setFormula('=SUM(D4:D7)');
sheet.range('A1:D1').format({fontSize:18,bold:true,textColor:'#762060'});
sheet.range('A3:D3').format({bold:true,fillColor:'#762060',textColor:'#ffffff'});
sheet.range('C4:D9').format({numberFormatCode:'$#,##0.00'});
sheet.range('A9:D9').format({bold:true,fillColor:'#e4f4ee'});
[260,110,140,160].forEach((pixels,index)=>sheet.columns.at(index).setWidth({pixels}));
return {sheet,total:sheet.cell('D9').value};
}
Currency formatting changes the presentation of C4:D9 without turning numeric values into strings. The header fill, bold total row, merged title, and column widths are part of the workbook design.
Save with the OpenDocument Stream Type
Call editor.save(StreamType.OpenDocumentSpreadsheet) to obtain binary ODS bytes. Deliver those bytes with the MIME type application/vnd.oasis.opendocument.spreadsheet and the filename project-budget.ods.
ODS is a workbook format. Use the byte-based save method, rather than saveText(), which is intended for tabular text formats.
Reopen and Verify the Result
The sample's Save and reopen ODS action saves the workbook, loads the returned bytes with the same stream type, and acquires the first worksheet from the newly loaded document. It then verifies the displayed total from D9:
import {createEditor,StreamType,download,busy,showWarnings,status} from './common.js';
import {build} from './model.js';
async function start(){
const editor=await createEditor();
const actions={};let model={};
const addAction=(id,label,action)=>{
actions[id]=action;const button=document.createElement('button');button.id=id;button.textContent=label;
button.addEventListener('click',()=>busy('Working…',action).catch(()=>{}));
document.getElementById('actions').append(button);
};
const downloadXlsx=async()=>{
const bytes=await editor.save(StreamType.SpreadsheetML);
showWarnings(editor.getXlsxWarnings());
download(bytes,'create-ods.xlsx','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
status.textContent='Workbook exported successfully. Review conversion diagnostics.';
};
model=build(editor.workbook);
addAction('export','Download ODS',async()=>{const bytes=await editor.save(StreamType.OpenDocumentSpreadsheet);download(bytes,'project-budget.ods','application/vnd.oasis.opendocument.spreadsheet');status.textContent='OpenDocument workbook exported. Total: $1,300.00.';});
addAction('reopen','Save and reopen ODS',async()=>{const bytes=await editor.save(StreamType.OpenDocumentSpreadsheet);const result=await editor.load(bytes,StreamType.OpenDocumentSpreadsheet);showWarnings(result.warnings);model={sheet:editor.workbook.sheets.at(0)};status.textContent='ODS reopened. D9 = '+model.sheet.cell('D9').value;});
status.textContent='Text, numbers, formulas and currency formatting · Total: $1,300.00.';
return {editor,actions,get model(){return model;}};
}
window.sampleReady=start();
window.sampleReady.catch(error=>{status.textContent=error.message;console.error(error);});
Reacquiring the worksheet matters because loading replaces the document. Inspect the returned warnings, and check formulas, widths, formatting, and totals instead of checking only whether the file opens.
Check the Workbook in LibreOffice Calc
Extract project-budget.ods from the sample ZIP and open it in LibreOffice Calc. Check the Project Budget sheet name, four detail rows, currency formats, and the $1,300 total. Select D4 to confirm its formula multiplies B4 by C4.
Change Consulting hours in B4 from 4 to 5. Its amount should become $625 and the grand total $1,425. Save a separate copy from Calc, reopen it in TX Sheet Control, and review the edited values and any import warnings.
Understand Standard Content and Extensions
ODS projects supported values, formulas, formatting, dimensions, and other spreadsheet structures into standard OpenDocument elements. TX Sheet Control also retains its complete workbook model through an extension part. Another spreadsheet application can display the standard content while handling private extensions differently.
This budget intentionally uses ordinary spreadsheet features. For workbooks with TX-specific dashboards, barcodes, or report metadata, validate exchanges with the target application and keep a TXWB original when complete editable TX behavior is required.
Read more in the TX Sheet Control documentation.
Previous: How to Apply Conditional Formatting in a JavaScript Spreadsheet
Next: How to Create an Excel XLSX File in JavaScript
JavaScript Spreadsheet Essentials · Part 6 of 8
- How to Import, Edit, and Export Excel XLSX Files in JavaScript
- How to Convert Excel to PDF in JavaScript
- How to Export JSON Data to Excel in JavaScript
- How to Create Pivot Tables in JavaScript
- How to Apply Conditional Formatting in a JavaScript Spreadsheet
- How to Create an ODS File in JavaScript
- How to Create an Excel XLSX File in JavaScript
- How to Load REST API Data into a JavaScript Spreadsheet
Frequently Asked Questions
Use StreamType.OpenDocumentSpreadsheet with the binary save method.
Yes. Pass the returned bytes to editor.load with the same stream type and reacquire worksheet handles afterward.
Check the worksheet name, formulas, numeric totals, currency formatting, column widths, and the result of a small edit followed by another save.
Jump to the other posts in this series:
- How to Import, Edit, and Export Excel XLSX Files in JavaScript
- How to Convert Excel to PDF in JavaScript
- How to Export JSON Data to Excel in JavaScript
- How to Create Pivot Tables in JavaScript
- How to Apply Conditional Formatting in a JavaScript Spreadsheet
- How to Create an ODS File in JavaScript
- How to Create an Excel XLSX File in JavaScript
- How to Load REST API Data into a JavaScript Spreadsheet
TX Sheet Control
Excel-compatible spreadsheet editing, a robust calculation engine, and interactive dashboards for business applications.
Related Posts
JavaScriptExcelJavaScript Spreadsheet Essentials
How to Load REST API Data into a JavaScript Spreadsheet
Fetch REST API JSON into a JavaScript spreadsheet with TX Sheet Control. Validate and map records, show loading and error states, refresh data, and update dependent formulas.
JavaScriptExcelJavaScript Spreadsheet Essentials
How to Create an Excel XLSX File in JavaScript
Create an Excel XLSX file from scratch in JavaScript. Add worksheets, write typed data and formulas, format headers and currency, set column widths, and download the workbook.
JavaScriptExcelJavaScript Spreadsheet Essentials
How to Apply Conditional Formatting in a JavaScript Spreadsheet
Apply conditional formatting in a JavaScript spreadsheet: highlight overdue invoices and negative margins, add revenue data bars and target color scales, and update the rules through cell edits.
JavaScriptExcelJavaScript Spreadsheet Essentials
How to Create Pivot Tables in JavaScript
Create a JavaScript PivotTable from sales records with TX Sheet Control. Configure row and column fields, sum revenue, filter regions, refresh source edits, and export a native Excel PivotTable.
JavaScriptExcelJavaScript Spreadsheet Essentials
How to Export JSON Data to Excel in JavaScript
Export JSON records to a formatted Excel workbook in JavaScript. Map fields, retain numeric values, format dates and currency, calculate totals, and download XLSX.
