]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
Excel parsing interface
authorMarko Luukkainen <marko.luukkainen@vtt.fi>
Thu, 2 Feb 2017 13:06:06 +0000 (15:06 +0200)
committerMarko Luukkainen <marko.luukkainen@vtt.fi>
Thu, 2 Feb 2017 13:06:06 +0000 (15:06 +0200)
refs #7012

Change-Id: I49f4880147ccdd0f6b9eab4294c41f2335df6761

21 files changed:
org.simantics.excel.poi/.classpath [new file with mode: 0644]
org.simantics.excel.poi/.gitignore [new file with mode: 0644]
org.simantics.excel.poi/.project [new file with mode: 0644]
org.simantics.excel.poi/.settings/org.eclipse.jdt.core.prefs [new file with mode: 0644]
org.simantics.excel.poi/META-INF/MANIFEST.MF [new file with mode: 0644]
org.simantics.excel.poi/build.properties [new file with mode: 0644]
org.simantics.excel.poi/src/org/simantics/excel/poi/Activator.java [new file with mode: 0644]
org.simantics.excel.poi/src/org/simantics/excel/poi/parser/CellBooleanDataResolver.java [new file with mode: 0644]
org.simantics.excel.poi/src/org/simantics/excel/poi/parser/CellContentDataResolver.java [new file with mode: 0644]
org.simantics.excel.poi/src/org/simantics/excel/poi/parser/CellDataResolverBase.java [new file with mode: 0644]
org.simantics.excel.poi/src/org/simantics/excel/poi/parser/CellDoubleDataResolver.java [new file with mode: 0644]
org.simantics.excel.poi/src/org/simantics/excel/poi/parser/CellStringArrayDataResolver.java [new file with mode: 0644]
org.simantics.excel.poi/src/org/simantics/excel/poi/parser/CellStringDataResolver.java [new file with mode: 0644]
org.simantics.excel.poi/src/org/simantics/excel/poi/parser/ColumnResolver.java [new file with mode: 0644]
org.simantics.excel.poi/src/org/simantics/excel/poi/parser/DataResolver.java [new file with mode: 0644]
org.simantics.excel.poi/src/org/simantics/excel/poi/parser/streaming/CellImpl.java [new file with mode: 0644]
org.simantics.excel.poi/src/org/simantics/excel/poi/parser/streaming/RowImpl.java [new file with mode: 0644]
org.simantics.excel.poi/src/org/simantics/excel/poi/parser/streaming/SheetImpl.java [new file with mode: 0644]
org.simantics.excel.poi/src/org/simantics/excel/poi/parser/streaming/StreamingParser.java [new file with mode: 0644]
org.simantics.excel.poi/src/org/simantics/excel/poi/parser/streaming/XSSSheetHandler.java [new file with mode: 0644]
org.simantics.excel.poi/src/org/simantics/excel/poi/parser/streaming/XSSWorkbookHandler.java [new file with mode: 0644]

diff --git a/org.simantics.excel.poi/.classpath b/org.simantics.excel.poi/.classpath
new file mode 100644 (file)
index 0000000..b862a29
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<classpath>\r
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>\r
+       <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>\r
+       <classpathentry kind="src" path="src"/>\r
+       <classpathentry kind="output" path="bin"/>\r
+</classpath>\r
diff --git a/org.simantics.excel.poi/.gitignore b/org.simantics.excel.poi/.gitignore
new file mode 100644 (file)
index 0000000..ae3c172
--- /dev/null
@@ -0,0 +1 @@
+/bin/
diff --git a/org.simantics.excel.poi/.project b/org.simantics.excel.poi/.project
new file mode 100644 (file)
index 0000000..33943a7
--- /dev/null
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<projectDescription>\r
+       <name>org.simantics.excel.poi</name>\r
+       <comment></comment>\r
+       <projects>\r
+       </projects>\r
+       <buildSpec>\r
+               <buildCommand>\r
+                       <name>org.eclipse.jdt.core.javabuilder</name>\r
+                       <arguments>\r
+                       </arguments>\r
+               </buildCommand>\r
+               <buildCommand>\r
+                       <name>org.eclipse.pde.ManifestBuilder</name>\r
+                       <arguments>\r
+                       </arguments>\r
+               </buildCommand>\r
+               <buildCommand>\r
+                       <name>org.eclipse.pde.SchemaBuilder</name>\r
+                       <arguments>\r
+                       </arguments>\r
+               </buildCommand>\r
+       </buildSpec>\r
+       <natures>\r
+               <nature>org.eclipse.pde.PluginNature</nature>\r
+               <nature>org.eclipse.jdt.core.javanature</nature>\r
+       </natures>\r
+</projectDescription>\r
diff --git a/org.simantics.excel.poi/.settings/org.eclipse.jdt.core.prefs b/org.simantics.excel.poi/.settings/org.eclipse.jdt.core.prefs
new file mode 100644 (file)
index 0000000..295926d
--- /dev/null
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1\r
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled\r
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8\r
+org.eclipse.jdt.core.compiler.compliance=1.8\r
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error\r
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error\r
+org.eclipse.jdt.core.compiler.source=1.8\r
diff --git a/org.simantics.excel.poi/META-INF/MANIFEST.MF b/org.simantics.excel.poi/META-INF/MANIFEST.MF
new file mode 100644 (file)
index 0000000..4356d5c
--- /dev/null
@@ -0,0 +1,13 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Excel / Apache POI
+Bundle-SymbolicName: org.simantics.excel.poi
+Bundle-Version: 1.0.0.qualifier
+Bundle-Activator: org.simantics.excel.poi.Activator
+Bundle-Vendor: VTT
+Require-Bundle: org.eclipse.core.runtime,
+ org.apache.poi;bundle-version="3.15.0"
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
+Bundle-ActivationPolicy: lazy
+Export-Package: org.simantics.excel.poi.parser,
+ org.simantics.excel.poi.parser.streaming
diff --git a/org.simantics.excel.poi/build.properties b/org.simantics.excel.poi/build.properties
new file mode 100644 (file)
index 0000000..41eb6ad
--- /dev/null
@@ -0,0 +1,4 @@
+source.. = src/\r
+output.. = bin/\r
+bin.includes = META-INF/,\\r
+               .\r
diff --git a/org.simantics.excel.poi/src/org/simantics/excel/poi/Activator.java b/org.simantics.excel.poi/src/org/simantics/excel/poi/Activator.java
new file mode 100644 (file)
index 0000000..68aaf2f
--- /dev/null
@@ -0,0 +1,30 @@
+package org.simantics.excel.poi;\r
+\r
+import org.osgi.framework.BundleActivator;\r
+import org.osgi.framework.BundleContext;\r
+\r
+public class Activator implements BundleActivator {\r
+\r
+       private static BundleContext context;\r
+\r
+       static BundleContext getContext() {\r
+               return context;\r
+       }\r
+\r
+       /*\r
+        * (non-Javadoc)\r
+        * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)\r
+        */\r
+       public void start(BundleContext bundleContext) throws Exception {\r
+               Activator.context = bundleContext;\r
+       }\r
+\r
+       /*\r
+        * (non-Javadoc)\r
+        * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)\r
+        */\r
+       public void stop(BundleContext bundleContext) throws Exception {\r
+               Activator.context = null;\r
+       }\r
+\r
+}\r
diff --git a/org.simantics.excel.poi/src/org/simantics/excel/poi/parser/CellBooleanDataResolver.java b/org.simantics.excel.poi/src/org/simantics/excel/poi/parser/CellBooleanDataResolver.java
new file mode 100644 (file)
index 0000000..b2e12de
--- /dev/null
@@ -0,0 +1,22 @@
+package org.simantics.excel.poi.parser;\r
+\r
+import org.apache.poi.ss.usermodel.Row;\r
+\r
+public class CellBooleanDataResolver extends CellDataResolverBase<Boolean> {\r
+       int column;\r
+       \r
+       public CellBooleanDataResolver(int column) {\r
+               super();\r
+               this.column = column;\r
+       }\r
+       \r
+       @Override\r
+       public Boolean getValue(Row row) {\r
+               if (row == null)\r
+                       return null;\r
+               return getCellBooleanValue(getCell(row, column));\r
+       }\r
+       \r
+       \r
+\r
+}\r
diff --git a/org.simantics.excel.poi/src/org/simantics/excel/poi/parser/CellContentDataResolver.java b/org.simantics.excel.poi/src/org/simantics/excel/poi/parser/CellContentDataResolver.java
new file mode 100644 (file)
index 0000000..e84c04d
--- /dev/null
@@ -0,0 +1,61 @@
+package org.simantics.excel.poi.parser;\r
+\r
+import org.apache.poi.ss.usermodel.Row;\r
+\r
+public class CellContentDataResolver extends CellStringDataResolver {\r
+       int column;\r
+       int element;\r
+       String separator;\r
+       boolean cut = true;\r
+       \r
+       public CellContentDataResolver(int column, int element, String separator) {\r
+               super(column);\r
+               this.column = column;\r
+               this.element = element;\r
+               this.separator = separator;\r
+       }\r
+       \r
+       public CellContentDataResolver(int column, int element, String separator, boolean cut) {\r
+               super(column);\r
+               this.column = column;\r
+               this.element = element;\r
+               this.separator = separator;\r
+               this.cut = cut;\r
+       }\r
+\r
+//     @Override\r
+//     public Double getDouble(Row row) {\r
+//             String s =  getSubString(row);\r
+//             if (s != null) {\r
+//                     return Double.parseDouble(s);\r
+//             }\r
+//             return null;\r
+//     }\r
+       \r
+       @Override\r
+       public String getValue(Row row) {\r
+               if (row == null)\r
+                       return null;\r
+               return getSubString(row);\r
+       }\r
+       \r
+       protected String getSubString(Row row) {\r
+               String s =  getCellStringValue(getCell(row, column));\r
+               if (cut) {\r
+                       String vals[] = s.split(separator);\r
+                       if (vals.length > element) {\r
+                               return vals[element];\r
+                       }\r
+               } else {\r
+                       int index = -1;\r
+                       for (int i = 0; i < element; i++) {\r
+                               index = s.indexOf(separator,index+1);\r
+                               if (index == -1)\r
+                                       return null;\r
+                       }\r
+                       return s.substring(index+1);\r
+               }\r
+               return null;\r
+       }\r
+}\r
+\r
diff --git a/org.simantics.excel.poi/src/org/simantics/excel/poi/parser/CellDataResolverBase.java b/org.simantics.excel.poi/src/org/simantics/excel/poi/parser/CellDataResolverBase.java
new file mode 100644 (file)
index 0000000..5a78735
--- /dev/null
@@ -0,0 +1,88 @@
+package org.simantics.excel.poi.parser;\r
+\r
+import org.apache.poi.ss.usermodel.Cell;\r
+import org.apache.poi.ss.usermodel.Row;\r
+\r
+public abstract class CellDataResolverBase<T> implements DataResolver<T> {\r
+       \r
+               \r
+       protected Double getCellNumericValue(Cell cell) {\r
+               if (cell == null)\r
+                       return null;\r
+               switch (cell.getCellType()) {\r
+               case Cell.CELL_TYPE_BLANK:\r
+                       return null;\r
+               case Cell.CELL_TYPE_BOOLEAN:\r
+                       return null;\r
+               case Cell.CELL_TYPE_ERROR:\r
+                       return null;\r
+               case Cell.CELL_TYPE_FORMULA:\r
+                       return null;\r
+               case Cell.CELL_TYPE_NUMERIC:\r
+                       return cell.getNumericCellValue();\r
+               case Cell.CELL_TYPE_STRING:\r
+                       return null;\r
+                       \r
+               }\r
+               throw new RuntimeException();\r
+       }\r
+       \r
+       protected String getCellStringValue(Cell cell) {\r
+               if (cell == null)\r
+                       return null;\r
+               switch (cell.getCellType()) {\r
+               case Cell.CELL_TYPE_BLANK:\r
+                       return null;\r
+               case Cell.CELL_TYPE_BOOLEAN:\r
+                       return Boolean.toString(cell.getBooleanCellValue());\r
+               case Cell.CELL_TYPE_ERROR:\r
+                       return null;\r
+               case Cell.CELL_TYPE_FORMULA:\r
+                       return null;\r
+               case Cell.CELL_TYPE_NUMERIC:\r
+                       return Double.toString(cell.getNumericCellValue());\r
+               case Cell.CELL_TYPE_STRING:\r
+                       return cell.getStringCellValue();\r
+                       \r
+               }\r
+               throw new RuntimeException();\r
+       }\r
+       \r
+       protected Boolean getCellBooleanValue(Cell cell) {\r
+               if (cell == null)\r
+                       return null;\r
+               switch (cell.getCellType()) {\r
+               case Cell.CELL_TYPE_BLANK:\r
+                       return null;\r
+               case Cell.CELL_TYPE_BOOLEAN:\r
+                       return cell.getBooleanCellValue();\r
+               case Cell.CELL_TYPE_ERROR:\r
+                       return null;\r
+               case Cell.CELL_TYPE_FORMULA:\r
+                       return null;\r
+               case Cell.CELL_TYPE_NUMERIC:\r
+                       return null;\r
+               case Cell.CELL_TYPE_STRING:\r
+                       String value = cell.getStringCellValue();\r
+                       if ("true".equalsIgnoreCase(value))\r
+                               return true;\r
+                       if ("1".equalsIgnoreCase(value))\r
+                               return true;\r
+                       return false;           \r
+               }\r
+               throw new RuntimeException();\r
+       }\r
+       \r
+       protected Cell getCell(Row row, int colIndex) {\r
+               for (short i = row.getFirstCellNum(); i <= row.getLastCellNum(); i++) {\r
+                       Cell c = row.getCell(i);\r
+                       if (c == null)\r
+                               continue;\r
+                       if (c.getColumnIndex() == colIndex)\r
+                               return c;\r
+                       \r
+               }\r
+               return null;\r
+       }\r
+\r
+}\r
diff --git a/org.simantics.excel.poi/src/org/simantics/excel/poi/parser/CellDoubleDataResolver.java b/org.simantics.excel.poi/src/org/simantics/excel/poi/parser/CellDoubleDataResolver.java
new file mode 100644 (file)
index 0000000..53bad3a
--- /dev/null
@@ -0,0 +1,24 @@
+package org.simantics.excel.poi.parser;\r
+\r
+import org.apache.poi.ss.usermodel.Row;\r
+\r
+public class CellDoubleDataResolver extends CellDataResolverBase<Double> {\r
+       int column;\r
+       \r
+       public CellDoubleDataResolver(int column) {\r
+               super();\r
+               this.column = column;\r
+       }\r
+\r
+       @Override\r
+       public Double getValue(Row row) {\r
+               if (row == null)\r
+                       return null;\r
+               try {\r
+                       return getCellNumericValue(getCell(row, column));\r
+               } catch (Exception e) {\r
+                       return null;\r
+               }\r
+       }\r
+\r
+}\r
diff --git a/org.simantics.excel.poi/src/org/simantics/excel/poi/parser/CellStringArrayDataResolver.java b/org.simantics.excel.poi/src/org/simantics/excel/poi/parser/CellStringArrayDataResolver.java
new file mode 100644 (file)
index 0000000..4d6ce43
--- /dev/null
@@ -0,0 +1,59 @@
+package org.simantics.excel.poi.parser;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.apache.poi.ss.usermodel.Row;\r
+\r
+public class CellStringArrayDataResolver extends CellDataResolverBase<String[]>{\r
+       \r
+       int index[];\r
+       boolean all = false;\r
+       \r
+       public CellStringArrayDataResolver(int... index) {\r
+               this.index = index;\r
+       }\r
+       \r
+    public CellStringArrayDataResolver(List<Integer> index) {\r
+               this.index = new int[index.size()];\r
+               for (int i = 0; i < index.size(); i++) {\r
+                       this.index[i] = index.get(i);\r
+               }\r
+       }\r
+    \r
+    /**\r
+     * If resolver is parameterized with one index, return all values from all columns from the index. Default false.\r
+     * @param all\r
+     */\r
+    public CellStringArrayDataResolver setAll(boolean all) {\r
+               this.all = all;\r
+               return this;\r
+       }\r
+       \r
+       @Override\r
+       public String[] getValue(Row row) {\r
+               if (row == null)\r
+                       return null;\r
+               if (index.length > 1 || !all) {\r
+                       String data[] = new String[index.length];\r
+                       for (int i = 0; i < data.length; i++) {\r
+                               data[i] = getCellStringValue(getCell(row, index[i]));\r
+                       }\r
+                       return data;\r
+               } else {\r
+                       List<String> data = new ArrayList<String>();\r
+                       int i = index[0];\r
+                       while (true) {\r
+                               String value = getCellStringValue(getCell(row, i));\r
+                               if (value != null && value.length() > 0) {\r
+                                       data.add(value);\r
+                                       i++;\r
+                               } else {\r
+                                       break;\r
+                               }\r
+                       }\r
+                       return data.toArray(new String[data.size()]);\r
+               }\r
+       }\r
+\r
+}\r
diff --git a/org.simantics.excel.poi/src/org/simantics/excel/poi/parser/CellStringDataResolver.java b/org.simantics.excel.poi/src/org/simantics/excel/poi/parser/CellStringDataResolver.java
new file mode 100644 (file)
index 0000000..4c0929e
--- /dev/null
@@ -0,0 +1,22 @@
+package org.simantics.excel.poi.parser;\r
+\r
+import org.apache.poi.ss.usermodel.Row;\r
+\r
+public class CellStringDataResolver extends CellDataResolverBase<String> {\r
+       int column;\r
+       \r
+       public CellStringDataResolver(int column) {\r
+               super();\r
+               this.column = column;\r
+       }\r
+       \r
+       @Override\r
+       public String getValue(Row row) {\r
+               if (row == null)\r
+                       return null;\r
+               return getCellStringValue(getCell(row, column));\r
+       }\r
+       \r
+       \r
+\r
+}\r
diff --git a/org.simantics.excel.poi/src/org/simantics/excel/poi/parser/ColumnResolver.java b/org.simantics.excel.poi/src/org/simantics/excel/poi/parser/ColumnResolver.java
new file mode 100644 (file)
index 0000000..1aaec80
--- /dev/null
@@ -0,0 +1,106 @@
+package org.simantics.excel.poi.parser;\r
+\r
+import java.util.HashMap;\r
+import java.util.HashSet;\r
+import java.util.Map;\r
+import java.util.Map.Entry;\r
+import java.util.Set;\r
+\r
+import org.apache.poi.ss.usermodel.Cell;\r
+import org.apache.poi.ss.usermodel.Row;\r
+\r
+public class ColumnResolver {\r
+       \r
+       private enum Type {SINGLE,MULTI};\r
+       \r
+       private Map<String,int[]> values = new HashMap<String, int[]>();\r
+       private Map<String,Type> types = new HashMap<String, Type>();\r
+       private Set<String> optional = new HashSet<String>();\r
+       private Set<String> resolved = new HashSet<String>();\r
+       \r
+       public void addSingleColumn(String id) {\r
+               addSingleColumn(id, true);\r
+       }\r
+       \r
+       public void addSingleColumn(String id, boolean required) {\r
+               types.put(id, Type.SINGLE);\r
+               if (!required)\r
+                       this.optional.add(id);\r
+       }\r
+       \r
+       public void addMultiColumn(String id) {\r
+               addMultiColumn(id, true);\r
+       }\r
+       \r
+       public void addMultiColumn(String id, boolean required) {\r
+               types.put(id, Type.MULTI);\r
+               if (!required)\r
+                       this.optional.add(id);\r
+       }\r
+       \r
+       \r
+       public int getSingleColumn(String id) {\r
+               int[] val = values.get(id);\r
+               if (val == null)\r
+                       return -1;\r
+               if (val.length == 0)\r
+                       return -1;\r
+               return val[0];\r
+       }\r
+       \r
+       public int[] getMultiColumn(String id) {\r
+               return values.get(id);\r
+       }\r
+       \r
+       public boolean resolve(Row row) {\r
+               return resolve(row, true);\r
+       }\r
+       \r
+       public boolean resolve(Row row, boolean ignoreCase) {\r
+               values.clear();\r
+               resolved.clear();\r
+               if (row == null) {\r
+                       return false;\r
+               }\r
+       \r
+               for (int i = 0; i <= row.getLastCellNum(); i++) {\r
+                       Cell cell = row.getCell(i);\r
+                       if (cell == null)\r
+                               continue;\r
+                       int colIndex = cell.getColumnIndex();\r
+                       String value = cell.getStringCellValue();\r
+                       for (Entry<String, Type> col : types.entrySet()) {\r
+                               String id = col.getKey();\r
+                               if (id.equals(value) || ignoreCase && id.equalsIgnoreCase(value)) {\r
+                                       if (col.getValue() == Type.SINGLE) {\r
+                                               values.put(id, new int[]{colIndex});\r
+                                       } else {\r
+                                               int curr[] = values.get(id);\r
+                                               if (curr == null) {\r
+                                                       values.put(id, new int[]{colIndex});\r
+                                               } else {\r
+                                                       int n[] = new int[curr.length+1];\r
+                                                       System.arraycopy(curr, 0, n, 0, curr.length);\r
+                                                       n[curr.length] = colIndex;\r
+                                                       values.put(id, n);\r
+                                               }\r
+                                               \r
+                                       }\r
+                                       resolved.add(id);\r
+                                       break;\r
+                               }\r
+                       }\r
+               }\r
+               // check that required columns have been resolved\r
+               for (Entry<String, Type> col : types.entrySet()) {\r
+                       if (!optional.contains(col.getKey())) {\r
+                               if (!resolved.contains(col.getKey()))\r
+                                       return false;\r
+                       }\r
+               }\r
+               return true;\r
+                       \r
+       }\r
+       \r
+\r
+}\r
diff --git a/org.simantics.excel.poi/src/org/simantics/excel/poi/parser/DataResolver.java b/org.simantics.excel.poi/src/org/simantics/excel/poi/parser/DataResolver.java
new file mode 100644 (file)
index 0000000..ad3a6b6
--- /dev/null
@@ -0,0 +1,7 @@
+package org.simantics.excel.poi.parser;\r
+\r
+import org.apache.poi.ss.usermodel.Row;\r
+\r
+public interface DataResolver<T> {\r
+       public T getValue(Row row);\r
+}\r
diff --git a/org.simantics.excel.poi/src/org/simantics/excel/poi/parser/streaming/CellImpl.java b/org.simantics.excel.poi/src/org/simantics/excel/poi/parser/streaming/CellImpl.java
new file mode 100644 (file)
index 0000000..c5ee733
--- /dev/null
@@ -0,0 +1,262 @@
+package org.simantics.excel.poi.parser.streaming;\r
+\r
+import java.util.Calendar;\r
+import java.util.Date;\r
+\r
+import org.apache.poi.ss.formula.FormulaParseException;\r
+import org.apache.poi.ss.usermodel.Cell;\r
+import org.apache.poi.ss.usermodel.CellStyle;\r
+import org.apache.poi.ss.usermodel.CellType;\r
+import org.apache.poi.ss.usermodel.Comment;\r
+import org.apache.poi.ss.usermodel.ExcelStyleDateFormatter;\r
+import org.apache.poi.ss.usermodel.Hyperlink;\r
+import org.apache.poi.ss.usermodel.RichTextString;\r
+import org.apache.poi.ss.usermodel.Row;\r
+import org.apache.poi.ss.usermodel.Sheet;\r
+import org.apache.poi.ss.util.CellAddress;\r
+import org.apache.poi.ss.util.CellRangeAddress;\r
+\r
+public class CellImpl implements Cell{\r
+       \r
+       private RowImpl row;\r
+       private int index;\r
+       \r
+       public CellImpl(RowImpl row, int index) {\r
+               this.row = row;\r
+               this.index = index;\r
+       }\r
+       \r
+       \r
+       private String getType() {\r
+               return row.cellTypes.get(index);\r
+       }\r
+       \r
+       @Override\r
+       public boolean getBooleanCellValue() {\r
+               return 1 == Integer.parseInt(getStringCellValue());\r
+       }\r
+       \r
+       @Override\r
+       public Date getDateCellValue() {\r
+               ExcelStyleDateFormatter formatter = new ExcelStyleDateFormatter(""); //FIXME: date format\r
+               try {\r
+                       return formatter.parse(getStringCellValue());\r
+               } catch (Exception e) {\r
+                       return null;\r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public byte getErrorCellValue() {\r
+               // TODO Auto-generated method stub\r
+               return 0;\r
+       }\r
+       \r
+       @Override\r
+       public double getNumericCellValue() {\r
+               return Double.parseDouble(getStringCellValue());\r
+       }\r
+       \r
+       @Override\r
+       public RichTextString getRichStringCellValue() {\r
+               return null;\r
+       }\r
+       \r
+       @Override\r
+       public String getStringCellValue() {\r
+               return row.cellData.get(index);\r
+       }\r
+       \r
+       \r
+       @Override\r
+       public int getCellType() {\r
+               String type = getType();\r
+               if ("v".equals(type)) {\r
+                       return CELL_TYPE_NUMERIC;\r
+               } else if ("n".equals(type)) {\r
+                       return CELL_TYPE_NUMERIC;\r
+               } else if ("s".equals(type)) {\r
+                       return CELL_TYPE_STRING;\r
+               } else if ("b".equals(type)) {\r
+                       return CELL_TYPE_STRING;\r
+               } else if ("inlineStr".equals(type)) {\r
+                       return CELL_TYPE_STRING;\r
+               }\r
+               return CELL_TYPE_STRING;\r
+       }\r
+       \r
+\r
+       \r
+       \r
+       @Override\r
+       public Row getRow() {\r
+               return row;\r
+       }\r
+       \r
+       @Override\r
+       public int getRowIndex() {\r
+               return row.getRowNum();\r
+       }\r
+       \r
+       \r
+       @Override\r
+       public CellRangeAddress getArrayFormulaRange() {\r
+               return null;\r
+       }\r
+       \r
+       \r
+       @Override\r
+       public int getCachedFormulaResultType() {\r
+               return 0;\r
+       }\r
+       \r
+       @Override\r
+       public Comment getCellComment() {\r
+               return null;\r
+       }\r
+       \r
+       @Override\r
+       public String getCellFormula() {\r
+               return null;\r
+       }\r
+       \r
+       @Override\r
+       public CellStyle getCellStyle() {\r
+               return null;\r
+       }\r
+       \r
+       @Override\r
+       public int getColumnIndex() {\r
+               return index;\r
+       }\r
+       \r
+       @Override\r
+       public Hyperlink getHyperlink() {\r
+               return null;\r
+       }\r
+       \r
+       \r
+       @Override\r
+       public Sheet getSheet() {\r
+               return row.getSheet();\r
+       }\r
+       \r
+       @Override\r
+       public boolean isPartOfArrayFormulaGroup() {\r
+               return false;\r
+       }\r
+       \r
+       @Override\r
+       public void removeCellComment() {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void setAsActiveCell() {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void setCellComment(Comment comment) {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void setCellErrorValue(byte value) {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void setCellFormula(String formula) throws FormulaParseException {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void setCellStyle(CellStyle style) {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void setCellType(int cellType) {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void setCellValue(boolean value) {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void setCellValue(Calendar value) {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void setCellValue(Date value) {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void setCellValue(double value) {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void setCellValue(RichTextString value) {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void setCellValue(String value) {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void setHyperlink(Hyperlink link) {\r
+               \r
+       }\r
+\r
+\r
+       @Override\r
+       public CellAddress getAddress() {\r
+               return new CellAddress(this);\r
+       }\r
+\r
+\r
+       @Override\r
+       public CellType getCachedFormulaResultTypeEnum() {\r
+               throw new UnsupportedOperationException();\r
+       }\r
+\r
+\r
+       @Override\r
+       public CellType getCellTypeEnum() {\r
+               String type = getType();\r
+               if ("v".equals(type)) {\r
+                       return CellType.NUMERIC;\r
+               } else if ("n".equals(type)) {\r
+                       return CellType.NUMERIC;\r
+               } else if ("s".equals(type)) {\r
+                       return CellType.STRING;\r
+               } else if ("b".equals(type)) {\r
+                       return CellType.STRING;\r
+               } else if ("inlineStr".equals(type)) {\r
+                       return CellType.STRING;\r
+               }\r
+               return CellType.STRING;\r
+       }\r
+       \r
+       @Override\r
+       public void setCellType(CellType arg0) {\r
+               throw new UnsupportedOperationException();\r
+       }\r
+       \r
+\r
+\r
+       @Override\r
+       public void removeHyperlink() {\r
+               throw new UnsupportedOperationException();\r
+       }\r
+       \r
+\r
+}\r
diff --git a/org.simantics.excel.poi/src/org/simantics/excel/poi/parser/streaming/RowImpl.java b/org.simantics.excel.poi/src/org/simantics/excel/poi/parser/streaming/RowImpl.java
new file mode 100644 (file)
index 0000000..1ca2eb3
--- /dev/null
@@ -0,0 +1,166 @@
+package org.simantics.excel.poi.parser.streaming;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+\r
+import org.apache.poi.ss.usermodel.Cell;\r
+import org.apache.poi.ss.usermodel.CellStyle;\r
+import org.apache.poi.ss.usermodel.CellType;\r
+import org.apache.poi.ss.usermodel.Row;\r
+import org.apache.poi.ss.usermodel.Sheet;\r
+\r
+public class RowImpl implements Row {\r
+       SheetImpl sheetImpl;\r
+       \r
+       List<String> cellData;\r
+       List<String> cellTypes;\r
+       List<Cell> cells;\r
+\r
+       int index;\r
+       \r
+       public RowImpl(SheetImpl sheetImpl, List<String> cellData, List<String> cellTypes, int index) {\r
+               this.sheetImpl = sheetImpl;\r
+               this.cellData = cellData;\r
+               this.cellTypes = cellTypes;\r
+               this.cells = new ArrayList<Cell>(cellData.size());\r
+               for (int i = 0; i < cellData.size(); i++) {\r
+                       cells.add(new CellImpl(this, i));\r
+               }\r
+               this.index = index;\r
+       }\r
+       \r
+       @Override\r
+       public Iterator<Cell> cellIterator() {\r
+               return cells.iterator();\r
+       }\r
+       \r
+       @Override\r
+       public Cell createCell(int column) {\r
+               return null;\r
+       }\r
+       \r
+       @Override\r
+       public Cell createCell(int column, int type) {\r
+               return null;\r
+       }\r
+       \r
+       @Override\r
+       public Cell getCell(int cellnum) {\r
+               return cells.get(cellnum);\r
+       }\r
+       \r
+       @Override\r
+       public Cell getCell(int cellnum, MissingCellPolicy policy) {\r
+               return cells.get(cellnum);\r
+       }\r
+       \r
+       @Override\r
+       public short getFirstCellNum() {\r
+               return 0;\r
+       }\r
+       \r
+       @Override\r
+       public short getLastCellNum() {\r
+               return (short)(cells.size()-1);\r
+       }\r
+       \r
+       \r
+       @Override\r
+       public short getHeight() {\r
+               return 0;\r
+       }\r
+       \r
+       @Override\r
+       public float getHeightInPoints() {\r
+               return 0;\r
+       }\r
+       \r
+       \r
+       @Override\r
+       public int getPhysicalNumberOfCells() {\r
+               return cells.size();\r
+       }\r
+       \r
+       @Override\r
+       public int getRowNum() {\r
+               return index;\r
+       }\r
+       \r
+       @Override\r
+       public CellStyle getRowStyle() {\r
+               return null;\r
+       }\r
+       \r
+       @Override\r
+       public Sheet getSheet() {\r
+               return sheetImpl;\r
+       }\r
+       \r
+       @Override\r
+       public boolean getZeroHeight() {\r
+               return false;\r
+       }\r
+       \r
+       @Override\r
+       public boolean isFormatted() {\r
+               return false;\r
+       }\r
+       \r
+       @Override\r
+       public Iterator<Cell> iterator() {\r
+               return cells.iterator();\r
+       }\r
+       \r
+       @Override\r
+       public void removeCell(Cell cell) {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void setHeight(short height) {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void setHeightInPoints(float height) {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void setRowNum(int rowNum) {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void setRowStyle(CellStyle style) {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void setZeroHeight(boolean zHeight) {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public int getOutlineLevel() {\r
+               return 0;\r
+       }\r
+       \r
+       @Override\r
+       public Cell createCell(int arg0, CellType arg1) {\r
+               throw new UnsupportedOperationException();\r
+       }\r
+       \r
+       \r
+       \r
+       @Override\r
+       public String toString() {\r
+               String s = "";\r
+               for (int i = 0; i < cellData.size(); i++) {\r
+                       s += cellTypes.get(i)+":" + cellData.get(i) + "; ";\r
+               }\r
+               return s;\r
+       }\r
+\r
+}\r
diff --git a/org.simantics.excel.poi/src/org/simantics/excel/poi/parser/streaming/SheetImpl.java b/org.simantics.excel.poi/src/org/simantics/excel/poi/parser/streaming/SheetImpl.java
new file mode 100644 (file)
index 0000000..f45fd21
--- /dev/null
@@ -0,0 +1,675 @@
+package org.simantics.excel.poi.parser.streaming;\r
+\r
+import java.util.Collection;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+import java.util.Map;\r
+\r
+import org.apache.poi.hssf.util.PaneInformation;\r
+import org.apache.poi.ss.usermodel.AutoFilter;\r
+import org.apache.poi.ss.usermodel.Cell;\r
+import org.apache.poi.ss.usermodel.CellRange;\r
+import org.apache.poi.ss.usermodel.CellStyle;\r
+import org.apache.poi.ss.usermodel.Comment;\r
+import org.apache.poi.ss.usermodel.DataValidation;\r
+import org.apache.poi.ss.usermodel.DataValidationHelper;\r
+import org.apache.poi.ss.usermodel.Drawing;\r
+import org.apache.poi.ss.usermodel.Footer;\r
+import org.apache.poi.ss.usermodel.Header;\r
+import org.apache.poi.ss.usermodel.Hyperlink;\r
+import org.apache.poi.ss.usermodel.PrintSetup;\r
+import org.apache.poi.ss.usermodel.Row;\r
+import org.apache.poi.ss.usermodel.Sheet;\r
+import org.apache.poi.ss.usermodel.SheetConditionalFormatting;\r
+import org.apache.poi.ss.usermodel.Workbook;\r
+import org.apache.poi.ss.util.CellAddress;\r
+import org.apache.poi.ss.util.CellRangeAddress;\r
+\r
+public class SheetImpl implements Sheet{\r
+       \r
+       private String name;\r
+       private int index;\r
+       private String id;\r
+       \r
+       public SheetImpl(String name, int index, String id) {\r
+               this.name = name;\r
+               this.index = index;\r
+               this.id = id;\r
+       }\r
+       \r
+       public int getIndex() {\r
+               return index;\r
+       }\r
+       \r
+       public String getId() {\r
+               return id;\r
+       }\r
+       \r
+       @Override\r
+       public int getFirstRowNum() {\r
+               return 0;\r
+       }\r
+\r
+       @Override\r
+       public int getLastRowNum() {\r
+               return 0;\r
+       }\r
+       \r
+       @Override\r
+       public Row getRow(int rownum) {\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public int getPhysicalNumberOfRows() {\r
+               return 0;\r
+       }\r
+       \r
+       @Override\r
+       public Workbook getWorkbook() {\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public String getSheetName() {\r
+               return name;\r
+       }\r
+       \r
+       \r
+       \r
+       @Override\r
+       public int addMergedRegion(CellRangeAddress region) {\r
+               return 0;\r
+       }\r
+       \r
+       @Override\r
+       public void addValidationData(DataValidation dataValidation) {\r
+               \r
+       }\r
+       \r
+       public void autoSizeColumn(int column) {};\r
+       \r
+       @Override\r
+       public void autoSizeColumn(int column, boolean useMergedCells) {\r
+               \r
+       }\r
+       \r
+       public org.apache.poi.ss.usermodel.Drawing createDrawingPatriarch() {\r
+               return null;\r
+       };\r
+       \r
+       @Override\r
+       public void createFreezePane(int colSplit, int rowSplit) {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void createFreezePane(int colSplit, int rowSplit, int leftmostColumn, int topRow) {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public Row createRow(int rownum) {\r
+               return null;\r
+       }\r
+       \r
+       @Override\r
+       public void createSplitPane(int xSplitPos, int ySplitPos, int leftmostColumn, int topRow, int activePane) {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public boolean getAutobreaks() {\r
+               return false;\r
+       }\r
+       \r
+       @Override\r
+       public Comment getCellComment(int row, int column) {\r
+               return null;\r
+       }\r
+       \r
+       public int[] getColumnBreaks() {\r
+               return null;\r
+       };\r
+       \r
+       @Override\r
+       public CellStyle getColumnStyle(int column) {\r
+               return null;\r
+       }\r
+       \r
+       @Override\r
+       public int getColumnWidth(int columnIndex) {\r
+               return 0;\r
+       }\r
+       \r
+       @Override\r
+       public DataValidationHelper getDataValidationHelper() {\r
+               return null;\r
+       }\r
+       \r
+       public int getDefaultColumnWidth() {\r
+               return 0;\r
+       }\r
+\r
+       @Override\r
+       public Iterator<Row> iterator() {\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public void removeRow(Row row) {\r
+               \r
+       }\r
+\r
+       \r
+\r
+       \r
+\r
+       @Override\r
+       public void setColumnHidden(int columnIndex, boolean hidden) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public boolean isColumnHidden(int columnIndex) {\r
+               return false;\r
+       }\r
+\r
+       @Override\r
+       public void setRightToLeft(boolean value) {\r
+       \r
+       }\r
+\r
+       @Override\r
+       public boolean isRightToLeft() {\r
+               return false;\r
+       }\r
+\r
+       @Override\r
+       public void setColumnWidth(int columnIndex, int width) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public void setDefaultColumnWidth(int width) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public short getDefaultRowHeight() {\r
+               return 0;\r
+       }\r
+\r
+       @Override\r
+       public float getDefaultRowHeightInPoints() {\r
+               return 0;\r
+       }\r
+\r
+       @Override\r
+       public void setDefaultRowHeight(short height) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public void setDefaultRowHeightInPoints(float height) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public void setVerticallyCenter(boolean value) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public void setHorizontallyCenter(boolean value) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public boolean getHorizontallyCenter() {\r
+               return false;\r
+       }\r
+\r
+       @Override\r
+       public boolean getVerticallyCenter() {\r
+               return false;\r
+       }\r
+\r
+       @Override\r
+       public void removeMergedRegion(int index) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public int getNumMergedRegions() {\r
+               return 0;\r
+       }\r
+\r
+       @Override\r
+       public CellRangeAddress getMergedRegion(int index) {\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public Iterator<Row> rowIterator() {\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public void setForceFormulaRecalculation(boolean value) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public boolean getForceFormulaRecalculation() {\r
+               return false;\r
+       }\r
+\r
+       @Override\r
+       public void setAutobreaks(boolean value) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public void setDisplayGuts(boolean value) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public void setDisplayZeros(boolean value) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public boolean isDisplayZeros() {\r
+               return false;\r
+       }\r
+\r
+       @Override\r
+       public void setFitToPage(boolean value) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public void setRowSumsBelow(boolean value) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public void setRowSumsRight(boolean value) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public boolean getDisplayGuts() {\r
+               return false;\r
+       }\r
+\r
+       @Override\r
+       public boolean getFitToPage() {\r
+               return false;\r
+       }\r
+\r
+       @Override\r
+       public boolean getRowSumsBelow() {\r
+               return false;\r
+       }\r
+\r
+       @Override\r
+       public boolean getRowSumsRight() {\r
+               return false;\r
+       }\r
+\r
+       @Override\r
+       public boolean isPrintGridlines() {\r
+               return false;\r
+       }\r
+\r
+       @Override\r
+       public void setPrintGridlines(boolean show) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public PrintSetup getPrintSetup() {\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public Header getHeader() {\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public Footer getFooter() {\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public void setSelected(boolean value) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public double getMargin(short margin) {\r
+               return 0;\r
+       }\r
+\r
+       @Override\r
+       public void setMargin(short margin, double size) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public boolean getProtect() {\r
+               return false;\r
+       }\r
+\r
+       @Override\r
+       public void protectSheet(String password) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public boolean getScenarioProtect() {\r
+               return false;\r
+       }\r
+\r
+       @Override\r
+       public void setZoom(int numerator, int denominator) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public short getTopRow() {\r
+               return 0;\r
+       }\r
+\r
+       @Override\r
+       public short getLeftCol() {\r
+               return 0;\r
+       }\r
+\r
+       @Override\r
+       public void showInPane(int toprow, int leftcol) {\r
+               \r
+       }\r
+\r
+//     @Override\r
+//     public void showInPane(short toprow, short leftcol) {\r
+//             \r
+//     }\r
+\r
+       @Override\r
+       public void shiftRows(int startRow, int endRow, int n) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public void shiftRows(int startRow, int endRow, int n, boolean copyRowHeight, boolean resetOriginalRowHeight) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public PaneInformation getPaneInformation() {\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public void setDisplayGridlines(boolean show) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public boolean isDisplayGridlines() {\r
+               return false;\r
+       }\r
+\r
+       @Override\r
+       public void setDisplayFormulas(boolean show) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public boolean isDisplayFormulas() {\r
+               return false;\r
+       }\r
+\r
+       @Override\r
+       public void setDisplayRowColHeadings(boolean show) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public boolean isDisplayRowColHeadings() {\r
+               return false;\r
+       }\r
+\r
+       @Override\r
+       public void setRowBreak(int row) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public boolean isRowBroken(int row) {\r
+               return false;\r
+       }\r
+\r
+       @Override\r
+       public void removeRowBreak(int row) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public int[] getRowBreaks() {\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public void setColumnBreak(int column) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public boolean isColumnBroken(int column) {\r
+               return false;\r
+       }\r
+\r
+       @Override\r
+       public void removeColumnBreak(int column) {\r
+                       }\r
+\r
+       @Override\r
+       public void setColumnGroupCollapsed(int columnNumber, boolean collapsed) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public void groupColumn(int fromColumn, int toColumn) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public void ungroupColumn(int fromColumn, int toColumn) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public void groupRow(int fromRow, int toRow) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public void ungroupRow(int fromRow, int toRow) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public void setRowGroupCollapsed(int row, boolean collapse) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public void setDefaultColumnStyle(int column, CellStyle style) {\r
+               \r
+       }\r
+\r
+       \r
+\r
+       @Override\r
+       public boolean isSelected() {\r
+               return false;\r
+       }\r
+\r
+       @Override\r
+       public CellRange<? extends Cell> setArrayFormula(String formula, CellRangeAddress range) {\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public CellRange<? extends Cell> removeArrayFormula(Cell cell) {\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public AutoFilter setAutoFilter(CellRangeAddress range) {\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public SheetConditionalFormatting getSheetConditionalFormatting() {\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public CellRangeAddress getRepeatingRows() {\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public CellRangeAddress getRepeatingColumns() {\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public void setRepeatingRows(CellRangeAddress rowRangeRef) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public void setRepeatingColumns(CellRangeAddress columnRangeRef) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public int addMergedRegionUnsafe(CellRangeAddress arg0) {\r
+               // TODO Auto-generated method stub\r
+               return 0;\r
+       }\r
+\r
+       @Override\r
+       public CellAddress getActiveCell() {\r
+               // TODO Auto-generated method stub\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public Comment getCellComment(CellAddress arg0) {\r
+               // TODO Auto-generated method stub\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public Map<CellAddress, ? extends Comment> getCellComments() {\r
+               // TODO Auto-generated method stub\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public int getColumnOutlineLevel(int arg0) {\r
+               // TODO Auto-generated method stub\r
+               return 0;\r
+       }\r
+\r
+       @Override\r
+       public float getColumnWidthInPixels(int arg0) {\r
+               // TODO Auto-generated method stub\r
+               return 0;\r
+       }\r
+\r
+       @Override\r
+       public List<? extends DataValidation> getDataValidations() {\r
+               // TODO Auto-generated method stub\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public Drawing getDrawingPatriarch() {\r
+               // TODO Auto-generated method stub\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public Hyperlink getHyperlink(CellAddress arg0) {\r
+               // TODO Auto-generated method stub\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public Hyperlink getHyperlink(int arg0, int arg1) {\r
+               // TODO Auto-generated method stub\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public List<? extends Hyperlink> getHyperlinkList() {\r
+               // TODO Auto-generated method stub\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public List<CellRangeAddress> getMergedRegions() {\r
+               // TODO Auto-generated method stub\r
+               return null;\r
+       }\r
+\r
+       @Override\r
+       public boolean isPrintRowAndColumnHeadings() {\r
+               // TODO Auto-generated method stub\r
+               return false;\r
+       }\r
+\r
+       @Override\r
+       public void removeMergedRegions(Collection<Integer> arg0) {\r
+               // TODO Auto-generated method stub\r
+               \r
+       }\r
+\r
+       @Override\r
+       public void setActiveCell(CellAddress arg0) {\r
+               // TODO Auto-generated method stub\r
+               \r
+       }\r
+\r
+       @Override\r
+       public void setPrintRowAndColumnHeadings(boolean arg0) {\r
+               // TODO Auto-generated method stub\r
+               \r
+       }\r
+\r
+       @Override\r
+       public void setZoom(int arg0) {\r
+               // TODO Auto-generated method stub\r
+               \r
+       }\r
+\r
+       @Override\r
+       public void validateMergedRegions() {\r
+               // TODO Auto-generated method stub\r
+               \r
+       };\r
+       \r
+       \r
+\r
+       \r
+}\r
diff --git a/org.simantics.excel.poi/src/org/simantics/excel/poi/parser/streaming/StreamingParser.java b/org.simantics.excel.poi/src/org/simantics/excel/poi/parser/streaming/StreamingParser.java
new file mode 100644 (file)
index 0000000..add64d9
--- /dev/null
@@ -0,0 +1,62 @@
+package org.simantics.excel.poi.parser.streaming;\r
+\r
+import java.io.File;\r
+import java.io.InputStream;\r
+import java.util.Iterator;\r
+\r
+import org.apache.poi.openxml4j.opc.OPCPackage;\r
+import org.apache.poi.ss.usermodel.Row;\r
+import org.apache.poi.xssf.eventusermodel.XSSFReader;\r
+import org.apache.poi.xssf.model.SharedStringsTable;\r
+import org.xml.sax.ContentHandler;\r
+import org.xml.sax.InputSource;\r
+import org.xml.sax.SAXException;\r
+import org.xml.sax.XMLReader;\r
+import org.xml.sax.helpers.XMLReaderFactory;\r
+\r
+public class StreamingParser {\r
+\r
+       \r
+       public void process(Row row) {\r
+               \r
+       }\r
+       \r
+       public void processAllSheets(File file) throws Exception {\r
+               OPCPackage pkg = OPCPackage.open(file);\r
+               XSSFReader r = new XSSFReader( pkg );\r
+               SharedStringsTable sst = r.getSharedStringsTable();\r
+               \r
+               XSSWorkbookHandler workbookHandler = new XSSWorkbookHandler();\r
+               XMLReader parser = fetchParser(workbookHandler);\r
+               InputStream wb = r.getWorkbookData();\r
+               InputSource wbSource = new InputSource(wb);\r
+               parser.parse(wbSource);\r
+               wb.close();\r
+               \r
+               \r
+               Iterator<InputStream> sheets = r.getSheetsData();\r
+               XSSSheetHandler sheetHandler = new XSSSheetHandler(sst) {\r
+                       @Override\r
+                       public void writeRow(Row row) {\r
+                               process(row);\r
+                       }\r
+               };\r
+               parser = fetchParser(sheetHandler);\r
+               int sheetIndex = 0;\r
+               while(sheets.hasNext()) {\r
+                       sheetHandler.setSheet(workbookHandler.getSheets().get(sheetIndex));\r
+                       InputStream sheet = sheets.next();\r
+                       InputSource sheetSource = new InputSource(sheet);\r
+                       parser.parse(sheetSource);\r
+                       sheet.close();\r
+                       sheetIndex++;\r
+               }\r
+       }\r
+\r
+       public XMLReader fetchParser(ContentHandler handler) throws SAXException {\r
+               XMLReader parser = XMLReaderFactory.createXMLReader();\r
+               parser.setContentHandler(handler);\r
+               return parser;\r
+       }\r
+\r
+}\r
diff --git a/org.simantics.excel.poi/src/org/simantics/excel/poi/parser/streaming/XSSSheetHandler.java b/org.simantics.excel.poi/src/org/simantics/excel/poi/parser/streaming/XSSSheetHandler.java
new file mode 100644 (file)
index 0000000..5df804a
--- /dev/null
@@ -0,0 +1,120 @@
+package org.simantics.excel.poi.parser.streaming;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.apache.poi.ss.usermodel.Row;\r
+import org.apache.poi.xssf.model.SharedStringsTable;\r
+import org.apache.poi.xssf.usermodel.XSSFRichTextString;\r
+import org.xml.sax.Attributes;\r
+import org.xml.sax.SAXException;\r
+import org.xml.sax.helpers.DefaultHandler;\r
+\r
+public class XSSSheetHandler extends DefaultHandler {\r
+       private SharedStringsTable sst;\r
+       private String lastContents;\r
+       private boolean nextIsString;\r
+       \r
+       int rowIndex = 0;\r
+       List<String> row = new ArrayList<String>();\r
+       List<String> rowTypes = new ArrayList<String>();\r
+       \r
+       String cellType;\r
+       String cellId;\r
+       \r
+       SheetImpl sheet;\r
+       \r
+       public XSSSheetHandler(SharedStringsTable sst) {\r
+               this.sst = sst;\r
+       }\r
+       \r
+       public void setSheet(SheetImpl sheet) {\r
+               this.sheet = sheet;\r
+       }\r
+       \r
+       public void writeRow(Row row) {\r
+               System.out.println(row);\r
+       }\r
+       \r
+       public void startElement(String uri, String localName, String name,\r
+                       Attributes attributes) throws SAXException {\r
+               // c => cell\r
+//             System.out.println(name);\r
+//             for (int i = 0; i < attributes.getLength(); i++) {\r
+//                     System.out.println("  " + attributes.getLocalName(i) + "; "+attributes.getValue(i) + "; " + attributes.getType(i) );\r
+//                     \r
+//             }\r
+               if(name.equals("c")) {\r
+                       // Figure out if the value is an index in the SST\r
+                       cellType = attributes.getValue("t");\r
+                       cellId = attributes.getValue("r");\r
+                       if(cellType != null) {\r
+                               if (cellType.equals("s"))\r
+                                       nextIsString = true;\r
+                               else\r
+                                       nextIsString = false;\r
+                       } else {\r
+                               nextIsString = false;\r
+                               cellType = "v";\r
+                       }\r
+               } \r
+               // Clear contents cache\r
+               lastContents = "";\r
+       }\r
+       \r
+       public void endElement(String uri, String localName, String name)\r
+                       throws SAXException {\r
+               // Process the last contents as required.\r
+               // Do now, as characters() may be called more than once\r
+               if(nextIsString) {\r
+                       int idx = Integer.parseInt(lastContents);\r
+                       lastContents = new XSSFRichTextString(sst.getEntryAt(idx)).toString();\r
+                       nextIsString = false;\r
+               } \r
+\r
+               // v => contents of a cell\r
+               // Output after we've seen the string contents\r
+               if(name.equals("c")) {\r
+                       int colIndex = getColIndex(cellId);\r
+                       for (int i = row.size(); i< colIndex; i++) {\r
+                               row.add(null);\r
+                               rowTypes.add("s");\r
+                       }\r
+                       row.add(lastContents);\r
+                       rowTypes.add(cellType);\r
+                       //System.out.println(lastContents);\r
+                       lastContents = "";\r
+               } else if (name.equals("row")) {\r
+                       writeRow( new RowImpl(sheet, row, rowTypes,rowIndex));\r
+                       rowIndex++;\r
+                       row.clear();\r
+                       rowTypes.clear();\r
+               }\r
+       }\r
+\r
+       public void characters(char[] ch, int start, int length)\r
+                       throws SAXException {\r
+               lastContents += new String(ch, start, length);\r
+//             System.out.println("char : " + lastContents);\r
+       }\r
+\r
+       private int getColIndex(String id) {\r
+               int len = 0;\r
+               int range = 'Z'-'A'+1;\r
+               for (int i = 0; i < id.length(); i++) {\r
+                       char c = id.charAt(i) ;\r
+                       if ('A' <= c && c <= 'Z') {\r
+                               len = i+1;\r
+                       } else {\r
+                               break;\r
+                       }\r
+               }\r
+               int index = 0;\r
+               for (int i = 0; i < len; i++) {\r
+                       char c = id.charAt(len-i-1);\r
+                       index += (c-'A') + i * range;\r
+               }\r
+               return index;\r
+               \r
+       }\r
+}\r
diff --git a/org.simantics.excel.poi/src/org/simantics/excel/poi/parser/streaming/XSSWorkbookHandler.java b/org.simantics.excel.poi/src/org/simantics/excel/poi/parser/streaming/XSSWorkbookHandler.java
new file mode 100644 (file)
index 0000000..af59d37
--- /dev/null
@@ -0,0 +1,47 @@
+package org.simantics.excel.poi.parser.streaming;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.xml.sax.Attributes;\r
+import org.xml.sax.SAXException;\r
+import org.xml.sax.helpers.DefaultHandler;\r
+\r
+public class XSSWorkbookHandler extends DefaultHandler {\r
+\r
+       \r
+       \r
+       List<SheetImpl> sheets = new ArrayList<SheetImpl>();\r
+       \r
+\r
+       public List<SheetImpl> getSheets() {\r
+               return sheets;\r
+       }\r
+       \r
+       public void startElement(String uri, String localName, String name,\r
+                       Attributes attributes) throws SAXException {\r
+//             System.out.println(name);\r
+//             for (int i = 0; i < attributes.getLength(); i++) {\r
+//                     System.out.println("  " + attributes.getLocalName(i) + "; "+attributes.getValue(i) + "; " + attributes.getType(i) );\r
+//                     \r
+//             }\r
+               if(name.equals("sheet")) {\r
+                       String sheetName = attributes.getValue("name");\r
+                       String sheetId = attributes.getValue("sheetId");\r
+                       String id = attributes.getValue("id");\r
+                       sheets.add(new SheetImpl(sheetName, Integer.parseInt(sheetId), id));\r
+               } \r
+\r
+       }\r
+       \r
+       public void endElement(String uri, String localName, String name)\r
+                       throws SAXException {\r
+       \r
+       }\r
+\r
+       public void characters(char[] ch, int start, int length)\r
+                       throws SAXException {\r
+               \r
+       }\r
+\r
+}\r