github-52: add ExcelToHtmlConverter method that works on InputStreams. Thanks to Tony Zeng! This closes #52.
https://github.com/apache/poi/pull/52 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1795256 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fac98b5bef
commit
b527f96daa
@ -18,6 +18,7 @@ package org.apache.poi.hssf.converter;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -106,7 +107,7 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
|
|||||||
* Converts Excel file (97-2007) into HTML file.
|
* Converts Excel file (97-2007) into HTML file.
|
||||||
*
|
*
|
||||||
* @param xlsFile
|
* @param xlsFile
|
||||||
* file to process
|
* workbook file to process
|
||||||
* @return DOM representation of result HTML
|
* @return DOM representation of result HTML
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* @throws ParserConfigurationException
|
* @throws ParserConfigurationException
|
||||||
@ -114,12 +115,48 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
|
|||||||
public static Document process( File xlsFile ) throws IOException, ParserConfigurationException
|
public static Document process( File xlsFile ) throws IOException, ParserConfigurationException
|
||||||
{
|
{
|
||||||
final HSSFWorkbook workbook = ExcelToHtmlUtils.loadXls( xlsFile );
|
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(
|
ExcelToHtmlConverter excelToHtmlConverter = new ExcelToHtmlConverter(
|
||||||
XMLHelper.getDocumentBuilderFactory().newDocumentBuilder()
|
XMLHelper.getDocumentBuilderFactory().newDocumentBuilder()
|
||||||
.newDocument() );
|
.newDocument() );
|
||||||
excelToHtmlConverter.processWorkbook( workbook );
|
excelToHtmlConverter.processWorkbook( workbook );
|
||||||
Document doc = excelToHtmlConverter.getDocument();
|
Document doc = excelToHtmlConverter.getDocument();
|
||||||
workbook.close();
|
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user