diff options
author | Sergey Vladimirov <sergey@apache.org> | 2011-09-13 16:10:27 +0000 |
---|---|---|
committer | Sergey Vladimirov <sergey@apache.org> | 2011-09-13 16:10:27 +0000 |
commit | 87174c60a124f56a84dd173103ad74be63d00f5d (patch) | |
tree | 8e798bcda1e67acd8ebf99add17e55bc6149f403 | |
parent | d2e01397f004973a86c9f7bcc261a9dedeaa69cb (diff) | |
download | poi-87174c60a124f56a84dd173103ad74be63d00f5d.tar.gz poi-87174c60a124f56a84dd173103ad74be63d00f5d.zip |
better handle (i.e. skip) empty cells
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1170223 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToFoConverter.java | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToFoConverter.java b/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToFoConverter.java index dd0b826ec8..0d031396c0 100644 --- a/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToFoConverter.java +++ b/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToFoConverter.java @@ -40,6 +40,7 @@ import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.hwpf.converter.FoDocumentFacade; import org.apache.poi.hwpf.converter.FontReplacer.Triplet; import org.apache.poi.ss.formula.eval.ErrorEval; +import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.util.Beta; import org.apache.poi.util.POILogFactory; @@ -179,6 +180,22 @@ public class ExcelToFoConverter extends AbstractExcelConverter return foDocumentFacade.getDocument(); } + /** + * Returns <tt>false</tt> if cell style by itself (without text, i.e. + * borders, fill, etc.) worth a mention, <tt>true</tt> otherwise + * + * @return <tt>false</tt> if cell style by itself (without text, i.e. + * borders, fill, etc.) worth a mention, <tt>true</tt> otherwise + */ + protected boolean isEmptyStyle( CellStyle cellStyle ) + { + return cellStyle.getFillPattern() == 0 // + && cellStyle.getBorderTop() == HSSFCellStyle.BORDER_NONE // + && cellStyle.getBorderRight() == HSSFCellStyle.BORDER_NONE // + && cellStyle.getBorderBottom() == HSSFCellStyle.BORDER_NONE // + && cellStyle.getBorderLeft() == HSSFCellStyle.BORDER_NONE; // + } + protected boolean processCell( HSSFWorkbook workbook, HSSFCell cell, Element tableCellElement, int normalWidthPx, int maxSpannedWidthPx, float normalHeightPt ) @@ -255,8 +272,8 @@ public class ExcelToFoConverter extends AbstractExcelConverter final boolean noText = ExcelToHtmlUtils.isEmpty( value ); final boolean wrapInDivs = !noText && !cellStyle.getWrapText(); - final short cellStyleIndex = cellStyle.getIndex(); - if ( cellStyleIndex != 0 ) + final boolean emptyStyle = isEmptyStyle( cellStyle ); + if ( !emptyStyle ) { if ( noText ) { @@ -306,13 +323,13 @@ public class ExcelToFoConverter extends AbstractExcelConverter block.setAttribute( "keep-together.within-line", "always" ); } - processCellStyle( workbook, cell.getCellStyle(), tableCellElement, - block ); + processCellStyle( workbook, cell.getCellStyle(), + tableCellElement, block ); block.appendChild( text ); tableCellElement.appendChild( block ); - return ExcelToHtmlUtils.isEmpty( value ) && cellStyleIndex == 0; + return ExcelToHtmlUtils.isEmpty( value ) && emptyStyle; } protected void processCellStyle( HSSFWorkbook workbook, @@ -358,6 +375,7 @@ public class ExcelToFoConverter extends AbstractExcelConverter HSSFFont font = cellStyle.getFont( workbook ); processCellStyleFont( workbook, blockTarget, font ); + } protected void processCellStyleBorder( HSSFWorkbook workbook, |