on writeFile as dbf modify the column header #1888

Closed
opened 2020-04-02 17:30:33 +00:00 by bandizsolt · 1 comment
bandizsolt commented 2020-04-02 17:30:33 +00:00 (Migrated from github.com)

I use SheetJS to upload a dbf file, then parse, modify some info and then writeFile as dbf. If I saw correct after parsing the dbf file the column properties will be lost (I don't know if there a way to retain). And when I want so save the file, the writeFile function will export my file and the column header properties will be automatically calculated. (how I can edit?)

   const reader = new FileReader();
      reader.onload = function(e) {
        const data = e.target.result;
        if (!rABS) data = new Uint8Array(data);
        const workbook = XLSX.read(data, {
          type: rABS ? "binary" : "array",
        });

        const first_sheet_name = workbook.SheetNames[0];
        const worksheet = workbook.Sheets[first_sheet_name];

        XLSX.writeFile(workbook, "out.dbf", {
              bookType: "dbf",
              type: "array",
            });
      };

example:
source file column properties: NR_ACT,C,50
source
exported file column properties: NR_ACT,C,250
export

Thanks your help!

I use SheetJS to upload a dbf file, then parse, modify some info and then writeFile as dbf. If I saw correct after parsing the dbf file the column properties will be lost (I don't know if there a way to retain). And when I want so save the file, the writeFile function will export my file and the column header properties will be automatically calculated. (how I can edit?) ``` const reader = new FileReader(); reader.onload = function(e) { const data = e.target.result; if (!rABS) data = new Uint8Array(data); const workbook = XLSX.read(data, { type: rABS ? "binary" : "array", }); const first_sheet_name = workbook.SheetNames[0]; const worksheet = workbook.Sheets[first_sheet_name]; XLSX.writeFile(workbook, "out.dbf", { bookType: "dbf", type: "array", }); }; ``` example: source file column properties: NR_ACT,C,50 ![source](https://user-images.githubusercontent.com/52448147/78279665-8ccefc80-7520-11ea-921b-b9178c9f037d.PNG) exported file column properties: NR_ACT,C,250 ![export](https://user-images.githubusercontent.com/52448147/78279663-8c366600-7520-11ea-96bc-35ab69db75ba.PNG) Thanks your help!
SheetJSDev commented 2020-04-02 18:09:49 +00:00 (Migrated from github.com)

On read the original field type and lengths are not preserved. On write, they are automatically deduced based on the worksheet data.

  • Strings (field type C) have a hard-coded-length of 250.
  • Numbers are written as VFP doubles (field type B) and are fixed-width (so we don't pass a width field)

The column type metadata could theoretically be attached to column info (which is how we store column width info) and referenced on write. For our testing, can you share that file?

On read the original field type and lengths are not preserved. On write, they are automatically deduced based on the worksheet data. - Strings (field type C) have a hard-coded-length of 250. - Numbers are written as VFP doubles (field type B) and are fixed-width (so we don't pass a width field) The column type metadata could theoretically be attached to column info (which is how we store column width info) and referenced on write. For our testing, can you share that file?
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/sheetjs#1888
No description provided.