Skip to content

Commit

Permalink
Merge pull request #1 from manikk/master
Browse files Browse the repository at this point in the history
Increasing the no. of columns support
  • Loading branch information
Intellipharm authored May 24, 2018
2 parents 7a873f1 + 7f419ac commit 3332925
Show file tree
Hide file tree
Showing 3 changed files with 700 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/scripts/models/worksheet-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ window.JSFile = window.JSFile || {};
self[cell_letter + cell_number] = new module.WorksheetCell({type: 's', value: item.value});

// increment letter
cell_letter = module.FileUtil.nextLetter(cell_letter);
//cell_letter = module.FileUtil.nextLetter(cell_letter);
cell_letter = module.FileUtil.nextColumn(cell_letter);

// count letters
_letter_count++;
Expand Down
39 changes: 38 additions & 1 deletion src/scripts/utils/file-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ window.JSFile = window.JSFile || {};
}

// increment letter
letter = self.nextLetter(letter);
letter = self.nextColumn(letter);
});

});
Expand Down Expand Up @@ -439,6 +439,43 @@ window.JSFile = window.JSFile || {};

return result;
};

this.nextColumn = function(currentColumn) {
//Logic only works upto two series column - A ... ZZ
//As it supports around 702 columns, in which practically we wouldn't hit

var charCode;

// convert letter to upper case
currentColumn = currentColumn.toUpperCase();
var nxtColumn = "";

if(currentColumn.length > 2) {
console.warn("Only 702 columns are supported");
}

if(currentColumn[currentColumn.length -1] === "Z" ) {
// Generate unicode value for given character
charCode = currentColumn.charCodeAt(0);
var suffix = "A";
if(charCode < 90) {
// Convert integer to character
nxtColumn = String.fromCharCode(charCode + 1) + suffix;
} else {
suffix += "A";
nxtColumn = suffix;
}

} else {
// Generate unicode value for given character
charCode = currentColumn[currentColumn.length -1].charCodeAt(0);
var prefix = currentColumn.slice(0, -1);
// Convert integer to character
nxtColumn = prefix + String.fromCharCode(charCode + 1);
}

return nxtColumn;
};
};

// create singleton
Expand Down
Loading

0 comments on commit 3332925

Please sign in to comment.