Source Code Cross Referenced for CellReference.java in  » Collaboration » poi-3.0.2-beta2 » org » apache » poi » hssf » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Collaboration » poi 3.0.2 beta2 » org.apache.poi.hssf.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ====================================================================
002:           Licensed to the Apache Software Foundation (ASF) under one or more
003:           contributor license agreements.  See the NOTICE file distributed with
004:           this work for additional information regarding copyright ownership.
005:           The ASF licenses this file to You under the Apache License, Version 2.0
006:           (the "License"); you may not use this file except in compliance with
007:           the License.  You may obtain a copy of the License at
008:
009:               http://www.apache.org/licenses/LICENSE-2.0
010:
011:           Unless required by applicable law or agreed to in writing, software
012:           distributed under the License is distributed on an "AS IS" BASIS,
013:           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:           See the License for the specific language governing permissions and
015:           limitations under the License.
016:        ==================================================================== */
017:
018:        package org.apache.poi.hssf.util;
019:
020:        /**
021:         *
022:         * @author  Avik Sengupta
023:         * @author  Dennis Doubleday (patch to seperateRowColumns())
024:         */
025:        public class CellReference {
026:
027:            /** Creates new CellReference */
028:            private int row;
029:            private int col;
030:            private String sheetName;
031:            private boolean rowAbs;
032:            private boolean colAbs;
033:
034:            public CellReference(String cellRef) {
035:                String[] parts = separateRefParts(cellRef);
036:                sheetName = parts[0];
037:                String ref = parts[1];
038:                if ((ref == null) || ("".equals(ref)))
039:                    throw new IllegalArgumentException(
040:                            "Invalid Formula cell reference: '" + cellRef + "'");
041:                if (ref.charAt(0) == '$') {
042:                    colAbs = true;
043:                    ref = ref.substring(1);
044:                }
045:                col = convertColStringToNum(ref);
046:                ref = parts[2];
047:                if ((ref == null) || ("".equals(ref)))
048:                    throw new IllegalArgumentException(
049:                            "Invalid Formula cell reference: '" + cellRef + "'");
050:                if (ref.charAt(0) == '$') {
051:                    rowAbs = true;
052:                    ref = ref.substring(1);
053:                }
054:                row = Integer.parseInt(ref) - 1;
055:            }
056:
057:            public CellReference(int pRow, int pCol) {
058:                this (pRow, pCol, false, false);
059:            }
060:
061:            public CellReference(int pRow, int pCol, boolean pAbsRow,
062:                    boolean pAbsCol) {
063:                row = pRow;
064:                col = pCol;
065:                rowAbs = pAbsRow;
066:                colAbs = pAbsCol;
067:
068:            }
069:
070:            public int getRow() {
071:                return row;
072:            }
073:
074:            public short getCol() {
075:                return (short) col;
076:            }
077:
078:            public boolean isRowAbsolute() {
079:                return rowAbs;
080:            }
081:
082:            public boolean isColAbsolute() {
083:                return colAbs;
084:            }
085:
086:            public String getSheetName() {
087:                return sheetName;
088:            }
089:
090:            /**
091:             * takes in a column reference portion of a CellRef and converts it from
092:             * ALPHA-26 number format to 0-based base 10.
093:             */
094:            private int convertColStringToNum(String ref) {
095:                int len = ref.length();
096:                int retval = 0;
097:                int pos = 0;
098:
099:                for (int k = ref.length() - 1; k > -1; k--) {
100:                    char thechar = ref.charAt(k);
101:                    if (pos == 0) {
102:                        retval += (Character.getNumericValue(thechar) - 9);
103:                    } else {
104:                        retval += (Character.getNumericValue(thechar) - 9)
105:                                * (pos * 26);
106:                    }
107:                    pos++;
108:                }
109:                return retval - 1;
110:            }
111:
112:            /**
113:             * Seperates the row from the columns and returns an array.  Element in
114:             * position one is the substring containing the columns still in ALPHA-26
115:             * number format.
116:             */
117:            private String[] separateRefParts(String reference) {
118:
119:                // Look for end of sheet name. This will either set
120:                // start to 0 (if no sheet name present) or the
121:                // index after the sheet reference ends.
122:                String retval[] = new String[3];
123:
124:                int start = reference.indexOf("!");
125:                if (start != -1)
126:                    retval[0] = reference.substring(0, start);
127:                start += 1;
128:
129:                int length = reference.length();
130:
131:                char[] chars = reference.toCharArray();
132:                int loc = start;
133:                if (chars[loc] == '$')
134:                    loc++;
135:                for (; loc < chars.length; loc++) {
136:                    if (Character.isDigit(chars[loc]) || chars[loc] == '$') {
137:                        break;
138:                    }
139:                }
140:
141:                retval[1] = reference.substring(start, loc);
142:                retval[2] = reference.substring(loc);
143:                return retval;
144:            }
145:
146:            /**
147:             * takes in a 0-based base-10 column and returns a ALPHA-26 representation
148:             */
149:            private static String convertNumToColString(int col) {
150:                String retval = null;
151:                int mod = col % 26;
152:                int div = col / 26;
153:                char small = (char) (mod + 65);
154:                char big = (char) (div + 64);
155:
156:                if (div == 0) {
157:                    retval = "" + small;
158:                } else {
159:                    retval = "" + big + "" + small;
160:                }
161:
162:                return retval;
163:            }
164:
165:            public String toString() {
166:                StringBuffer retval = new StringBuffer();
167:                retval.append((colAbs) ? "$" : "");
168:                retval.append(convertNumToColString(col));
169:                retval.append((rowAbs) ? "$" : "");
170:                retval.append(row + 1);
171:
172:                return retval.toString();
173:            }
174:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.