]> source.dussan.org Git - poi.git/commitdiff
do not output hidden rows and columns by default (and add options to do so)
authorSergey Vladimirov <sergey@apache.org>
Mon, 18 Jul 2011 11:07:51 +0000 (11:07 +0000)
committerSergey Vladimirov <sergey@apache.org>
Mon, 18 Jul 2011 11:07:51 +0000 (11:07 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1147808 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java

index 74df9e9c095b764f74a9ece3f261001ecb83daab..375273d8862c16a98af9a6238b00f17be1784146 100644 (file)
@@ -129,6 +129,10 @@ public class ExcelToHtmlConverter
 
     private boolean outputColumnHeaders = true;
 
+    private boolean outputHiddenColumns = false;
+
+    private boolean outputHiddenRows = false;
+
     private boolean outputRowNumbers = true;
 
     private final Element stylesElement;
@@ -314,6 +318,16 @@ public class ExcelToHtmlConverter
         return outputColumnHeaders;
     }
 
+    public boolean isOutputHiddenColumns()
+    {
+        return outputHiddenColumns;
+    }
+
+    public boolean isOutputHiddenRows()
+    {
+        return outputHiddenRows;
+    }
+
     public boolean isOutputRowNumbers()
     {
         return outputRowNumbers;
@@ -413,7 +427,8 @@ public class ExcelToHtmlConverter
         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();
         table.appendChild( tableHeader );
@@ -428,6 +443,9 @@ public class ExcelToHtmlConverter
 
         for ( int c = 0; c < maxSheetColumns; c++ )
         {
+            if ( !isOutputHiddenColumns() && sheet.isColumnHidden( c ) )
+                continue;
+
             Element th = htmlDocumentFacade.createTableHeaderCell();
             String text = getColumnName( c );
             th.appendChild( htmlDocumentFacade.createText( text ) );
@@ -451,6 +469,9 @@ public class ExcelToHtmlConverter
         }
         for ( int c = 0; c < maxSheetColumns; c++ )
         {
+            if ( !isOutputHiddenColumns() && sheet.isColumnHidden( c ) )
+                continue;
+
             Element col = htmlDocumentFacade.createTableColumn();
             col.setAttribute( "width", String.valueOf( ExcelToHtmlUtils
                     .getColumnWidthInPx( sheet.getColumnWidth( c ) ) ) );
@@ -479,8 +500,8 @@ public class ExcelToHtmlConverter
     /**
      * @return maximum 1-base index of column that were rendered, zero if none
      */
-    protected int processRow( HSSFWorkbook workbook, HSSFRow row,
-            Element tableRowElement )
+    protected int processRow( HSSFWorkbook workbook, HSSFSheet sheet,
+            HSSFRow row, Element tableRowElement )
     {
         final short maxColIx = row.getLastCellNum();
         if ( maxColIx <= 0 )
@@ -501,6 +522,9 @@ public class ExcelToHtmlConverter
         {
             HSSFCell cell = row.getCell( colIx );
 
+            if ( !isOutputHiddenColumns() && sheet.isColumnHidden( colIx ) )
+                continue;
+
             Element tableCellElement = htmlDocumentFacade.createTableCell();
 
             boolean emptyCell;
@@ -559,17 +583,16 @@ public class ExcelToHtmlConverter
         {
             HSSFRow row = sheet.getRow( r );
 
+            if ( row == null )
+                continue;
+
+            if ( !isOutputHiddenRows() && row.getZeroHeight() )
+                continue;
+
             Element tableRowElement = htmlDocumentFacade.createTableRow();
 
-            int maxRowColumnNumber;
-            if ( row != null )
-            {
-                maxRowColumnNumber = processRow( workbook, row, tableRowElement );
-            }
-            else
-            {
-                maxRowColumnNumber = 0;
-            }
+            int maxRowColumnNumber = processRow( workbook, sheet, row,
+                    tableRowElement );
 
             if ( maxRowColumnNumber == 0 )
             {
@@ -595,7 +618,7 @@ public class ExcelToHtmlConverter
 
         if ( isOutputColumnHeaders() )
         {
-            processColumnHeaders( maxSheetColumns, table );
+            processColumnHeaders( sheet, maxSheetColumns, table );
         }
 
         table.appendChild( tableBody );
@@ -640,6 +663,16 @@ public class ExcelToHtmlConverter
         this.outputColumnHeaders = outputColumnHeaders;
     }
 
+    public void setOutputHiddenColumns( boolean outputZeroWidthColumns )
+    {
+        this.outputHiddenColumns = outputZeroWidthColumns;
+    }
+
+    public void setOutputHiddenRows( boolean outputZeroHeightRows )
+    {
+        this.outputHiddenRows = outputZeroHeightRows;
+    }
+
     public void setOutputRowNumbers( boolean outputRowNumbers )
     {
         this.outputRowNumbers = outputRowNumbers;