# 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.

- **Author:** Bjoern Meyer
- **Published:** 2026-12-05
- **Modified:** 2026-12-04
- **Description:** 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.
- **7 min read** (1366 words)
- **Tags:**
  - JavaScript
  - TX Sheet Control
  - Excel
  - Spreadsheet
  - JavaScript Spreadsheet Essentials
- **Web URL:** https://www.textcontrol.com/blog/2026/12/05/how-to-create-an-ods-file-in-javascript/
- **LLMs URL:** https://www.textcontrol.com/blog/2026/12/05/how-to-create-an-ods-file-in-javascript/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2026/12/05/how-to-create-an-ods-file-in-javascript/llms-full.txt

---

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)](https://s1-www.textcontrol.com/assets/dist/blog/2026/12/05/f/assets/javascript-create-ods.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.

![The project budget before ODS export, with four service rows and a $1,300 total.](https://s1-www.textcontrol.com/assets/dist/blog/2026/12/05/f/assets/sample.webp "The project budget before ODS export, with four service rows and a $1,300 total.") The project budget before ODS export, with four service rows and a $1,300 total.

### 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);});
```

![The ODS file reopened in TX Sheet Control. The sample reads D9 as 1300 after loading.](https://s1-www.textcontrol.com/assets/dist/blog/2026/12/05/f/assets/create-ods-reopened.webp "The ODS file reopened in TX Sheet Control. The sample reads D9 as 1300 after loading.") The ODS file reopened in TX Sheet Control. The sample reads D9 as 1300 after loading.

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](https://docs.textcontrol.com/tx-sheet-control/document-processing/ods/).

[Previous: How to Apply Conditional Formatting in a JavaScript Spreadsheet](https://www.textcontrol.com/blog/2026/12/05/how-to-apply-conditional-formatting-in-a-javascript-spreadsheet/llms-full.txt)  
[Next: How to Create an Excel XLSX File in JavaScript](https://www.textcontrol.com/blog/2026/12/05/how-to-create-an-excel-xlsx-file-in-javascript/llms-full.txt)

JavaScript Spreadsheet Essentials · Part 6 of 8

1. [How to Import, Edit, and Export Excel XLSX Files in JavaScript](https://www.textcontrol.com/blog/2026/12/05/how-to-import-edit-and-export-excel-xlsx-files-in-javascript/llms-full.txt)
2. [How to Convert Excel to PDF in JavaScript](https://www.textcontrol.com/blog/2026/12/05/how-to-convert-excel-to-pdf-in-javascript/llms-full.txt)
3. [How to Export JSON Data to Excel in JavaScript](https://www.textcontrol.com/blog/2026/12/05/how-to-export-json-data-to-excel-in-javascript/llms-full.txt)
4. [How to Create Pivot Tables in JavaScript](https://www.textcontrol.com/blog/2026/12/05/how-to-create-pivot-tables-in-javascript/llms-full.txt)
5. [How to Apply Conditional Formatting in a JavaScript Spreadsheet](https://www.textcontrol.com/blog/2026/12/05/how-to-apply-conditional-formatting-in-a-javascript-spreadsheet/llms-full.txt)
6. How to Create an ODS File in JavaScript
7. [How to Create an Excel XLSX File in JavaScript](https://www.textcontrol.com/blog/2026/12/05/how-to-create-an-excel-xlsx-file-in-javascript/llms-full.txt)
8. [How to Load REST API Data into a JavaScript Spreadsheet](https://www.textcontrol.com/blog/2026/12/05/how-to-load-rest-api-data-into-a-javascript-spreadsheet/llms-full.txt)

### Frequently Asked Questions

Which stream type creates an ODS file? 
---------------------------------------

Use StreamType.OpenDocumentSpreadsheet with the binary save method.

Can I reopen the ODS bytes without downloading first? 
------------------------------------------------------

Yes. Pass the returned bytes to editor.load with the same stream type and reacquire worksheet handles afterward.

What should I check in LibreOffice Calc? 
-----------------------------------------

Check the worksheet name, formulas, numeric totals, currency formatting, column widths, and the result of a small edit followed by another save.

---

## About Bjoern Meyer

As CEO, Bjoern is the visionary behind our strategic direction and business development, bridging the gap between our customers and engineering teams. His deep passion for coding and web technologies drives the creation of innovative products. If you're at a tech conference, be sure to stop by our booth - you'll most likely meet Bjoern in person. With an advanced graduate degree (Dipl. Inf.) in Computer Science, specializing in AI, from the University of Bremen, Bjoern brings significant expertise to his role. In his spare time, Bjoern enjoys running, paragliding, mountain biking, and playing the piano.

- [LinkedIn](https://www.linkedin.com/in/bjoernmeyer/)
- [X](https://x.com/txbjoern)
- [GitHub](https://github.com/bjoerntx)

---

## Series

- [How to Import, Edit, and Export Excel XLSX Files in JavaScript](https://www.textcontrol.com/blog/2026/12/05/how-to-import-edit-and-export-excel-xlsx-files-in-javascript/llms.txt)
- [How to Convert Excel to PDF in JavaScript](https://www.textcontrol.com/blog/2026/12/05/how-to-convert-excel-to-pdf-in-javascript/llms.txt)
- [How to Export JSON Data to Excel in JavaScript](https://www.textcontrol.com/blog/2026/12/05/how-to-export-json-data-to-excel-in-javascript/llms.txt)
- [How to Create Pivot Tables in JavaScript](https://www.textcontrol.com/blog/2026/12/05/how-to-create-pivot-tables-in-javascript/llms.txt)
- [How to Apply Conditional Formatting in a JavaScript Spreadsheet](https://www.textcontrol.com/blog/2026/12/05/how-to-apply-conditional-formatting-in-a-javascript-spreadsheet/llms.txt)
- **How to Create an ODS File in JavaScript** (this article)
- [How to Create an Excel XLSX File in JavaScript](https://www.textcontrol.com/blog/2026/12/05/how-to-create-an-excel-xlsx-file-in-javascript/llms.txt)
- [How to Load REST API Data into a JavaScript Spreadsheet](https://www.textcontrol.com/blog/2026/12/05/how-to-load-rest-api-data-into-a-javascript-spreadsheet/llms.txt)

---

## Related Posts

- [How to Load REST API Data into a JavaScript Spreadsheet](https://www.textcontrol.com/blog/2026/12/05/how-to-load-rest-api-data-into-a-javascript-spreadsheet/llms.txt)
- [How to Create an Excel XLSX File in JavaScript](https://www.textcontrol.com/blog/2026/12/05/how-to-create-an-excel-xlsx-file-in-javascript/llms.txt)
- [How to Apply Conditional Formatting in a JavaScript Spreadsheet](https://www.textcontrol.com/blog/2026/12/05/how-to-apply-conditional-formatting-in-a-javascript-spreadsheet/llms.txt)
- [How to Create Pivot Tables in JavaScript](https://www.textcontrol.com/blog/2026/12/05/how-to-create-pivot-tables-in-javascript/llms.txt)
- [How to Export JSON Data to Excel in JavaScript](https://www.textcontrol.com/blog/2026/12/05/how-to-export-json-data-to-excel-in-javascript/llms.txt)
- [How to Convert Excel to PDF in JavaScript](https://www.textcontrol.com/blog/2026/12/05/how-to-convert-excel-to-pdf-in-javascript/llms.txt)
- [How to Import, Edit, and Export Excel XLSX Files in JavaScript](https://www.textcontrol.com/blog/2026/12/05/how-to-import-edit-and-export-excel-xlsx-files-in-javascript/llms.txt)
- [Inside the TX Sheet Control Spreadsheet Editor: A Complete Spreadsheet for Your Web Applications](https://www.textcontrol.com/blog/2026/12/01/inside-the-tx-sheet-control-spreadsheet-editor/llms.txt)
- [TX Sheet Control 2.0 Is Now Available: Spreadsheets and Dashboards for Your Applications](https://www.textcontrol.com/blog/2026/12/01/tx-sheet-control-2-0-is-now-available/llms.txt)
