Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sheet_to_csv skips first blank line with blankrows: true option #2752

Open
pibi opened this issue Aug 2, 2022 · 9 comments
Open

sheet_to_csv skips first blank line with blankrows: true option #2752

pibi opened this issue Aug 2, 2022 · 9 comments

Comments

@pibi
Copy link

pibi commented Aug 2, 2022

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
@SheetJSDev
Copy link
Contributor

This is an aoa_to_sheet issue. It will generate a sheet where the starting cell is A2 rather than A1. See #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);
  }

@anmol5varma
Copy link

Is the issue still open? I would like to take it up if that is the case.

sankhavaramsaitulasiram added a commit to sankhavaramsaitulasiram/sheetjs that referenced this issue Aug 26, 2022
…true option

sheet_to_csv skips first blank line with blankrows: true option
@anshul137
Copy link

Is the issue still open? I would like to take it up if that is the case.

@PrathyushaModala
Copy link

Hi @pibi ,
I'd like to work on this, could you please assign me :)

@naikmohit13
Copy link

is it still open?

@sayantandasgupta
Copy link

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.

@VanshSutariya
Copy link

"Hello, I have a solution for this issue. If it has not been solved yet, I would love to solve it."

@VanshSutariya
Copy link

by using Array(7).fill('') as a blank row we can solve this issue

@adesh1998
Copy link

could you assign this issue to me? @pibi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants