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

last column of spreadsheet is lost if first column is blank #37

Closed
mitchellsundt opened this issue Oct 28, 2013 · 2 comments
Closed

last column of spreadsheet is lost if first column is blank #37

mitchellsundt opened this issue Oct 28, 2013 · 2 comments

Comments

@mitchellsundt
Copy link

Two bugs in parseSheet():

(1) the dimension test logic always fails, so the sheet dimension is never set.

(2) the column-index logic in parseSheet() is wrong -- it assumes one-based, but the cells.forEach() uses zero-based, so the -1 corrections are not appropriate.

Patch:

diff -r ac083a41a811 xlsxconverter/WebContent/js-xlsx/xlsx.js
--- a/xlsxconverter/WebContent/js-xlsx/xlsx.js  Mon Oct 28 12:42:35 2013 -0700
+++ b/xlsxconverter/WebContent/js-xlsx/xlsx.js  Mon Oct 28 12:44:41 2013 -0700
@@ -533,7 +533,7 @@

    /* 18.3.1.35 dimension CT_SheetDimension ? */
    var ref = data.match(/<dimension ref="([^"]*)"\s*\/>/);
-   if(ref && ref.indexOf(":") !== -1) s["!ref"] = ref[1];
+   if(ref && ref.length == 2 && ref[1].indexOf(":") !== -1) s["!ref"] = ref[1];

    var refguess = {s: {r:1000000, c:1000000}, e: {r:0, c:0} };
    var q = ["v","f"];
@@ -552,8 +552,9 @@
        var cells = x.substr(x.indexOf('>')+1).split(/<c/);
        cells.forEach(function(c, idx) { if(c === "" || c.trim() === "") return;
            c = "<c" + c;
-           if(refguess.s.c > idx - 1) refguess.s.c = idx - 1;
-           if(refguess.e.c < idx - 1) refguess.e.c = idx - 1;
+           // idx is already zero-based
+           if(refguess.s.c > idx) refguess.s.c = idx;
+           if(refguess.e.c < idx) refguess.e.c = idx;
            var cell = parsexmltag((c.match(/<c[^>]*>/)||[c])[0]); delete cell[0];
            var d = c.substr(c.indexOf('>')+1);
            var p = {};
@@ -600,7 +601,8 @@
            s[cell.r] = p;
        });
    });
-   if(!s["!ref"]) s["!ref"] = encode_range(refguess);
+   var rguess = encode_range(refguess);
+   if(!s["!ref"]) s["!ref"] = rguess;
    return s;
 }

@redchair123
Copy link

@mitchellsundt confirm that this works

@mitchellsundt
Copy link
Author

Confirmed

On Mon, Oct 28, 2013 at 1:31 PM, Niggler notifications@github.com wrote:

@mitchellsundt https://github.com/mitchellsundt confirm that this works


Reply to this email directly or view it on GitHubhttps://github.com//issues/37#issuecomment-27253149
.

Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

SheetJSDev added a commit that referenced this issue Dec 6, 2013
@SheetJS SheetJS locked and limited conversation to collaborators Feb 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants