Empty file #968

Closed
opened 2018-01-24 15:48:59 +00:00 by wlodi83 · 7 comments
wlodi83 commented 2018-01-24 15:48:59 +00:00 (Migrated from github.com)

When I try to save XLSX file with CSV data, I am getting empty file. I am getting CSV data, from get response with tab separator. Here is example code:

let workbook = { SheetNames: [], Sheets: {} };

for (const [key, viewId] of Object.entries(viewIds)) {
    let url = `${context.hostname}${viewId}`;
    let result = await makeGetRequest(url);
    let data = result.body;

    let wb = XLSX.read(data, {type: 'buffer'});
    let ws = wb.Sheets[wb.SheetNames[0]];

    /* Add the sheet name to the list */
    let sheetName = key.replace(/\/*\\*\[*\]*\:*\**\?*/g, '').substr(0,30);
    workbook.SheetNames.push(sheetName);

    /* Load the worksheet object */
    workbook.Sheets[key] = ws;
};

const tmpobj = tmp.fileSync({mode: '0644', postfix: '_test.xlsx'});
XLSX.writeFile(workbook, tmpobj.name);

Example of CSV data (TAB separator):

TEST November 29, 2017 23 FA TEST - FA CLICK 1 $1.10 $1.10
TEST November 29, 2017 23 GA TEST - GA CLICK 1 $1.10 $1.10

I am able to get the data, but file is empty. I don't see any error. Would that be problem with parsing CSV data?

When I try to save XLSX file with CSV data, I am getting empty file. I am getting CSV data, from get response with tab separator. Here is example code: let workbook = { SheetNames: [], Sheets: {} }; for (const [key, viewId] of Object.entries(viewIds)) { let url = `${context.hostname}${viewId}`; let result = await makeGetRequest(url); let data = result.body; let wb = XLSX.read(data, {type: 'buffer'}); let ws = wb.Sheets[wb.SheetNames[0]]; /* Add the sheet name to the list */ let sheetName = key.replace(/\/*\\*\[*\]*\:*\**\?*/g, '').substr(0,30); workbook.SheetNames.push(sheetName); /* Load the worksheet object */ workbook.Sheets[key] = ws; }; const tmpobj = tmp.fileSync({mode: '0644', postfix: '_test.xlsx'}); XLSX.writeFile(workbook, tmpobj.name); Example of CSV data (TAB separator): TEST November 29, 2017 23 FA TEST - FA CLICK 1 $1.10 $1.10 TEST November 29, 2017 23 GA TEST - GA CLICK 1 $1.10 $1.10 I am able to get the data, but file is empty. I don't see any error. Would that be problem with parsing CSV data?
reviewher commented 2018-01-24 16:36:45 +00:00 (Migrated from github.com)

Is the worksheet in the loop empty? Log the data and ws objects within the loop.

Is the worksheet in the loop empty? Log the data and ws objects within the loop.
wlodi83 commented 2018-01-24 16:56:58 +00:00 (Migrated from github.com)

Worksheet seems to have data:

"G14665":{"t":"n","w":"1","v":1},"H14665":{"t":"n","w":"$2.88","v":2.88},"I14665":{"t":"n","w":"$2.88","v":2.88},"A14666":{"t":"s","v":"TEST"}

Worksheet seems to have data: "G14665":{"t":"n","w":"1","v":1},"H14665":{"t":"n","w":"$2.88","v":2.88},"I14665":{"t":"n","w":"$2.88","v":2.88},"A14666":{"t":"s","v":"TEST"}
reviewher commented 2018-01-24 17:25:23 +00:00 (Migrated from github.com)

can you round trip through a buffer? Write to a buffer in memory (call XLSX.write with bookType "xlsx" and type "buffer") then read the new buffer and inspect th result.

can you round trip through a buffer? Write to a buffer in memory (call XLSX.write with bookType "xlsx" and type "buffer") then read the new buffer and inspect th result.
wlodi83 commented 2018-01-24 18:37:28 +00:00 (Migrated from github.com)

Using following options:

const wopts = {type: 'buffer', bookType: 'xlsx'};

I am getting an error: TypeError: x.charCodeAt is not a function

Using following options: const wopts = {type: 'buffer', bookType: 'xlsx'}; I am getting an error: TypeError: x.charCodeAt is not a function
wlodi83 commented 2018-01-24 21:35:51 +00:00 (Migrated from github.com)

I am also getting following error: TypeError: Cannot set property 'General' of undefined

I am also getting following error: TypeError: Cannot set property 'General' of undefined
wlodi83 commented 2018-01-25 09:25:22 +00:00 (Migrated from github.com)

Problem is that method generates XLSX file but cells are empty. But number of empty cells is not lower than number of rows in data.

Problem is that method generates XLSX file but cells are empty. But number of empty cells is not lower than number of rows in data.
SheetJSDev commented 2018-01-25 15:19:07 +00:00 (Migrated from github.com)

First: console.log(ws["!ref"]) within the loop and see if the asserted range includes the cells. The utilities ultimately look at that key to determine what cells are in the worksheet.

If the range is too small, could you share the original data that was passed to json_to_sheet?

If the range looks correct, can you share JSON.stringify(ws), JSON.stringify(wb) outside the loop, and the actual XLSX file that was generated?

First: `console.log(ws["!ref"])` within the loop and see if the asserted range includes the cells. The utilities ultimately look at that key to determine what cells are in the worksheet. If the range is too small, could you share the original `data` that was passed to `json_to_sheet`? If the range looks correct, can you share `JSON.stringify(ws)`, `JSON.stringify(wb)` outside the loop, and the actual XLSX file that was generated?
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#968
No description provided.