Clear duplicate data in each cell when merging the same cells #3090

Open
opened 2024-03-18 03:38:37 +00:00 by heaxo · 4 comments

I encountered a calculation error when using the SUM function to merge the same cells using workSheet ['! Merges']. The reason is that when I canceled the merged cells, each cell still retained its pre merged value

Figure 1 is what I expected

And Figure 2 is my current one. Canceling the merge of cells is incorrect, and the values before the merge are still retained

I encountered a calculation error when using the SUM function to merge the same cells using workSheet ['! Merges']. The reason is that when I canceled the merged cells, each cell still retained its pre merged value Figure 1 is what I expected And Figure 2 is my current one. Canceling the merge of cells is incorrect, and the values before the merge are still retained
Owner

Can you share the original file, before you cleared merge cells?

Can you share the original file, before you cleared merge cells?
Author

Can you share the original file, before you cleared merge cells?

Of course I can

> Can you share the original file, before you cleared merge cells? Of course I can
Owner
function fix_merges_in_workbook(wb) {
	wb.SheetNames.forEach(n => {
		var ws = wb.Sheets[n];
		ws?.["!merges"]?.forEach(m => {
			if(typeof m == "string") m = XLSX.utils.decode_range(m);
			for(var R = m.s.r; R <= m.e.r; ++R) for(var C = m.s.c; C <= m.e.c; ++C) {
				var cell = ws["!data"] ? ws["!data"][R]?.[C] : ws[XLSX.utils.encode_cell({r:R,c:C})];
				if(!cell || R == m.s.r && C == m.s.c) continue;
				delete cell.v; delete cell.w;
			}
		});	
	});
}
```js function fix_merges_in_workbook(wb) { wb.SheetNames.forEach(n => { var ws = wb.Sheets[n]; ws?.["!merges"]?.forEach(m => { if(typeof m == "string") m = XLSX.utils.decode_range(m); for(var R = m.s.r; R <= m.e.r; ++R) for(var C = m.s.c; C <= m.e.c; ++C) { var cell = ws["!data"] ? ws["!data"][R]?.[C] : ws[XLSX.utils.encode_cell({r:R,c:C})]; if(!cell || R == m.s.r && C == m.s.c) continue; delete cell.v; delete cell.w; } }); }); } ```
Author

Thank you for solving my problem, but I am curious why the xlsx.js library does not directly handle this situation when merging

Thank you for solving my problem, but I am curious why the xlsx.js library does not directly handle this situation when merging
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#3090
No description provided.