]> gerrit.simantics Code Review - simantics/interop.git/blob - org.simantics.excel.poi/src/org/simantics/excel/poi/parser/streaming/CellImpl.java
Reducing use of deprecated code: using CellType enum instead of int for
[simantics/interop.git] / org.simantics.excel.poi / src / org / simantics / excel / poi / parser / streaming / CellImpl.java
1 package org.simantics.excel.poi.parser.streaming;\r
2 \r
3 import java.util.Calendar;\r
4 import java.util.Date;\r
5 \r
6 import org.apache.poi.ss.formula.FormulaParseException;\r
7 import org.apache.poi.ss.usermodel.Cell;\r
8 import org.apache.poi.ss.usermodel.CellStyle;\r
9 import org.apache.poi.ss.usermodel.CellType;\r
10 import org.apache.poi.ss.usermodel.Comment;\r
11 import org.apache.poi.ss.usermodel.ExcelStyleDateFormatter;\r
12 import org.apache.poi.ss.usermodel.Hyperlink;\r
13 import org.apache.poi.ss.usermodel.RichTextString;\r
14 import org.apache.poi.ss.usermodel.Row;\r
15 import org.apache.poi.ss.usermodel.Sheet;\r
16 import org.apache.poi.ss.util.CellAddress;\r
17 import org.apache.poi.ss.util.CellRangeAddress;\r
18 \r
19 public class CellImpl implements Cell{\r
20         \r
21         private RowImpl row;\r
22         private int index;\r
23         \r
24         public CellImpl(RowImpl row, int index) {\r
25                 this.row = row;\r
26                 this.index = index;\r
27         }\r
28         \r
29         \r
30         private String getType() {\r
31                 return row.cellTypes.get(index);\r
32         }\r
33         \r
34         @Override\r
35         public boolean getBooleanCellValue() {\r
36                 return 1 == Integer.parseInt(getStringCellValue());\r
37         }\r
38         \r
39         @Override\r
40         public Date getDateCellValue() {\r
41                 ExcelStyleDateFormatter formatter = new ExcelStyleDateFormatter(""); //FIXME: date format\r
42                 try {\r
43                         return formatter.parse(getStringCellValue());\r
44                 } catch (Exception e) {\r
45                         return null;\r
46                 }\r
47         }\r
48         \r
49         @Override\r
50         public byte getErrorCellValue() {\r
51                 // TODO Auto-generated method stub\r
52                 return 0;\r
53         }\r
54         \r
55         @Override\r
56         public double getNumericCellValue() {\r
57                 return Double.parseDouble(getStringCellValue());\r
58         }\r
59         \r
60         @Override\r
61         public RichTextString getRichStringCellValue() {\r
62                 return null;\r
63         }\r
64         \r
65         @Override\r
66         public String getStringCellValue() {\r
67                 return row.cellData.get(index);\r
68         }\r
69         \r
70         \r
71         @Override\r
72         public int getCellType() {\r
73                 String type = getType();\r
74                 if ("v".equals(type)) {\r
75                         return CELL_TYPE_NUMERIC;\r
76                 } else if ("n".equals(type)) {\r
77                         return CELL_TYPE_NUMERIC;\r
78                 } else if ("s".equals(type)) {\r
79                         return CELL_TYPE_STRING;\r
80                 } else if ("b".equals(type)) {\r
81                         return CELL_TYPE_STRING;\r
82                 } else if ("inlineStr".equals(type)) {\r
83                         return CELL_TYPE_STRING;\r
84                 }\r
85                 return CELL_TYPE_STRING;\r
86         }\r
87         \r
88 \r
89         \r
90         \r
91         @Override\r
92         public Row getRow() {\r
93                 return row;\r
94         }\r
95         \r
96         @Override\r
97         public int getRowIndex() {\r
98                 return row.getRowNum();\r
99         }\r
100         \r
101         \r
102         @Override\r
103         public CellRangeAddress getArrayFormulaRange() {\r
104                 return null;\r
105         }\r
106         \r
107         \r
108         @Override\r
109         public int getCachedFormulaResultType() {\r
110                 return 0;\r
111         }\r
112         \r
113         @Override\r
114         public Comment getCellComment() {\r
115                 return null;\r
116         }\r
117         \r
118         @Override\r
119         public String getCellFormula() {\r
120                 return null;\r
121         }\r
122         \r
123         @Override\r
124         public CellStyle getCellStyle() {\r
125                 return null;\r
126         }\r
127         \r
128         @Override\r
129         public int getColumnIndex() {\r
130                 return index;\r
131         }\r
132         \r
133         @Override\r
134         public Hyperlink getHyperlink() {\r
135                 return null;\r
136         }\r
137         \r
138         \r
139         @Override\r
140         public Sheet getSheet() {\r
141                 return row.getSheet();\r
142         }\r
143         \r
144         @Override\r
145         public boolean isPartOfArrayFormulaGroup() {\r
146                 return false;\r
147         }\r
148         \r
149         @Override\r
150         public void removeCellComment() {\r
151                 \r
152         }\r
153         \r
154         @Override\r
155         public void setAsActiveCell() {\r
156                 \r
157         }\r
158         \r
159         @Override\r
160         public void setCellComment(Comment comment) {\r
161                 \r
162         }\r
163         \r
164         @Override\r
165         public void setCellErrorValue(byte value) {\r
166                 \r
167         }\r
168         \r
169         @Override\r
170         public void setCellFormula(String formula) throws FormulaParseException {\r
171                 \r
172         }\r
173         \r
174         @Override\r
175         public void setCellStyle(CellStyle style) {\r
176                 \r
177         }\r
178         \r
179         @Override\r
180         public void setCellType(int cellType) {\r
181                 \r
182         }\r
183         \r
184         @Override\r
185         public void setCellValue(boolean value) {\r
186                 \r
187         }\r
188         \r
189         @Override\r
190         public void setCellValue(Calendar value) {\r
191                 \r
192         }\r
193         \r
194         @Override\r
195         public void setCellValue(Date value) {\r
196                 \r
197         }\r
198         \r
199         @Override\r
200         public void setCellValue(double value) {\r
201                 \r
202         }\r
203         \r
204         @Override\r
205         public void setCellValue(RichTextString value) {\r
206                 \r
207         }\r
208         \r
209         @Override\r
210         public void setCellValue(String value) {\r
211                 \r
212         }\r
213         \r
214         @Override\r
215         public void setHyperlink(Hyperlink link) {\r
216                 \r
217         }\r
218 \r
219 \r
220         @Override\r
221         public CellAddress getAddress() {\r
222                 return new CellAddress(this);\r
223         }\r
224 \r
225 \r
226         @Override\r
227         public CellType getCachedFormulaResultTypeEnum() {\r
228                 throw new UnsupportedOperationException();\r
229         }\r
230 \r
231 \r
232         @Override\r
233         public CellType getCellTypeEnum() {\r
234                 String type = getType();\r
235                 if ("v".equals(type)) {\r
236                         return CellType.NUMERIC;\r
237                 } else if ("n".equals(type)) {\r
238                         return CellType.NUMERIC;\r
239                 } else if ("s".equals(type)) {\r
240                         return CellType.STRING;\r
241                 } else if ("b".equals(type)) {\r
242                         return CellType.STRING;\r
243                 } else if ("inlineStr".equals(type)) {\r
244                         return CellType.STRING;\r
245                 }\r
246                 return CellType.STRING;\r
247         }\r
248         \r
249         @Override\r
250         public void setCellType(CellType arg0) {\r
251                 throw new UnsupportedOperationException();\r
252         }\r
253         \r
254 \r
255 \r
256         @Override\r
257         public void removeHyperlink() {\r
258                 throw new UnsupportedOperationException();\r
259         }\r
260         \r
261 \r
262 }\r