Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public static Document process(InputStream xlsStream) throws IOException, Parser
public static Document process(HSSFWorkbook workbook) throws IOException, ParserConfigurationException {
ExcelToHtmlConverter excelToHtmlConverter = new ExcelToHtmlConverter(
XMLHelper.newDocumentBuilder().newDocument());
excelToHtmlConverter.processWorkbook(workbook);
excelToHtmlConverter.processWorkbookSheet(workbook);
return excelToHtmlConverter.getDocument();
}

Expand Down Expand Up @@ -668,7 +668,7 @@ protected void processSheetHeader(Element htmlBody, HSSFSheet sheet) {
htmlBody.appendChild(h2);
}

public void processWorkbook(HSSFWorkbook workbook) {
public void processWorkbookSheet(HSSFWorkbook workbook) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need to be renamed

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, naming is not an issue. It was just my idea. Keeping the name same is also fine

final SummaryInformation summaryInformation = workbook
.getSummaryInformation();
if (summaryInformation != null) {
Expand All @@ -692,6 +692,24 @@ public void processWorkbook(HSSFWorkbook workbook) {
htmlDocumentFacade.updateStylesheet();
}

public void processWorkbookSheet(HSSFWorkbook workbook, int sheetNumber) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you call this processWorksheet?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be better to just pass a HSSFWorksheet in the input instead of a workbook and 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) {
this.cssClassPrefixCell = cssClassPrefixCell;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
import javax.xml.transform.stream.StreamResult;

import org.apache.poi.POIDataSamples;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.util.XMLHelper;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -64,6 +65,7 @@ public static Stream<Arguments> files() {
void testFo(File child) throws Exception
{
HSSFWorkbook workbook;
int sheetNumber = 0;
try {
workbook = AbstractExcelUtils.loadXls( child );
} catch ( Exception exc ) {
Expand All @@ -73,7 +75,8 @@ void testFo(File child) throws Exception

ExcelToHtmlConverter excelToHtmlConverter = new ExcelToHtmlConverter(
XMLHelper.newDocumentBuilder().newDocument() );
excelToHtmlConverter.processWorkbook( workbook );
excelToHtmlConverter.processWorkbookSheet( workbook);
excelToHtmlConverter.processWorkbookSheet( workbook, sheetNumber);

StringWriter stringWriter = new StringWriter();

Expand All @@ -90,6 +93,8 @@ void testFo(File child) throws Exception
void testHtml(File child) throws Exception
{
HSSFWorkbook workbook;
int sheetNumber = 0; //

try {
workbook = AbstractExcelUtils.loadXls( child );
} catch ( Exception exc ) {
Expand All @@ -99,7 +104,8 @@ void testHtml(File child) throws Exception

ExcelToHtmlConverter excelToHtmlConverter = new ExcelToHtmlConverter(
XMLHelper.newDocumentBuilder().newDocument() );
excelToHtmlConverter.processWorkbook( workbook );
excelToHtmlConverter.processWorkbookSheet( workbook);
excelToHtmlConverter.processWorkbookSheet( workbook, sheetNumber);

StringWriter stringWriter = new StringWriter();

Expand Down