poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From one...@apache.org
Subject svn commit: r1795256 - /poi/trunk/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java
Date Tue, 16 May 2017 00:58:01 GMT
Author: onealj
Date: Tue May 16 00:58:01 2017
New Revision: 1795256

URL: http://svn.apache.org/viewvc?rev=1795256&view=rev
Log:
github-52: add ExcelToHtmlConverter method that works on InputStreams. Thanks to Tony Zeng!
This closes #52.
https://github.com/apache/poi/pull/52

Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java?rev=1795256&r1=1795255&r2=1795256&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java Tue
May 16 00:58:01 2017
@@ -18,6 +18,7 @@ package org.apache.poi.hssf.converter;
 
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
@@ -106,7 +107,7 @@ public class ExcelToHtmlConverter extend
      * Converts Excel file (97-2007) into HTML file.
      * 
      * @param xlsFile
-     *            file to process
+     *            workbook file to process
      * @return DOM representation of result HTML
      * @throws IOException 
      * @throws ParserConfigurationException 
@@ -114,12 +115,48 @@ public class ExcelToHtmlConverter extend
     public static Document process( File xlsFile ) throws IOException, ParserConfigurationException
     {
         final HSSFWorkbook workbook = ExcelToHtmlUtils.loadXls( xlsFile );
+        try {
+            return ExcelToHtmlConverter.process( workbook );
+        } finally {
+            workbook.close();
+        }
+    }
+
+    /**
+     * Converts Excel file (97-2007) into HTML file.
+     * 
+     * @param xlsFile
+     *            workbook stream to process
+     * @return DOM representation of result HTML
+     * @throws IOException 
+     * @throws ParserConfigurationException 
+     */
+    public static Document process( InputStream xlsStream ) throws IOException, ParserConfigurationException
+    {
+        final HSSFWorkbook workbook = new HSSFWorkbook( xlsStream );
+        try {
+            return ExcelToHtmlConverter.process( workbook );
+        } finally {
+            workbook.close();
+        }
+    }
+
+    /**
+     * Converts Excel file (97-2007) into HTML file.
+     * 
+     * @param xlsFile
+     *            workbook instance to process
+     * @return DOM representation of result HTML
+     * @throws IOException 
+     * @throws ParserConfigurationException 
+     */
+    public static Document process( HSSFWorkbook workbook ) throws IOException, ParserConfigurationException
+    {
         ExcelToHtmlConverter excelToHtmlConverter = new ExcelToHtmlConverter(
                 XMLHelper.getDocumentBuilderFactory().newDocumentBuilder()
                         .newDocument() );
         excelToHtmlConverter.processWorkbook( workbook );
         Document doc = excelToHtmlConverter.getDocument();
-        workbook.close();
         return doc;
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message