acoliver    02/04/28 11:23:06

  Modified:    src/java/org/apache/poi/hssf/util ReferenceUtil.java
  Log:
  created functions to go the other direction row,col = cellref "A1"
  
  Revision  Changes    Path
  1.4       +33 -3     jakarta-poi/src/java/org/apache/poi/hssf/util/ReferenceUtil.java
  
  Index: ReferenceUtil.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/util/ReferenceUtil.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ReferenceUtil.java        28 Apr 2002 18:02:21 -0000      1.3
  +++ ReferenceUtil.java        28 Apr 2002 18:23:06 -0000      1.4
  @@ -20,8 +20,8 @@
        * takes in a cell reference string A1 for instance and returns an integer
        * array with the first element being the row number and the second being 
        * the column number, all in 0-based base 10 format.
  -     *
  -     * @return xyarray row and column number
  +     * @param reference a cell reference such as A1 or AA1 or IV1
  +     * @return xyarray int array containing row and column number
        */
       public static int[] getXYFromReference(String reference) {
              int[] retval = new int[2];
  @@ -32,6 +32,36 @@
       }
       
       /**
  +     * takes in a row and column and returns a string cellref
  +     * @param row the 0 based row such as 0 
  +     * @param col the 0 based col number such as 1 
  +     * @return cellreference string such as B1
  +     */
  +    public static String getReferenceFromXY(int row, int col) {
  +        String retval = convertNumToColString(col) + ""+(row+1);
  +        return retval;
  +    }
  +    
  +    /**
  +     * takes in a 0-based base-10 column and returns a ALPHA-26 representation
  +     */
  +    private static String convertNumToColString(int col) {
  +        String retval = null;
  +        int mod = col % 26;
  +        int div = col / 26;
  +        char small=(char)(mod + 65);
  +        char big = (char)(div + 64);
  +                
  +        if (div == 0) {
  +            retval = ""+small;
  +        } else {
  +            retval = ""+big+""+small;
  +        }
  +        
  +        return retval;
  +    }
  +    
  +    /**
        * takes in a column reference portion of a CellRef and converts it from 
        * ALPHA-26 number format to 0-based base 10.
        */
  @@ -74,5 +104,5 @@
           retval[1] = reference.substring(loc);        
           return retval;
       }
  -    
  +        
   }
  
  
  


Reply via email to