sheetjs
sheetjs copied to clipboard
sheet_to_csv skips first blank line with blankrows: true option
sheet_to_csv skips the first blank line of a sheet, even with an explicit {blankrows: true}
set.
Code sample:
var ws = XLSX.utils.aoa_to_sheet([
[ , , , , , , ],
["S", "h", "e", "e", "t", "J", "S"],
[ , , , , , , ],
[ 1, 2, , , 5, 6, 7],
[ 2, 3, , , 6, 7, 8],
[ 3, 4, , , 7, 8, 9],
[ 4, 5, 6, 7, 8, 9, 0]
]);
console.log(XLSX.utils.sheet_to_csv(ws, {blankrows: true}));
Result:
S,h,e,e,t,J,S
,,,,,,
1,2,,,5,6,7
2,3,,,6,7,8
3,4,,,7,8,9
4,5,6,7,8,9,0
Expected:
,,,,,,
S,h,e,e,t,J,S
,,,,,,
1,2,,,5,6,7
2,3,,,6,7,8
3,4,,,7,8,9
4,5,6,7,8,9,0
This is an aoa_to_sheet
issue. It will generate a sheet where the starting cell is A2 rather than A1. See https://github.com/SheetJS/sheetjs/issues/2737 for more details on why the range is relevant.
The simplest fix is to pin the starting point to the origin in https://github.com/SheetJS/sheetjs/blob/master/bits/27_csfutils.js#L176 (we'll accept a PR):
if(range.s.c < 10000000) {
if(range.s.c > _C) range.s.c = _C;
if(range.s.r > _R) range.s.r = _R;
ws['!ref'] = encode_range(range);
}
Is the issue still open? I would like to take it up if that is the case.
Is the issue still open? I would like to take it up if that is the case.
Hi @pibi , I'd like to work on this, could you please assign me :)
is it still open?
Has this issue been solved? I am seeing a PR request for a fix. If the issue has not been solved I would like to take it up.
"Hello, I have a solution for this issue. If it has not been solved yet, I would love to solve it."
by using Array(7).fill('') as a blank row we can solve this issue
could you assign this issue to me? @pibi