reading and writing with cellStyles: true does not perpetuate styles #3214

Closed
opened 2024-09-12 08:19:35 +00:00 by EmilienKopp · 1 comment

Issue:
Reading a .xlsx file, making a modification, and reexporting it does not keep the cell styles like border and color background.

		const data = fs.readFileSync(path);
		const workbook = XLSX.read(data, { type: 'buffer', cellStyles: true, cellNF: true });

		// Edit the workbook
		const sheet = workbook.Sheets['観点別成績診断一覧(学習の様子あり)'];
		if (sheet) {
			sheet.A6 = { t: 's', v: '知・技', w: '知・技' };
		}

		// Save the workbook to a file
		const wopts = {
			bookType,
			type: 'buffer',
			cellStyles: true
		};
    
     const fileData = XLSX.writeXLSX(workbook,  wopts);
        fs.writeFileSync(outputPath, fileData);

Reproduction repo:
https://github.com/EmilienKopp/xlsx_styles_repro
git@github.com:EmilienKopp/xlsx_styles_repro.git

Issue: Reading a .xlsx file, making a modification, and reexporting it does not keep the cell styles like border and color background. ```js const data = fs.readFileSync(path); const workbook = XLSX.read(data, { type: 'buffer', cellStyles: true, cellNF: true }); // Edit the workbook const sheet = workbook.Sheets['観点別成績診断一覧(学習の様子あり)']; if (sheet) { sheet.A6 = { t: 's', v: '知・技', w: '知・技' }; } // Save the workbook to a file const wopts = { bookType, type: 'buffer', cellStyles: true };  const fileData = XLSX.writeXLSX(workbook, wopts); fs.writeFileSync(outputPath, fileData); ``` Reproduction repo: https://github.com/EmilienKopp/xlsx_styles_repro git@github.com:EmilienKopp/xlsx_styles_repro.git
Owner

We offer a special workflow for modifying existing files as part of "Pro Edit"

We do hope to add it to SheetJS CE at some point, but the current focus is data processing correctness and performance.

We offer a special workflow for modifying existing files as part of ["Pro Edit"](https://sheetjs.com/pro/) We do hope to add it to SheetJS CE at some point, but the current focus is data processing correctness and performance.
Sign in to join this conversation.
No Milestone
No Assignees
2 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#3214
No description provided.