Skip to content

Commit

Permalink
add support for columns AA-ZZ
Browse files Browse the repository at this point in the history
  • Loading branch information
qqmyers committed May 29, 2019
1 parent 02c36c4 commit 34b64b6
Showing 1 changed file with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -359,21 +359,43 @@ public void startElement(String uri, String localName, String name,
cellContents = "";
}

/* Works from 1-702 columns. Could be made recursive to work beyond that*/
private int getColumnCount(String columnTag) {
int count = -1;
if (columnTag.length() == 1 && columnTag.matches("[A-Z]")) {
count = columnTag.charAt(0) - 'A';
} else {
dbglog.warning("Unsupported column index tag: "+columnTag);
if (columnTag.length() == 2) {
int c1 = columnTag.charAt(0) - 'A';
int c2 = columnTag.charAt(1) - 'A';
if (c1 >= 0 && c1 < 26 && c2 >= 0 && c2 < 26) {
dbglog.fine(columnTag + ": " + ((c1 + 1) * 26 + c2));
return ((c1 + 1) * 26 + c2);
} else {
dbglog.warning("Unsupported column index tag: " + columnTag);
}
} else {
dbglog.warning("Unsupported column index tag: " + columnTag);
}
}

return count;
}

/* Supports A-Z and AA-ZZ (0-701 column count/position) */
private String getColumnLetterTag(int columnCount) {
if (columnCount < 0 || columnCount > 25) {
dbglog.warning("Multi-letter column codes not yet supported.");
return null;
if(columnCount >25 && columnCount < 702) { //AA-ZZ
int code1 = 'A' + columnCount/26 -1;
int code2 = 'A' + columnCount%26;
char[] letterTag = new char[2];
letterTag[0] = (char)code1;
letterTag[1] = (char)code2;
dbglog.fine(columnCount + ": " + new String(letterTag));
return new String(letterTag);
} else {
dbglog.warning("3+ letter column codes not yet supported.");
return null;
}
}
int letterCode = 'A' + columnCount;
char[] letterTag = new char[1];
Expand Down

0 comments on commit 34b64b6

Please sign in to comment.