]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/editor/ExcelLink.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.spreadsheet.ui / src / org / simantics / spreadsheet / ui / editor / ExcelLink.java
index 1bec0694b83f0b7b829b156cd1447b8bab622a8d..03467d6f67ff86f48ee12bd1da7ef37e38c8a39b 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.spreadsheet.ui.editor;\r
-\r
-import java.io.File;\r
-import java.io.IOException;\r
-\r
-import org.simantics.Simantics;\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.databoard.binding.mutable.Variant;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.Session;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.request.ResourceRead;\r
-import org.simantics.db.common.request.WriteRequest;\r
-import org.simantics.db.common.utils.Logger;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.util.Layer0Utils;\r
-import org.simantics.excel.Excel;\r
-import org.simantics.excel.ExcelException;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.spreadsheet.ClientModel;\r
-import org.simantics.spreadsheet.Range;\r
-import org.simantics.spreadsheet.common.client.ClientModelListenerAdapter;\r
-import org.simantics.spreadsheet.common.exception.CellParseException;\r
-import org.simantics.spreadsheet.resource.SpreadsheetResource;\r
-import org.simantics.spreadsheet.util.SpreadsheetUtils;\r
-import org.simantics.utils.FileUtils;\r
-import org.simantics.utils.datastructures.Pair;\r
-import org.simantics.utils.ui.dialogs.ShowMessage;\r
-\r
-public class ExcelLink extends ClientModelListenerAdapter {\r
-\r
-       final private Session session;\r
-       final private Resource container;\r
-    final private ClientModel model;\r
-    final private Resource book;\r
-    final private String bookName;\r
-    final private String sheetName;\r
-    final private String prefix;\r
-    final private Excel excel;\r
-    private int handle;\r
-    \r
-    public ExcelLink(Session session, Resource container, ClientModel model, final Resource book, String bookName, String sheetName, String prefix) {\r
-        \r
-       this.session = session;\r
-       this.container = container;\r
-       this.handle = 0;\r
-        this.model = model;\r
-        this.bookName = bookName + ".xlsx";\r
-        this.sheetName = sheetName;\r
-        this.prefix = prefix;\r
-        this.book = book;\r
-        \r
-        this.excel = tryGetExcel(book, bookName);\r
-\r
-               model.addListener(this);\r
-        \r
-    }\r
-    \r
-    public static Excel tryGetExcel(final Resource book, final String bookName) {\r
-\r
-       try {\r
-\r
-               Excel excel = Excel.getInstance(System.out);\r
-               String file = excel.getFile(bookName);\r
-               final File tester = new File(file);\r
-\r
-               if(!tester.exists()) {\r
-                       // Restore file from graph\r
-                       try {\r
-                               byte[] saved = Simantics.getSession().syncRequest(new ResourceRead<byte[]>(book) {\r
-\r
-                                       @Override\r
-                                       public byte[] perform(ReadGraph graph) throws DatabaseException {\r
-                                               SpreadsheetResource SR = SpreadsheetResource.getInstance(graph);\r
-                                               return graph.getPossibleRelatedValue(book, SR.HasMicrosoftExcelDocumentData, Bindings.BYTE_ARRAY);\r
-                                       }\r
-\r
-                               });\r
-                               if(saved != null) FileUtils.writeFile(tester, saved);\r
-                       } catch (DatabaseException e) {\r
-                               Logger.defaultLogError(e);\r
-                       } catch (IOException e) {\r
-                               Logger.defaultLogError(e);\r
-                       }\r
-               }\r
-\r
-               return excel;\r
-\r
-       } catch (ExcelException e1) {\r
-\r
-               Logger.defaultLogError(e1);\r
-\r
-       } \r
-\r
-       return null;\r
-\r
-    }\r
-\r
-    public void dispose() {\r
-       \r
-       model.removeListener(this);\r
-\r
-               try {\r
-                       \r
-                       if(excel != null) {\r
-                       if(handle != 0) excel.close_(handle);\r
-                               String file = excel.getFile(bookName);\r
-                               File tester = new File(file);\r
-                               if(tester.exists()) {\r
-                                       final byte[] saved = FileUtils.readFile(tester);\r
-                                       if(saved != null) {\r
-                                               Simantics.getSession().syncRequest(new WriteRequest() {\r
-       \r
-                                                       @Override\r
-                                                       public void perform(WriteGraph graph) throws DatabaseException {\r
-                                                               SpreadsheetResource SR = SpreadsheetResource.getInstance(graph);\r
-                                                               graph.claimLiteral(book, SR.HasMicrosoftExcelDocumentData, saved, Bindings.BYTE_ARRAY);\r
-                                                       }\r
-       \r
-                                               });\r
-                                       }\r
-                               }\r
-                       }\r
-                       \r
-               } catch (DatabaseException e) {\r
-                       Logger.defaultLogError(e);\r
-               } catch (IOException e) {\r
-                       Logger.defaultLogError(e);\r
-               }\r
-       \r
-    }\r
-\r
-       @Override\r
-       public void propertyChange(String location, String property, Object value) {\r
-               \r
-               if(ClientModel.CONTENT.equals(property) && value != null && value instanceof Variant) {\r
-                       \r
-                       if(handle == 0) return;\r
-                       Range range = SpreadsheetUtils.decodeCellAbsolute(location);\r
-                       excel.setString_(handle, range.startRow, range.startColumn, ((Variant)value).getValue().toString());\r
-                       final String modis = excel.getModifications_(handle);\r
-\r
-                       session.asyncRequest(new WriteRequest() {\r
-\r
-                               @Override\r
-                               public void perform(WriteGraph graph) throws DatabaseException {\r
-\r
-                                       String[] parts = (modis+"0").split("#");\r
-                                       \r
-                                       Range range = SpreadsheetUtils.decodeRange(parts[0]);\r
-                                       \r
-                               Layer0 L0 = Layer0.getInstance(graph);\r
-                               SpreadsheetResource SHEET = SpreadsheetResource.getInstance(graph);\r
-                                       \r
-                                       int index = 1;\r
-                                       for(int i=0;i<range.height();i++) {\r
-                                               for(int j=0;j<range.width();j++) {\r
-                                                       \r
-                                                       String addr = SpreadsheetUtils.cellName(range.startRow + i, range.startColumn + j);\r
-                                                       String content = parts[index++];\r
-                                                       \r
-                                                       Resource cell = Layer0Utils.getPossibleChild(graph, container, addr);\r
-                                                       if(cell != null) {\r
-                                                               Variant newValue = Variant.ofInstance(content);\r
-                                                               Variant existing = graph.getRelatedValue(cell, SHEET.Cell_content, Bindings.VARIANT);\r
-                                                               if(!newValue.equals(existing)) {\r
-                                                                       graph.claimLiteral(cell, SHEET.Cell_content, SHEET.Cell_content_Inverse, L0.Variant, newValue, Bindings.VARIANT);\r
-                                                               }\r
-                                                       } else {\r
-                                                               cell = graph.newResource();\r
-                                                               graph.claim(cell, L0.InstanceOf, null, SHEET.TextCell);\r
-                                                               graph.addLiteral(cell, L0.HasName, L0.NameOf, L0.String, addr, Bindings.STRING);\r
-                                                               graph.addLiteral(cell, SHEET.Cell_content, SHEET.Cell_content_Inverse, L0.Variant, Variant.ofInstance(content), Bindings.VARIANT);\r
-                                                               graph.claim(cell, L0.PartOf, container);\r
-                                                       }\r
-                                                       \r
-                                               }\r
-                                       }\r
-                                       \r
-                                       for(int i=1;i<parts.length;i++) {\r
-//                                             String addr = parts[i];\r
-//                                             String content = parts[i+1];\r
-//                                             \r
-//                                     Layer0 L0 = Layer0.getInstance(graph);\r
-//                                     SpreadsheetResource SHEET = SpreadsheetResource.getInstance(graph);\r
-//                                     \r
-//                                     Resource cell = Layer0Utils.getPossibleChild(graph, container, addr);\r
-//                                     if(cell != null) {\r
-//                                             Variant newValue = Variant.ofInstance(content);\r
-//                                             Variant existing = graph.getRelatedValue(cell, SHEET.Cell_content, Bindings.VARIANT);\r
-//                                             if(!newValue.equals(existing))\r
-//                                                     graph.claimLiteral(cell, SHEET.Cell_content, SHEET.Cell_content_Inverse, L0.Variant, newValue, Bindings.VARIANT);\r
-//                                     } else {\r
-//                                             cell = graph.newResource();\r
-//                                             graph.claim(cell, L0.InstanceOf, null, SHEET.TextCell);\r
-//                                             graph.addLiteral(cell, L0.HasName, L0.NameOf, L0.String, addr, Bindings.STRING);\r
-//                                             graph.addLiteral(cell, SHEET.Cell_content, SHEET.Cell_content_Inverse, L0.Variant, Variant.ofInstance(content), Bindings.VARIANT);\r
-//                                             graph.claim(cell, L0.PartOf, container);\r
-//                                     }\r
-                                       \r
-\r
-                                       }\r
-                                       \r
-                                       \r
-                               }\r
-                               \r
-                       });\r
-                       \r
-//                     System.err.println("excel.setString " + value);\r
-                       \r
-               } else if("Excel".equals(location) && "Visible".equals(property) && value instanceof Boolean) {\r
-\r
-                       Boolean visible = (Boolean)value;\r
-                       if(visible) {\r
-                               \r
-                       try {\r
-                               if(handle == 0) {\r
-                                       \r
-                                       Excel excel = Excel.getInstance(System.out);\r
-                                       String file = excel.getFile(bookName);\r
-                                       FileUtils.ensureParentDirectoryExists(file);\r
-                                       \r
-                                       //String sheetName2 = sheetName;//(sheetName + UUID.randomUUID().toString()).substring(0,30);\r
-                                       String sheetName2 = (bookName + "_" + sheetName).substring(0,30).replace(".", "_");\r
-                                       \r
-                                       String handleString = excel.open_(file, sheetName2);\r
-                                       try {\r
-                                               handle = Integer.valueOf(handleString);\r
-                                       } catch (NumberFormatException e) {\r
-                                               ShowMessage.showError("Problems with Excel", handleString);\r
-                                               Logger.defaultLogError(new RuntimeException(handleString));\r
-                                               return;\r
-                                       }\r
-//                                     System.err.println("excel.open " + (name + ".xlsx"));\r
-                                       \r
-                                               for(Pair<String, Object> label : model.listAll(ClientModel.LABEL)) {\r
-                                                       try {\r
-                                                               Range range = SpreadsheetUtils.decodeCellAbsolute(label.first);\r
-                                                               excel.setString_(handle, range.startRow, range.startColumn, (String)label.second);\r
-//                                                             System.err.println("excel.setString " + label.second);\r
-                                                       } catch (CellParseException e) {\r
-                                                       }\r
-                                               }\r
-                                               for(Pair<String, Object> label : model.listAll(ClientModel.CONTENT)) {\r
-                                                       try {\r
-                                                               Range range = SpreadsheetUtils.decodeCellAbsolute(label.first);\r
-                                                               //excel.setString_(handle, range.startRow, range.startColumn, (String)label.second);\r
-                                                               \r
-                                                               String uri = (String)label.second;\r
-                                                               if(uri.startsWith(prefix)) {\r
-                                                                       String rvi = uri.substring(prefix.length()+1).replace("#", "_").replace("(", "_").replace(")", "_").replace("+", "p").replace("-", "m");\r
-                                                                       excel.setName_(handle, range.startRow, range.startColumn, rvi);\r
-//                                                                     System.err.println("excel.setCellName '" + rvi + "'");\r
-                                                               }\r
-                                                               \r
-                                                       } catch (CellParseException e) {\r
-                                                       }\r
-                                               }\r
-                                               \r
-                               }\r
-                       } catch (Throwable t) {\r
-                               Logger.defaultLogError(t);\r
-                       }\r
-                               \r
-                       } else {\r
-\r
-                       try {\r
-//                             doClose();\r
-                               if(handle != 0) {\r
-                                       Excel excel = Excel.getInstance(System.out); \r
-                                       handle = excel.close_(handle);\r
-                                       handle = 0;\r
-                               }\r
-                       } catch (Throwable t) {\r
-                               Logger.defaultLogError(t);\r
-                       }\r
-                               \r
-                       }\r
-//                     excel.setVisible_(handle, (Boolean)value);\r
-//                     System.err.println("excel.setVisible " + value);\r
-               }\r
-       }\r
-    \r
-//    @Override\r
-//    public void changed(int row, int column, Cell cell) {\r
-//\r
-//        String value = cell != null ? cell.toString() : "";\r
-//        if(value == null) value = "...";\r
-//        excel.setString_(handle, row, column, value);\r
-//        \r
-//    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.spreadsheet.ui.editor;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.simantics.Simantics;
+import org.simantics.databoard.Bindings;
+import org.simantics.databoard.binding.mutable.Variant;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.Session;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.ResourceRead;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.common.utils.Logger;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.util.Layer0Utils;
+import org.simantics.excel.Excel;
+import org.simantics.excel.ExcelException;
+import org.simantics.layer0.Layer0;
+import org.simantics.spreadsheet.ClientModel;
+import org.simantics.spreadsheet.Range;
+import org.simantics.spreadsheet.common.client.ClientModelListenerAdapter;
+import org.simantics.spreadsheet.common.exception.CellParseException;
+import org.simantics.spreadsheet.resource.SpreadsheetResource;
+import org.simantics.spreadsheet.util.SpreadsheetUtils;
+import org.simantics.utils.FileUtils;
+import org.simantics.utils.datastructures.Pair;
+import org.simantics.utils.ui.dialogs.ShowMessage;
+
+public class ExcelLink extends ClientModelListenerAdapter {
+
+       final private Session session;
+       final private Resource container;
+    final private ClientModel model;
+    final private Resource book;
+    final private String bookName;
+    final private String sheetName;
+    final private String prefix;
+    final private Excel excel;
+    private int handle;
+    
+    public ExcelLink(Session session, Resource container, ClientModel model, final Resource book, String bookName, String sheetName, String prefix) {
+        
+       this.session = session;
+       this.container = container;
+       this.handle = 0;
+        this.model = model;
+        this.bookName = bookName + ".xlsx";
+        this.sheetName = sheetName;
+        this.prefix = prefix;
+        this.book = book;
+        
+        this.excel = tryGetExcel(book, bookName);
+
+               model.addListener(this);
+        
+    }
+    
+    public static Excel tryGetExcel(final Resource book, final String bookName) {
+
+       try {
+
+               Excel excel = Excel.getInstance(System.out);
+               String file = excel.getFile(bookName);
+               final File tester = new File(file);
+
+               if(!tester.exists()) {
+                       // Restore file from graph
+                       try {
+                               byte[] saved = Simantics.getSession().syncRequest(new ResourceRead<byte[]>(book) {
+
+                                       @Override
+                                       public byte[] perform(ReadGraph graph) throws DatabaseException {
+                                               SpreadsheetResource SR = SpreadsheetResource.getInstance(graph);
+                                               return graph.getPossibleRelatedValue(book, SR.HasMicrosoftExcelDocumentData, Bindings.BYTE_ARRAY);
+                                       }
+
+                               });
+                               if(saved != null) FileUtils.writeFile(tester, saved);
+                       } catch (DatabaseException e) {
+                               Logger.defaultLogError(e);
+                       } catch (IOException e) {
+                               Logger.defaultLogError(e);
+                       }
+               }
+
+               return excel;
+
+       } catch (ExcelException e1) {
+
+               Logger.defaultLogError(e1);
+
+       } 
+
+       return null;
+
+    }
+
+    public void dispose() {
+       
+       model.removeListener(this);
+
+               try {
+                       
+                       if(excel != null) {
+                       if(handle != 0) excel.close_(handle);
+                               String file = excel.getFile(bookName);
+                               File tester = new File(file);
+                               if(tester.exists()) {
+                                       final byte[] saved = FileUtils.readFile(tester);
+                                       if(saved != null) {
+                                               Simantics.getSession().syncRequest(new WriteRequest() {
+       
+                                                       @Override
+                                                       public void perform(WriteGraph graph) throws DatabaseException {
+                                                               SpreadsheetResource SR = SpreadsheetResource.getInstance(graph);
+                                                               graph.claimLiteral(book, SR.HasMicrosoftExcelDocumentData, saved, Bindings.BYTE_ARRAY);
+                                                       }
+       
+                                               });
+                                       }
+                               }
+                       }
+                       
+               } catch (DatabaseException e) {
+                       Logger.defaultLogError(e);
+               } catch (IOException e) {
+                       Logger.defaultLogError(e);
+               }
+       
+    }
+
+       @Override
+       public void propertyChange(String location, String property, Object value) {
+               
+               if(ClientModel.CONTENT.equals(property) && value != null && value instanceof Variant) {
+                       
+                       if(handle == 0) return;
+                       Range range = SpreadsheetUtils.decodeCellAbsolute(location);
+                       excel.setString_(handle, range.startRow, range.startColumn, ((Variant)value).getValue().toString());
+                       final String modis = excel.getModifications_(handle);
+
+                       session.asyncRequest(new WriteRequest() {
+
+                               @Override
+                               public void perform(WriteGraph graph) throws DatabaseException {
+
+                                       String[] parts = (modis+"0").split("#");
+                                       
+                                       Range range = SpreadsheetUtils.decodeRange(parts[0]);
+                                       
+                               Layer0 L0 = Layer0.getInstance(graph);
+                               SpreadsheetResource SHEET = SpreadsheetResource.getInstance(graph);
+                                       
+                                       int index = 1;
+                                       for(int i=0;i<range.height();i++) {
+                                               for(int j=0;j<range.width();j++) {
+                                                       
+                                                       String addr = SpreadsheetUtils.cellName(range.startRow + i, range.startColumn + j);
+                                                       String content = parts[index++];
+                                                       
+                                                       Resource cell = Layer0Utils.getPossibleChild(graph, container, addr);
+                                                       if(cell != null) {
+                                                               Variant newValue = Variant.ofInstance(content);
+                                                               Variant existing = graph.getRelatedValue(cell, SHEET.Cell_content, Bindings.VARIANT);
+                                                               if(!newValue.equals(existing)) {
+                                                                       graph.claimLiteral(cell, SHEET.Cell_content, SHEET.Cell_content_Inverse, L0.Variant, newValue, Bindings.VARIANT);
+                                                               }
+                                                       } else {
+                                                               cell = graph.newResource();
+                                                               graph.claim(cell, L0.InstanceOf, null, SHEET.TextCell);
+                                                               graph.addLiteral(cell, L0.HasName, L0.NameOf, L0.String, addr, Bindings.STRING);
+                                                               graph.addLiteral(cell, SHEET.Cell_content, SHEET.Cell_content_Inverse, L0.Variant, Variant.ofInstance(content), Bindings.VARIANT);
+                                                               graph.claim(cell, L0.PartOf, container);
+                                                       }
+                                                       
+                                               }
+                                       }
+                                       
+                                       for(int i=1;i<parts.length;i++) {
+//                                             String addr = parts[i];
+//                                             String content = parts[i+1];
+//                                             
+//                                     Layer0 L0 = Layer0.getInstance(graph);
+//                                     SpreadsheetResource SHEET = SpreadsheetResource.getInstance(graph);
+//                                     
+//                                     Resource cell = Layer0Utils.getPossibleChild(graph, container, addr);
+//                                     if(cell != null) {
+//                                             Variant newValue = Variant.ofInstance(content);
+//                                             Variant existing = graph.getRelatedValue(cell, SHEET.Cell_content, Bindings.VARIANT);
+//                                             if(!newValue.equals(existing))
+//                                                     graph.claimLiteral(cell, SHEET.Cell_content, SHEET.Cell_content_Inverse, L0.Variant, newValue, Bindings.VARIANT);
+//                                     } else {
+//                                             cell = graph.newResource();
+//                                             graph.claim(cell, L0.InstanceOf, null, SHEET.TextCell);
+//                                             graph.addLiteral(cell, L0.HasName, L0.NameOf, L0.String, addr, Bindings.STRING);
+//                                             graph.addLiteral(cell, SHEET.Cell_content, SHEET.Cell_content_Inverse, L0.Variant, Variant.ofInstance(content), Bindings.VARIANT);
+//                                             graph.claim(cell, L0.PartOf, container);
+//                                     }
+                                       
+
+                                       }
+                                       
+                                       
+                               }
+                               
+                       });
+                       
+//                     System.err.println("excel.setString " + value);
+                       
+               } else if("Excel".equals(location) && "Visible".equals(property) && value instanceof Boolean) {
+
+                       Boolean visible = (Boolean)value;
+                       if(visible) {
+                               
+                       try {
+                               if(handle == 0) {
+                                       
+                                       Excel excel = Excel.getInstance(System.out);
+                                       String file = excel.getFile(bookName);
+                                       FileUtils.ensureParentDirectoryExists(file);
+                                       
+                                       //String sheetName2 = sheetName;//(sheetName + UUID.randomUUID().toString()).substring(0,30);
+                                       String sheetName2 = (bookName + "_" + sheetName).substring(0,30).replace(".", "_");
+                                       
+                                       String handleString = excel.open_(file, sheetName2);
+                                       try {
+                                               handle = Integer.valueOf(handleString);
+                                       } catch (NumberFormatException e) {
+                                               ShowMessage.showError("Problems with Excel", handleString);
+                                               Logger.defaultLogError(new RuntimeException(handleString));
+                                               return;
+                                       }
+//                                     System.err.println("excel.open " + (name + ".xlsx"));
+                                       
+                                               for(Pair<String, Object> label : model.listAll(ClientModel.LABEL)) {
+                                                       try {
+                                                               Range range = SpreadsheetUtils.decodeCellAbsolute(label.first);
+                                                               excel.setString_(handle, range.startRow, range.startColumn, (String)label.second);
+//                                                             System.err.println("excel.setString " + label.second);
+                                                       } catch (CellParseException e) {
+                                                       }
+                                               }
+                                               for(Pair<String, Object> label : model.listAll(ClientModel.CONTENT)) {
+                                                       try {
+                                                               Range range = SpreadsheetUtils.decodeCellAbsolute(label.first);
+                                                               //excel.setString_(handle, range.startRow, range.startColumn, (String)label.second);
+                                                               
+                                                               String uri = (String)label.second;
+                                                               if(uri.startsWith(prefix)) {
+                                                                       String rvi = uri.substring(prefix.length()+1).replace("#", "_").replace("(", "_").replace(")", "_").replace("+", "p").replace("-", "m");
+                                                                       excel.setName_(handle, range.startRow, range.startColumn, rvi);
+//                                                                     System.err.println("excel.setCellName '" + rvi + "'");
+                                                               }
+                                                               
+                                                       } catch (CellParseException e) {
+                                                       }
+                                               }
+                                               
+                               }
+                       } catch (Throwable t) {
+                               Logger.defaultLogError(t);
+                       }
+                               
+                       } else {
+
+                       try {
+//                             doClose();
+                               if(handle != 0) {
+                                       Excel excel = Excel.getInstance(System.out); 
+                                       handle = excel.close_(handle);
+                                       handle = 0;
+                               }
+                       } catch (Throwable t) {
+                               Logger.defaultLogError(t);
+                       }
+                               
+                       }
+//                     excel.setVisible_(handle, (Boolean)value);
+//                     System.err.println("excel.setVisible " + value);
+               }
+       }
+    
+//    @Override
+//    public void changed(int row, int column, Cell cell) {
+//
+//        String value = cell != null ? cell.toString() : "";
+//        if(value == null) value = "...";
+//        excel.setString_(handle, row, column, value);
+//        
+//    }
+
+}