question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Empty sheets after using writeFile

See original GitHub issue

Hi,

I’m using the XLSX module to open a XLSX file with empty sheets and fill them.

This is an extract of our code :

var myXlsx  = XLSX.readFile( filePath );

myXlsx.Sheets[ 'existingSheet' ][ 'F3' ] = {"v":"TEST","t":"s","r":"<t>TEST</t>","h":"TEST"};

XLSX.writeFile(
    myXlsx,
    filePath
);

If i execute the same code with an existing XLSX with non empty sheets it works. But when i try to modify an empty cell it does not work!

Thanks in advance for your time

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
reviewhercommented, Jan 27, 2017

@andrewdsilva you can actually change the !ref field to include the full range! see https://github.com/SheetJS/js-xlsx/issues/82 for a similar issue.

@sheetjsdev It would be nice to have a helper function that takes a range and a cell and produces a new range that includes the cell.

0reactions
SheetJSDevcommented, Apr 10, 2017

We’re thinking of adding something like this to the utilities:

function range_add_cell(range, cell) {
	var rng = XLSX.utils.decode_range(range);
	var c = typeof cell == 'string' ? XLSX.utils.decode_cell(cell) : cell;
	console.log(rng, c);
	if(rng.s.r > c.r) rng.s.r = c.r;
	if(rng.s.c > c.c) rng.s.c = c.c;

	if(rng.e.r < c.r) rng.e.r = c.r;
	if(rng.e.c < c.c) rng.e.c = c.c;
	return XLSX.utils.encode_range(rng);
}

function add_to_sheet(sheet, cell) {
	sheet['!ref'] = range_add_cell(sheet['!ref'], range);
}

For now it is in the wiki: https://github.com/SheetJS/js-xlsx/wiki/General-Utility-Functions#adding-a-cell-to-a-range

Read more comments on GitHub >

github_iconTop Results From Across the Web

writeFile returns empty file in SheetJs - Stack Overflow
The function receives a valid worksheet object(I inspected), the worksheet name display well but no information is in the file.
Read more >
Response.writefile() method writes empty page in asp.net
C#. // Try This : byte[] fileBytes = File.ReadAllBytes(fi.FullName); Response.Clear() Response.ContentType == "application/pdf" Response.
Read more >
WriteFile function (fileapi.h) - Win32 apps - Microsoft Learn
Writes data to the specified file or input/output (I/O) device.
Read more >
writeFile - Cypress Documentation
Using null explicitly will allows you to write a Buffer directly, ... {projectRoot}/path/to/data.json will be created with the following contents:.
Read more >
Using the writeFileSync method in Node.js - LogRocket Blog
Catching errors while using writeFileSync in Node.js ... As such, you should use the asynchronous function writeFile for creating and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found