aboutsummaryrefslogtreecommitdiffstats
path: root/src/scratchpad
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2017-12-28 08:45:26 +0000
committerDominik Stadler <centic@apache.org>2017-12-28 08:45:26 +0000
commit62c8296c709b7ea1291d87f5658b69d80b20ace7 (patch)
treef55bf50981221a711bccbe585b1cb0ab7ffaf4ee /src/scratchpad
parent6e67de21602e2a33ff0420e83d914a7da61e27a3 (diff)
downloadpoi-62c8296c709b7ea1291d87f5658b69d80b20ace7.tar.gz
poi-62c8296c709b7ea1291d87f5658b69d80b20ace7.zip
Fix IntelliJ warnings and code formatting, generalize ExcelToHtmlUtils, use try-with-resources, update/enhance JavaDoc somewhat
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1819402 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/scratchpad')
-rw-r--r--src/scratchpad/src/org/apache/poi/hssf/converter/AbstractExcelUtils.java50
-rw-r--r--src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java173
-rw-r--r--src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlUtils.java28
3 files changed, 81 insertions, 170 deletions
diff --git a/src/scratchpad/src/org/apache/poi/hssf/converter/AbstractExcelUtils.java b/src/scratchpad/src/org/apache/poi/hssf/converter/AbstractExcelUtils.java
index ece9b46831..aa8863f841 100644
--- a/src/scratchpad/src/org/apache/poi/hssf/converter/AbstractExcelUtils.java
+++ b/src/scratchpad/src/org/apache/poi/hssf/converter/AbstractExcelUtils.java
@@ -20,15 +20,14 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
-import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.hwpf.converter.AbstractWordUtils;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
+import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.Beta;
-import org.apache.poi.util.IOUtils;
/**
* Common class for {@link ExcelToFoUtils} and {@link ExcelToHtmlUtils}
@@ -38,16 +37,13 @@ import org.apache.poi.util.IOUtils;
* @since POI 3.8 beta 5
*/
@Beta
-public class AbstractExcelUtils
-{
+public class AbstractExcelUtils {
/*package*/ static final String EMPTY = "";
private static final short EXCEL_COLUMN_WIDTH_FACTOR = 256;
private static final int UNIT_OFFSET_LENGTH = 7;
- public static String getAlign( HorizontalAlignment alignment )
- {
- switch ( alignment )
- {
+ public static String getAlign( HorizontalAlignment alignment ) {
+ switch ( alignment ) {
case CENTER:
return "center";
case CENTER_SELECTION:
@@ -68,11 +64,9 @@ public class AbstractExcelUtils
}
}
- public static String getBorderStyle( BorderStyle xlsBorder )
- {
+ public static String getBorderStyle( BorderStyle xlsBorder ) {
final String borderStyle;
- switch ( xlsBorder )
- {
+ switch ( xlsBorder ) {
case NONE:
borderStyle = "none";
break;
@@ -99,11 +93,9 @@ public class AbstractExcelUtils
return borderStyle;
}
- public static String getBorderWidth( BorderStyle xlsBorder )
- {
+ public static String getBorderWidth( BorderStyle xlsBorder ) {
final String borderWidth;
- switch ( xlsBorder )
- {
+ switch ( xlsBorder ) {
case MEDIUM_DASH_DOT:
case MEDIUM_DASH_DOT_DOT:
case MEDIUM_DASHED:
@@ -119,12 +111,10 @@ public class AbstractExcelUtils
return borderWidth;
}
- public static String getColor( HSSFColor color )
- {
+ public static String getColor( HSSFColor color ) {
StringBuilder stringBuilder = new StringBuilder( 7 );
stringBuilder.append( '#' );
- for ( short s : color.getTriplet() )
- {
+ for ( short s : color.getTriplet() ) {
if ( s < 10 )
stringBuilder.append( '0' );
@@ -152,8 +142,7 @@ public class AbstractExcelUtils
* "http://apache-poi.1045710.n5.nabble.com/Excel-Column-Width-Unit-Converter-pixels-excel-column-width-units-td2301481.html"
* >here</a> for Xio explanation and details
*/
- public static int getColumnWidthInPx( int widthUnits )
- {
+ public static int getColumnWidthInPx( int widthUnits ) {
int pixels = ( widthUnits / EXCEL_COLUMN_WIDTH_FACTOR )
* UNIT_OFFSET_LENGTH;
@@ -167,13 +156,12 @@ public class AbstractExcelUtils
/**
* @param mergedRanges
* map of sheet merged ranges built with
- * {@link ExcelToHtmlUtils#buildMergedRangesMap(HSSFSheet)}
+ * {@link ExcelToHtmlUtils#buildMergedRangesMap(Sheet)}
* @return {@link CellRangeAddress} from map if cell with specified row and
* column numbers contained in found range, <tt>null</tt> otherwise
*/
public static CellRangeAddress getMergedRange(
- CellRangeAddress[][] mergedRanges, int rowNumber, int columnNumber )
- {
+ CellRangeAddress[][] mergedRanges, int rowNumber, int columnNumber ) {
CellRangeAddress[] mergedRangeRowInfo = rowNumber < mergedRanges.length ? mergedRanges[rowNumber]
: null;
@@ -192,17 +180,9 @@ public class AbstractExcelUtils
return !isEmpty( str );
}
- public static HSSFWorkbook loadXls( File xlsFile ) throws IOException
- {
- final FileInputStream inputStream = new FileInputStream( xlsFile );
- try
- {
+ public static HSSFWorkbook loadXls(File xlsFile ) throws IOException {
+ try (final FileInputStream inputStream = new FileInputStream( xlsFile )) {
return new HSSFWorkbook( inputStream );
}
- finally
- {
- IOUtils.closeQuietly( inputStream );
- }
}
-
}
diff --git a/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java b/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java
index d507dba99f..2e173e15d4 100644
--- a/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java
+++ b/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java
@@ -27,7 +27,6 @@ import java.util.Map;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
@@ -59,9 +58,7 @@ import org.w3c.dom.Text;
* @author Sergey Vladimirov (vlsergey {at} gmail {dot} com)
*/
@Beta
-public class ExcelToHtmlConverter extends AbstractExcelConverter
-{
-
+public class ExcelToHtmlConverter extends AbstractExcelConverter {
private static final POILogger logger = POILogFactory
.getLogger( ExcelToHtmlConverter.class );
@@ -73,16 +70,10 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
* </p>
* Where infile is an input .xls file ( Word 97-2007) which will be rendered
* as HTML into outfile
- * @throws TransformerException
- * @throws Exception
*/
- public static void main( String[] args )
- throws IOException, ParserConfigurationException, TransformerException
- {
- if ( args.length < 2 )
- {
- System.err
- .println( "Usage: ExcelToHtmlConverter <inputFile.xls> <saveTo.html>" );
+ public static void main( String[] args ) throws Exception {
+ if ( args.length < 2 ) {
+ System.err.println( "Usage: ExcelToHtmlConverter <inputFile.xls> <saveTo.html>" );
return;
}
@@ -109,16 +100,12 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
* @param xlsFile
* workbook file to process
* @return DOM representation of result HTML
- * @throws IOException
- * @throws ParserConfigurationException
+ * @throws IOException If an error occurs reading or writing files
+ * @throws ParserConfigurationException If configuration is incorrect
*/
- public static Document process( File xlsFile ) throws IOException, ParserConfigurationException
- {
- final HSSFWorkbook workbook = ExcelToHtmlUtils.loadXls( xlsFile );
- try {
- return ExcelToHtmlConverter.process( workbook );
- } finally {
- workbook.close();
+ public static Document process( File xlsFile ) throws IOException, ParserConfigurationException {
+ try (HSSFWorkbook workbook = ExcelToHtmlUtils.loadXls(xlsFile)) {
+ return ExcelToHtmlConverter.process(workbook);
}
}
@@ -127,16 +114,12 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
*
* @param xlsStream workbook stream to process
* @return DOM representation of result HTML
- * @throws IOException
- * @throws ParserConfigurationException
+ * @throws IOException If an error occurs reading or writing files
+ * @throws ParserConfigurationException If configuration is incorrect
*/
- public static Document process( InputStream xlsStream ) throws IOException, ParserConfigurationException
- {
- final HSSFWorkbook workbook = new HSSFWorkbook( xlsStream );
- try {
- return ExcelToHtmlConverter.process( workbook );
- } finally {
- workbook.close();
+ public static Document process( InputStream xlsStream ) throws IOException, ParserConfigurationException {
+ try (HSSFWorkbook workbook = new HSSFWorkbook(xlsStream)) {
+ return ExcelToHtmlConverter.process(workbook);
}
}
@@ -145,11 +128,10 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
*
* @param workbook workbook instance to process
* @return DOM representation of result HTML
- * @throws IOException
- * @throws ParserConfigurationException
+ * @throws IOException If an error occurs reading or writing files
+ * @throws ParserConfigurationException If configuration is incorrect
*/
- public static Document process( HSSFWorkbook workbook ) throws IOException, ParserConfigurationException
- {
+ public static Document process( HSSFWorkbook workbook ) throws IOException, ParserConfigurationException {
ExcelToHtmlConverter excelToHtmlConverter = new ExcelToHtmlConverter(
XMLHelper.getDocumentBuilderFactory().newDocumentBuilder()
.newDocument() );
@@ -180,13 +162,11 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
htmlDocumentFacade = new HtmlDocumentFacade( doc );
}
- public ExcelToHtmlConverter( HtmlDocumentFacade htmlDocumentFacade )
- {
+ public ExcelToHtmlConverter( HtmlDocumentFacade htmlDocumentFacade ) {
this.htmlDocumentFacade = htmlDocumentFacade;
}
- protected String buildStyle( HSSFWorkbook workbook, HSSFCellStyle cellStyle )
- {
+ protected String buildStyle( HSSFWorkbook workbook, HSSFCellStyle cellStyle ) {
StringBuilder style = new StringBuilder();
style.append( "white-space:pre-wrap;" );
@@ -199,13 +179,13 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
final HSSFColor foregroundColor = cellStyle.getFillForegroundColorColor();
if ( foregroundColor == null ) break;
String fgCol = ExcelToHtmlUtils.getColor( foregroundColor );
- style.append( "background-color:" + fgCol + ";" );
+ style.append("background-color:").append(fgCol).append(";");
break;
default:
final HSSFColor backgroundColor = cellStyle.getFillBackgroundColorColor();
if ( backgroundColor == null ) break;
String bgCol = ExcelToHtmlUtils.getColor( backgroundColor );
- style.append( "background-color:" + bgCol + ";" );
+ style.append("background-color:").append(bgCol).append(";");
break;
}
@@ -225,8 +205,7 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
}
private void buildStyle_border( HSSFWorkbook workbook, StringBuilder style,
- String type, BorderStyle xlsBorder, short borderColor )
- {
+ String type, BorderStyle xlsBorder, short borderColor ) {
if ( xlsBorder == BorderStyle.NONE ) {
return;
}
@@ -244,12 +223,11 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
borderStyle.append( ExcelToHtmlUtils.getColor( color ) );
}
- style.append( "border-" + type + ":" + borderStyle + ";" );
+ style.append("border-").append(type).append(":").append(borderStyle).append(";");
}
void buildStyle_font( HSSFWorkbook workbook, StringBuilder style,
- HSSFFont font )
- {
+ HSSFFont font ) {
if ( font.getBold() )
{
style.append( "font-weight:bold;" );
@@ -258,11 +236,10 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
final HSSFColor fontColor = workbook.getCustomPalette().getColor(
font.getColor() );
if ( fontColor != null )
- style.append( "color: " + ExcelToHtmlUtils.getColor( fontColor )
- + "; " );
+ style.append("color: ").append(ExcelToHtmlUtils.getColor(fontColor)).append("; ");
if ( font.getFontHeightInPoints() != 0 )
- style.append( "font-size:" + font.getFontHeightInPoints() + "pt;" );
+ style.append("font-size:").append(font.getFontHeightInPoints()).append("pt;");
if ( font.getItalic() )
{
@@ -296,8 +273,7 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
}
protected String getStyleClassName( HSSFWorkbook workbook,
- HSSFCellStyle cellStyle )
- {
+ HSSFCellStyle cellStyle ) {
final Short cellStyleKey = Short.valueOf( cellStyle.getIndex() );
String knownClass = excelStyleToClass.get( cellStyleKey );
@@ -317,20 +293,17 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
}
protected boolean processCell( HSSFCell cell, Element tableCellElement,
- int normalWidthPx, int maxSpannedWidthPx, float normalHeightPt )
- {
+ int normalWidthPx, int maxSpannedWidthPx, float normalHeightPt ) {
final HSSFCellStyle cellStyle = cell.getCellStyle();
String value;
- switch ( cell.getCellType() )
- {
+ switch ( cell.getCellType() ) {
case STRING:
// XXX: enrich
value = cell.getRichStringCellValue().getString();
break;
case FORMULA:
- switch ( cell.getCachedFormulaResultType() )
- {
+ switch ( cell.getCachedFormulaResultType() ) {
case STRING:
HSSFRichTextString str = cell.getRichStringCellValue();
if ( str != null && str.length() > 0 )
@@ -384,8 +357,7 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
final boolean noText = ExcelToHtmlUtils.isEmpty( value );
final boolean wrapInDivs = !noText && isUseDivsToSpan() && !cellStyle.getWrapText();
- if ( cellStyle.getIndex() != 0 )
- {
+ if ( cellStyle.getIndex() != 0 ) {
@SuppressWarnings("resource")
HSSFWorkbook workbook = cell.getRow().getSheet().getWorkbook();
String mainCssClass = getStyleClassName( workbook, cellStyle );
@@ -407,8 +379,7 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
}
}
- if ( isOutputLeadingSpacesAsNonBreaking() && value.startsWith( " " ) )
- {
+ if ( isOutputLeadingSpacesAsNonBreaking() && value.startsWith( " " ) ) {
StringBuilder builder = new StringBuilder();
for ( int c = 0; c < value.length(); c++ )
{
@@ -425,8 +396,7 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
Text text = htmlDocumentFacade.createText( value );
- if ( wrapInDivs )
- {
+ if ( wrapInDivs ) {
Element outerDiv = htmlDocumentFacade.createBlock();
outerDiv.setAttribute( "class", this.cssClassContainerDiv );
@@ -435,8 +405,7 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
innerDivStyle.append( "position:absolute;min-width:" );
innerDivStyle.append( normalWidthPx );
innerDivStyle.append( "px;" );
- if ( maxSpannedWidthPx != Integer.MAX_VALUE )
- {
+ if ( maxSpannedWidthPx != Integer.MAX_VALUE ) {
innerDivStyle.append( "max-width:" );
innerDivStyle.append( maxSpannedWidthPx );
innerDivStyle.append( "px;" );
@@ -451,9 +420,7 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
innerDiv.appendChild( text );
outerDiv.appendChild( innerDiv );
tableCellElement.appendChild( outerDiv );
- }
- else
- {
+ } else {
tableCellElement.appendChild( text );
}
@@ -461,21 +428,18 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
}
protected void processColumnHeaders( HSSFSheet sheet, int maxSheetColumns,
- Element table )
- {
+ Element table ) {
Element tableHeader = htmlDocumentFacade.createTableHeader();
table.appendChild( tableHeader );
Element tr = htmlDocumentFacade.createTableRow();
- if ( isOutputRowNumbers() )
- {
+ if ( isOutputRowNumbers() ) {
// empty row at left-top corner
tr.appendChild( htmlDocumentFacade.createTableHeaderCell() );
}
- for ( int c = 0; c < maxSheetColumns; c++ )
- {
+ for ( int c = 0; c < maxSheetColumns; c++ ) {
if ( !isOutputHiddenColumns() && sheet.isColumnHidden( c ) )
continue;
@@ -492,8 +456,7 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
* first if <tt>{@link #isOutputRowNumbers()}==true</tt>)
*/
protected void processColumnWidths( HSSFSheet sheet, int maxSheetColumns,
- Element table )
- {
+ Element table ) {
// draw COLS after we know max column number
Element columnGroup = htmlDocumentFacade.createTableColumnGroup();
if ( isOutputRowNumbers() )
@@ -513,9 +476,7 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
table.appendChild( columnGroup );
}
- protected void processDocumentInformation(
- SummaryInformation summaryInformation )
- {
+ protected void processDocumentInformation(SummaryInformation summaryInformation ) {
if ( ExcelToHtmlUtils.isNotEmpty( summaryInformation.getTitle() ) )
htmlDocumentFacade.setTitle( summaryInformation.getTitle() );
@@ -534,8 +495,7 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
* @return maximum 1-base index of column that were rendered, zero if none
*/
protected int processRow( CellRangeAddress[][] mergedRanges, HSSFRow row,
- Element tableRowElement )
- {
+ Element tableRowElement ) {
final HSSFSheet sheet = row.getSheet();
final short maxColIx = row.getLastCellNum();
if ( maxColIx <= 0 )
@@ -615,18 +575,13 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
emptyCell = processCell( cell, tableCellElement,
getColumnWidth( sheet, colIx ), divWidthPx,
row.getHeight() / 20f );
- }
- else
- {
+ } else {
emptyCell = true;
}
- if ( emptyCell )
- {
+ if ( emptyCell ) {
emptyCells.add( tableCellElement );
- }
- else
- {
+ } else {
for ( Element emptyCellElement : emptyCells )
{
tableRowElement.appendChild( emptyCellElement );
@@ -642,15 +597,13 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
}
protected void processRowNumber( HSSFRow row,
- Element tableRowNumberCellElement )
- {
+ Element tableRowNumberCellElement ) {
tableRowNumberCellElement.setAttribute( "class", "rownumber" );
Text text = htmlDocumentFacade.createText( getRowName( row ) );
tableRowNumberCellElement.appendChild( text );
}
- protected void processSheet( HSSFSheet sheet )
- {
+ protected void processSheet( HSSFSheet sheet ) {
processSheetHeader( htmlDocumentFacade.getBody(), sheet );
final int physicalNumberOfRows = sheet.getPhysicalNumberOfRows();
@@ -669,8 +622,7 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
final List<Element> emptyRowElements = new ArrayList<>(
physicalNumberOfRows);
int maxSheetColumns = 1;
- for ( int r = sheet.getFirstRowNum(); r <= sheet.getLastRowNum(); r++ )
- {
+ for ( int r = sheet.getFirstRowNum(); r <= sheet.getLastRowNum(); r++ ) {
HSSFRow row = sheet.getRow( r );
if ( row == null )
@@ -687,16 +639,11 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
int maxRowColumnNumber = processRow( mergedRanges, row,
tableRowElement );
- if ( maxRowColumnNumber == 0 )
- {
+ if ( maxRowColumnNumber == 0 ) {
emptyRowElements.add( tableRowElement );
- }
- else
- {
- if ( !emptyRowElements.isEmpty() )
- {
- for ( Element emptyRowElement : emptyRowElements )
- {
+ } else {
+ if ( !emptyRowElements.isEmpty() ) {
+ for ( Element emptyRowElement : emptyRowElements ) {
tableBody.appendChild( emptyRowElement );
}
emptyRowElements.clear();
@@ -709,8 +656,7 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
processColumnWidths( sheet, maxSheetColumns, table );
- if ( isOutputColumnHeaders() )
- {
+ if ( isOutputColumnHeaders() ) {
processColumnHeaders( sheet, maxSheetColumns, table );
}
@@ -719,24 +665,20 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
htmlDocumentFacade.getBody().appendChild( table );
}
- protected void processSheetHeader( Element htmlBody, HSSFSheet sheet )
- {
+ protected void processSheetHeader( Element htmlBody, HSSFSheet sheet ) {
Element h2 = htmlDocumentFacade.createHeader2();
h2.appendChild( htmlDocumentFacade.createText( sheet.getSheetName() ) );
htmlBody.appendChild( h2 );
}
- public void processWorkbook( HSSFWorkbook workbook )
- {
+ public void processWorkbook( HSSFWorkbook workbook ) {
final SummaryInformation summaryInformation = workbook
.getSummaryInformation();
- if ( summaryInformation != null )
- {
+ if ( summaryInformation != null ) {
processDocumentInformation( summaryInformation );
}
- if ( isUseDivsToSpan() )
- {
+ if ( isUseDivsToSpan() ) {
// prepare CSS classes for later usage
this.cssClassContainerCell = htmlDocumentFacade
.getOrCreateCssClass( cssClassPrefixCell,
@@ -745,8 +687,7 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
cssClassPrefixDiv, "position:relative;" );
}
- for ( int s = 0; s < workbook.getNumberOfSheets(); s++ )
- {
+ for ( int s = 0; s < workbook.getNumberOfSheets(); s++ ) {
HSSFSheet sheet = workbook.getSheetAt( s );
processSheet( sheet );
}
diff --git a/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlUtils.java b/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlUtils.java
index fbc20e1e09..651d1f0dda 100644
--- a/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlUtils.java
+++ b/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlUtils.java
@@ -18,16 +18,14 @@ package org.apache.poi.hssf.converter;
import java.util.Arrays;
-import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
+import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.Beta;
@Beta
-public class ExcelToHtmlUtils extends AbstractExcelUtils
-{
- public static void appendAlign( StringBuilder style, HorizontalAlignment alignment )
- {
+public class ExcelToHtmlUtils extends AbstractExcelUtils {
+ public static void appendAlign( StringBuilder style, HorizontalAlignment alignment ) {
String cssAlign = getAlign( alignment );
if ( isEmpty( cssAlign ) )
return;
@@ -44,14 +42,11 @@ public class ExcelToHtmlUtils extends AbstractExcelUtils
*
* @see #getMergedRange(CellRangeAddress[][], int, int)
*/
- public static CellRangeAddress[][] buildMergedRangesMap( HSSFSheet sheet )
- {
+ public static CellRangeAddress[][] buildMergedRangesMap( Sheet sheet ) {
CellRangeAddress[][] mergedRanges = new CellRangeAddress[1][];
- for ( final CellRangeAddress cellRangeAddress : sheet.getMergedRegions() )
- {
+ for ( final CellRangeAddress cellRangeAddress : sheet.getMergedRegions() ) {
final int requiredHeight = cellRangeAddress.getLastRow() + 1;
- if ( mergedRanges.length < requiredHeight )
- {
+ if ( mergedRanges.length < requiredHeight ) {
CellRangeAddress[][] newArray = new CellRangeAddress[requiredHeight][];
System.arraycopy( mergedRanges, 0, newArray, 0,
mergedRanges.length );
@@ -59,18 +54,14 @@ public class ExcelToHtmlUtils extends AbstractExcelUtils
}
for ( int r = cellRangeAddress.getFirstRow(); r <= cellRangeAddress
- .getLastRow(); r++ )
- {
+ .getLastRow(); r++ ) {
final int requiredWidth = cellRangeAddress.getLastColumn() + 1;
CellRangeAddress[] rowMerged = mergedRanges[r];
- if ( rowMerged == null )
- {
+ if ( rowMerged == null ) {
rowMerged = new CellRangeAddress[requiredWidth];
mergedRanges[r] = rowMerged;
- }
- else
- {
+ } else {
final int rowMergedLength = rowMerged.length;
if ( rowMergedLength < requiredWidth )
{
@@ -89,5 +80,4 @@ public class ExcelToHtmlUtils extends AbstractExcelUtils
}
return mergedRanges;
}
-
}