mirror of https://github.com/apache/poi.git
do not output hidden rows and columns by default (and add options to do so)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1147808 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3bc22e541c
commit
3a325afe8a
|
@ -129,6 +129,10 @@ public class ExcelToHtmlConverter
|
||||||
|
|
||||||
private boolean outputColumnHeaders = true;
|
private boolean outputColumnHeaders = true;
|
||||||
|
|
||||||
|
private boolean outputHiddenColumns = false;
|
||||||
|
|
||||||
|
private boolean outputHiddenRows = false;
|
||||||
|
|
||||||
private boolean outputRowNumbers = true;
|
private boolean outputRowNumbers = true;
|
||||||
|
|
||||||
private final Element stylesElement;
|
private final Element stylesElement;
|
||||||
|
@ -314,6 +318,16 @@ public class ExcelToHtmlConverter
|
||||||
return outputColumnHeaders;
|
return outputColumnHeaders;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isOutputHiddenColumns()
|
||||||
|
{
|
||||||
|
return outputHiddenColumns;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isOutputHiddenRows()
|
||||||
|
{
|
||||||
|
return outputHiddenRows;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isOutputRowNumbers()
|
public boolean isOutputRowNumbers()
|
||||||
{
|
{
|
||||||
return outputRowNumbers;
|
return outputRowNumbers;
|
||||||
|
@ -413,7 +427,8 @@ public class ExcelToHtmlConverter
|
||||||
return ExcelToHtmlUtils.isEmpty( value ) && cellStyleIndex == 0;
|
return ExcelToHtmlUtils.isEmpty( value ) && cellStyleIndex == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void processColumnHeaders( int maxSheetColumns, Element table )
|
protected void processColumnHeaders( HSSFSheet sheet, int maxSheetColumns,
|
||||||
|
Element table )
|
||||||
{
|
{
|
||||||
Element tableHeader = htmlDocumentFacade.createTableHeader();
|
Element tableHeader = htmlDocumentFacade.createTableHeader();
|
||||||
table.appendChild( tableHeader );
|
table.appendChild( tableHeader );
|
||||||
|
@ -428,6 +443,9 @@ public class ExcelToHtmlConverter
|
||||||
|
|
||||||
for ( int c = 0; c < maxSheetColumns; c++ )
|
for ( int c = 0; c < maxSheetColumns; c++ )
|
||||||
{
|
{
|
||||||
|
if ( !isOutputHiddenColumns() && sheet.isColumnHidden( c ) )
|
||||||
|
continue;
|
||||||
|
|
||||||
Element th = htmlDocumentFacade.createTableHeaderCell();
|
Element th = htmlDocumentFacade.createTableHeaderCell();
|
||||||
String text = getColumnName( c );
|
String text = getColumnName( c );
|
||||||
th.appendChild( htmlDocumentFacade.createText( text ) );
|
th.appendChild( htmlDocumentFacade.createText( text ) );
|
||||||
|
@ -451,6 +469,9 @@ public class ExcelToHtmlConverter
|
||||||
}
|
}
|
||||||
for ( int c = 0; c < maxSheetColumns; c++ )
|
for ( int c = 0; c < maxSheetColumns; c++ )
|
||||||
{
|
{
|
||||||
|
if ( !isOutputHiddenColumns() && sheet.isColumnHidden( c ) )
|
||||||
|
continue;
|
||||||
|
|
||||||
Element col = htmlDocumentFacade.createTableColumn();
|
Element col = htmlDocumentFacade.createTableColumn();
|
||||||
col.setAttribute( "width", String.valueOf( ExcelToHtmlUtils
|
col.setAttribute( "width", String.valueOf( ExcelToHtmlUtils
|
||||||
.getColumnWidthInPx( sheet.getColumnWidth( c ) ) ) );
|
.getColumnWidthInPx( sheet.getColumnWidth( c ) ) ) );
|
||||||
|
@ -479,8 +500,8 @@ public class ExcelToHtmlConverter
|
||||||
/**
|
/**
|
||||||
* @return maximum 1-base index of column that were rendered, zero if none
|
* @return maximum 1-base index of column that were rendered, zero if none
|
||||||
*/
|
*/
|
||||||
protected int processRow( HSSFWorkbook workbook, HSSFRow row,
|
protected int processRow( HSSFWorkbook workbook, HSSFSheet sheet,
|
||||||
Element tableRowElement )
|
HSSFRow row, Element tableRowElement )
|
||||||
{
|
{
|
||||||
final short maxColIx = row.getLastCellNum();
|
final short maxColIx = row.getLastCellNum();
|
||||||
if ( maxColIx <= 0 )
|
if ( maxColIx <= 0 )
|
||||||
|
@ -501,6 +522,9 @@ public class ExcelToHtmlConverter
|
||||||
{
|
{
|
||||||
HSSFCell cell = row.getCell( colIx );
|
HSSFCell cell = row.getCell( colIx );
|
||||||
|
|
||||||
|
if ( !isOutputHiddenColumns() && sheet.isColumnHidden( colIx ) )
|
||||||
|
continue;
|
||||||
|
|
||||||
Element tableCellElement = htmlDocumentFacade.createTableCell();
|
Element tableCellElement = htmlDocumentFacade.createTableCell();
|
||||||
|
|
||||||
boolean emptyCell;
|
boolean emptyCell;
|
||||||
|
@ -559,17 +583,16 @@ public class ExcelToHtmlConverter
|
||||||
{
|
{
|
||||||
HSSFRow row = sheet.getRow( r );
|
HSSFRow row = sheet.getRow( r );
|
||||||
|
|
||||||
|
if ( row == null )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if ( !isOutputHiddenRows() && row.getZeroHeight() )
|
||||||
|
continue;
|
||||||
|
|
||||||
Element tableRowElement = htmlDocumentFacade.createTableRow();
|
Element tableRowElement = htmlDocumentFacade.createTableRow();
|
||||||
|
|
||||||
int maxRowColumnNumber;
|
int maxRowColumnNumber = processRow( workbook, sheet, row,
|
||||||
if ( row != null )
|
tableRowElement );
|
||||||
{
|
|
||||||
maxRowColumnNumber = processRow( workbook, row, tableRowElement );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
maxRowColumnNumber = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( maxRowColumnNumber == 0 )
|
if ( maxRowColumnNumber == 0 )
|
||||||
{
|
{
|
||||||
|
@ -595,7 +618,7 @@ public class ExcelToHtmlConverter
|
||||||
|
|
||||||
if ( isOutputColumnHeaders() )
|
if ( isOutputColumnHeaders() )
|
||||||
{
|
{
|
||||||
processColumnHeaders( maxSheetColumns, table );
|
processColumnHeaders( sheet, maxSheetColumns, table );
|
||||||
}
|
}
|
||||||
|
|
||||||
table.appendChild( tableBody );
|
table.appendChild( tableBody );
|
||||||
|
@ -640,6 +663,16 @@ public class ExcelToHtmlConverter
|
||||||
this.outputColumnHeaders = outputColumnHeaders;
|
this.outputColumnHeaders = outputColumnHeaders;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setOutputHiddenColumns( boolean outputZeroWidthColumns )
|
||||||
|
{
|
||||||
|
this.outputHiddenColumns = outputZeroWidthColumns;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOutputHiddenRows( boolean outputZeroHeightRows )
|
||||||
|
{
|
||||||
|
this.outputHiddenRows = outputZeroHeightRows;
|
||||||
|
}
|
||||||
|
|
||||||
public void setOutputRowNumbers( boolean outputRowNumbers )
|
public void setOutputRowNumbers( boolean outputRowNumbers )
|
||||||
{
|
{
|
||||||
this.outputRowNumbers = outputRowNumbers;
|
this.outputRowNumbers = outputRowNumbers;
|
||||||
|
|
Loading…
Reference in New Issue