]> source.dussan.org Git - poi.git/commitdiff
preserve align in case of "divved" cells
authorSergey Vladimirov <sergey@apache.org>
Mon, 18 Jul 2011 15:55:52 +0000 (15:55 +0000)
committerSergey Vladimirov <sergey@apache.org>
Mon, 18 Jul 2011 15:55:52 +0000 (15:55 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1147941 13f79535-47bb-0310-9956-ffa450edef68

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

index 8b0780aab7ca09a408c78f3c68c3e49370066db6..d3aadf34cbce3e7864c3974f75675ed742c962d6 100644 (file)
@@ -161,30 +161,7 @@ public class ExcelToHtmlConverter
         StringBuilder style = new StringBuilder();
 
         style.append( "white-space: pre-wrap; " );
-
-        switch ( cellStyle.getAlignment() )
-        {
-        case HSSFCellStyle.ALIGN_CENTER:
-            style.append( "text-align: center; " );
-            break;
-        case HSSFCellStyle.ALIGN_CENTER_SELECTION:
-            style.append( "text-align: center; " );
-            break;
-        case HSSFCellStyle.ALIGN_FILL:
-            // XXX: shall we support fill?
-            break;
-        case HSSFCellStyle.ALIGN_GENERAL:
-            break;
-        case HSSFCellStyle.ALIGN_JUSTIFY:
-            style.append( "text-align: justify; " );
-            break;
-        case HSSFCellStyle.ALIGN_LEFT:
-            style.append( "text-align: left; " );
-            break;
-        case HSSFCellStyle.ALIGN_RIGHT:
-            style.append( "text-align: right; " );
-            break;
-        }
+        ExcelToHtmlUtils.appendAlign( style, cellStyle.getAlignment() );
 
         if ( cellStyle.getFillPattern() == 0 )
         {
@@ -486,12 +463,13 @@ public class ExcelToHtmlConverter
             return true;
         }
 
+        boolean noText = ExcelToHtmlUtils.isEmpty( value );
         final short cellStyleIndex = cellStyle.getIndex();
         if ( cellStyleIndex != 0 )
         {
             tableCellElement.setAttribute( "class",
                     getStyleClassName( workbook, cellStyle ) );
-            if ( ExcelToHtmlUtils.isEmpty( value ) )
+            if ( noText )
             {
                 /*
                  * if cell style is defined (like borders, etc.) but cell text
@@ -520,7 +498,7 @@ public class ExcelToHtmlConverter
 
         Text text = htmlDocumentFacade.createText( value );
 
-        if ( isUseDivsToSpan() )
+        if ( !noText && isUseDivsToSpan() )
         {
             tableCellElement.setAttribute( "style",
                     "padding:0;margin:0;align:left;vertical-align:top;" );
@@ -530,13 +508,22 @@ public class ExcelToHtmlConverter
 
             Element innerDiv = htmlDocumentFacade.getDocument().createElement(
                     "div" );
-            innerDiv.setAttribute( "style", "position:absolute;min-width:"
-                    + normalWidthPx
-                    + "px;"
-                    + ( maxSpannedWidthPx != Integer.MAX_VALUE ? "max-width:"
-                            + maxSpannedWidthPx + "px;" : "" )
-                    + "overflow:hidden;max-height:" + normalHeightPt
-                    + "pt;white-space:nowrap;" );
+            StringBuilder innerDivStyle = new StringBuilder();
+            innerDivStyle.append( "position:absolute;min-width:" );
+            innerDivStyle.append( normalWidthPx );
+            innerDivStyle.append( "px;" );
+            if ( maxSpannedWidthPx != Integer.MAX_VALUE )
+            {
+                innerDivStyle.append( "max-width:" );
+                innerDivStyle.append( maxSpannedWidthPx );
+                innerDivStyle.append( "px;" );
+            }
+            innerDivStyle.append( "overflow:hidden;max-height:" );
+            innerDivStyle.append( normalHeightPt );
+            innerDivStyle.append( "pt;white-space:nowrap;" );
+            ExcelToHtmlUtils.appendAlign( innerDivStyle,
+                    cellStyle.getAlignment() );
+            innerDiv.setAttribute( "style", innerDivStyle.toString() );
 
             innerDiv.appendChild( text );
             outerDiv.appendChild( innerDiv );