sheetjs/packages/dta
SheetJS 0941ff97a3 dta v0.0.2 2024-03-22 00:39:09 -04:00
..
bin version bump 0.20.1 2023-12-05 03:19:42 -05:00
dist dta v0.0.2 2024-03-22 00:39:09 -04:00
types dta v0.0.2 2024-03-22 00:39:09 -04:00
.eslintrc dta initial 2023-11-13 06:13:07 -05:00
.gitignore version bump 0.20.1 2023-12-05 03:19:42 -05:00
Makefile dta v0.0.2 2024-03-22 00:39:09 -04:00
README.md dta v0.0.2 2024-03-22 00:39:09 -04:00
dta.ts dta v0.0.2 2024-03-22 00:39:09 -04:00
package.json dta v0.0.2 2024-03-22 00:39:09 -04:00
test.js version bump 0.20.1 2023-12-05 03:19:42 -05:00

DTA Data File Codec

Codec for reading Stata .DTA files and generating CSF workbook objects compatible with the SheetJS library constellation.

DTA datasets can support millions of observations and over 32767 variables. The codec will truncate data to 1048576 observations and 16384 variables.

https://docs.sheetjs.com/docs/constellation/dta includes a live demo.

Installation

Using NodeJS package manager:

npm install --save https://cdn.sheetjs.com/dta-0.0.2/dta-0.0.2.tgz

The standalone script is also hosted on the SheetJS CDN:

<script src="https://cdn.sheetjs.com/dta-0.0.2/package/dist/dta.min.js"></script>

Usage

The parse method accepts a Uint8Array representing the file data. It returns a "Common Spreadsheet Format" workbook object.

The set_utils method accepts a utils object from SheetJS CE or a SheetJS Pro build. parse will use methods from the utils object.

NodeJS

const XLSX = require("xlsx"), DTA = require("dta");
DTA.set_utils(XLSX.utils);

const wb = DTA.parse(fs.readFileSync("auto.dta"));

Browser

dist/dta.min.js is a standalone build designed to be added with <script>.

<script lang="javascript" src="https://cdn.sheetjs.com/xlsx-latest/package/dist/xlsx.full.min.js"></script>
<script src="dist/dta.min.js"></script>
<div id="out"></div>
<script>
DTA.set_utils(XLSX.utils);
(async() => {
  /* fetch file */
  const data = await (await fetch("test.dta")).arrayBuffer();
  /* parse */
  const wb = DTA.parse(new Uint8Array(data));
  /* wb is a SheetJS workbook object */
  const html = XLSX.utils.sheet_to_html(wb.Sheets[wb.SheetNames[0]]);
  out.innerHTML = html;
})();
</script>

dist/dta.mjs is a ECMAScript Module build designed to be used with bundlers:

import * as DTA from 'dta';