1 package com.calipso.reportgenerator.reportmanager; 2 3 import com.calipso.reportgenerator.common.InfoException; 4 import com.calipso.reportgenerator.common.LanguageTraslator; 5 6 12 public class ExcelSheetPosition { 13 14 private static final String columns = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 16 17 private String columnName; 18 private int row; 19 private short column; 20 21 26 public ExcelSheetPosition(String position) throws InfoException{ 27 if(position==null || position.equalsIgnoreCase("")){ 28 throw new InfoException(LanguageTraslator.traslate("379")); 29 } 30 position = position.toUpperCase(); 31 columnName = getLetters(position); 32 row = Integer.parseInt(getNumbers(position.substring(columnName.length()))); 33 column = getIndexFor(columnName); 34 } 35 36 41 public ExcelSheetPosition(int row, short column){ 42 this.row = row; 43 this.column = column; 44 } 45 46 52 public ExcelSheetPosition(String columnName, int row) throws InfoException { 53 this.row = row; 54 this.columnName = columnName; 55 this.column = getIndexFor(columnName); 56 } 57 58 65 private short getIndexFor(String columnName) throws InfoException { 66 if(columnName.length()==1){ 67 return (short)columns.indexOf(columnName); 68 }else if(columnName.length()==2){ 69 if(columns.indexOf(columnName.substring(0,1)) < 10){ 70 return (short)(26*(columns.indexOf(columnName.substring(0,1)) + 1) + columns.indexOf(columnName.substring(1))); 71 } 72 } 73 throw new InfoException(LanguageTraslator.traslate("378") + columnName); 74 } 75 76 81 private String getNumbers(String position) { 82 StringBuffer buffer = new StringBuffer (); 83 for(int i=0;i < position.length(); i++){ 84 if(Character.isDigit(position.charAt(i))){ 85 buffer.append(position.charAt(i)); 86 }else{ 87 break; 88 } 89 } 90 return buffer.toString(); 91 } 92 93 98 private String getLetters(String position) { 99 StringBuffer buffer = new StringBuffer (); 100 for(int i=0;i < position.length(); i++){ 101 if(Character.isLetter(position.charAt(i))){ 102 buffer.append(position.charAt(i)); 103 }else{ 104 break; 105 } 106 } 107 return buffer.toString(); 108 } 109 110 public int getRow() { 111 return row; 112 } 113 114 public short getColumn() { 115 return column; 116 } 117 118 public void setRow(int row) { 119 this.row = row; 120 } 121 122 public void setColumn(short column) { 123 this.column = column; 124 } 125 } 126 | Popular Tags |