mirror of https://github.com/apache/poi.git
Implement specificWorkbookSheet method
This commit is contained in:
parent
dd50cb1c67
commit
1c1bd6e585
|
@ -136,7 +136,7 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter {
|
||||||
public static Document process(HSSFWorkbook workbook) throws IOException, ParserConfigurationException {
|
public static Document process(HSSFWorkbook workbook) throws IOException, ParserConfigurationException {
|
||||||
ExcelToHtmlConverter excelToHtmlConverter = new ExcelToHtmlConverter(
|
ExcelToHtmlConverter excelToHtmlConverter = new ExcelToHtmlConverter(
|
||||||
XMLHelper.newDocumentBuilder().newDocument());
|
XMLHelper.newDocumentBuilder().newDocument());
|
||||||
excelToHtmlConverter.processWorkbook(workbook);
|
excelToHtmlConverter.processWorkbookSheet(workbook);
|
||||||
return excelToHtmlConverter.getDocument();
|
return excelToHtmlConverter.getDocument();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -668,7 +668,7 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter {
|
||||||
htmlBody.appendChild(h2);
|
htmlBody.appendChild(h2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void processWorkbook(HSSFWorkbook workbook) {
|
public void processWorkbookSheet(HSSFWorkbook workbook) {
|
||||||
final SummaryInformation summaryInformation = workbook
|
final SummaryInformation summaryInformation = workbook
|
||||||
.getSummaryInformation();
|
.getSummaryInformation();
|
||||||
if (summaryInformation != null) {
|
if (summaryInformation != null) {
|
||||||
|
@ -692,6 +692,24 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter {
|
||||||
htmlDocumentFacade.updateStylesheet();
|
htmlDocumentFacade.updateStylesheet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void processWorkbookSheet(HSSFWorkbook workbook, int sheetNumber) {
|
||||||
|
SummaryInformation summaryInformation = workbook.getSummaryInformation();
|
||||||
|
|
||||||
|
if (summaryInformation != null) {
|
||||||
|
this.processDocumentInformation(summaryInformation);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (workbook.getNumberOfSheets() < sheetNumber) {
|
||||||
|
throw new IllegalArgumentException("invalid sheet number: " + sheetNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
HSSFSheet sheet = workbook.getSheetAt(sheetNumber);
|
||||||
|
|
||||||
|
this.processSheet(sheet);
|
||||||
|
|
||||||
|
htmlDocumentFacade.updateStylesheet();
|
||||||
|
}
|
||||||
|
|
||||||
public void setCssClassPrefixCell(String cssClassPrefixCell) {
|
public void setCssClassPrefixCell(String cssClassPrefixCell) {
|
||||||
this.cssClassPrefixCell = cssClassPrefixCell;
|
this.cssClassPrefixCell = cssClassPrefixCell;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ import javax.xml.transform.dom.DOMSource;
|
||||||
import javax.xml.transform.stream.StreamResult;
|
import javax.xml.transform.stream.StreamResult;
|
||||||
|
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
|
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
import org.apache.poi.util.XMLHelper;
|
import org.apache.poi.util.XMLHelper;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
@ -64,6 +65,7 @@ public class TestExcelConverterSuite
|
||||||
void testFo(File child) throws Exception
|
void testFo(File child) throws Exception
|
||||||
{
|
{
|
||||||
HSSFWorkbook workbook;
|
HSSFWorkbook workbook;
|
||||||
|
int sheetNumber = 0;
|
||||||
try {
|
try {
|
||||||
workbook = AbstractExcelUtils.loadXls( child );
|
workbook = AbstractExcelUtils.loadXls( child );
|
||||||
} catch ( Exception exc ) {
|
} catch ( Exception exc ) {
|
||||||
|
@ -73,7 +75,8 @@ public class TestExcelConverterSuite
|
||||||
|
|
||||||
ExcelToHtmlConverter excelToHtmlConverter = new ExcelToHtmlConverter(
|
ExcelToHtmlConverter excelToHtmlConverter = new ExcelToHtmlConverter(
|
||||||
XMLHelper.newDocumentBuilder().newDocument() );
|
XMLHelper.newDocumentBuilder().newDocument() );
|
||||||
excelToHtmlConverter.processWorkbook( workbook );
|
excelToHtmlConverter.processWorkbookSheet( workbook);
|
||||||
|
excelToHtmlConverter.processWorkbookSheet( workbook, sheetNumber);
|
||||||
|
|
||||||
StringWriter stringWriter = new StringWriter();
|
StringWriter stringWriter = new StringWriter();
|
||||||
|
|
||||||
|
@ -90,6 +93,8 @@ public class TestExcelConverterSuite
|
||||||
void testHtml(File child) throws Exception
|
void testHtml(File child) throws Exception
|
||||||
{
|
{
|
||||||
HSSFWorkbook workbook;
|
HSSFWorkbook workbook;
|
||||||
|
int sheetNumber = 0; //
|
||||||
|
|
||||||
try {
|
try {
|
||||||
workbook = AbstractExcelUtils.loadXls( child );
|
workbook = AbstractExcelUtils.loadXls( child );
|
||||||
} catch ( Exception exc ) {
|
} catch ( Exception exc ) {
|
||||||
|
@ -99,7 +104,8 @@ public class TestExcelConverterSuite
|
||||||
|
|
||||||
ExcelToHtmlConverter excelToHtmlConverter = new ExcelToHtmlConverter(
|
ExcelToHtmlConverter excelToHtmlConverter = new ExcelToHtmlConverter(
|
||||||
XMLHelper.newDocumentBuilder().newDocument() );
|
XMLHelper.newDocumentBuilder().newDocument() );
|
||||||
excelToHtmlConverter.processWorkbook( workbook );
|
excelToHtmlConverter.processWorkbookSheet( workbook);
|
||||||
|
excelToHtmlConverter.processWorkbookSheet( workbook, sheetNumber);
|
||||||
|
|
||||||
StringWriter stringWriter = new StringWriter();
|
StringWriter stringWriter = new StringWriter();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue