From c628362e35d980d25e2eb982f1859dc48887e484 Mon Sep 17 00:00:00 2001 From: Sergey Vladimirov Date: Mon, 18 Jul 2011 12:25:10 +0000 Subject: [PATCH] fix table and table's cells css processing git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1147828 13f79535-47bb-0310-9956-ffa450edef68 --- .../hssf/converter/ExcelToHtmlConverter.java | 11 ++++++++--- .../poi/hssf/converter/ExcelToHtmlUtils.java | 19 +++++++++++++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) 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 375273d886..751cb30aa5 100644 --- a/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java +++ b/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java @@ -219,9 +219,9 @@ public class ExcelToHtmlConverter return; StringBuilder borderStyle = new StringBuilder(); - borderStyle.append( ExcelToHtmlUtils.getBorderStyle( xlsBorder ) ); - borderStyle.append( ' ' ); borderStyle.append( ExcelToHtmlUtils.getBorderWidth( xlsBorder ) ); + borderStyle.append( ' ' ); + borderStyle.append( ExcelToHtmlUtils.getBorderStyle( xlsBorder ) ); final HSSFColor color = workbook.getCustomPalette().getColor( borderColor ); @@ -231,7 +231,7 @@ public class ExcelToHtmlConverter borderStyle.append( ExcelToHtmlUtils.getColor( color ) ); } - style.append( type + "-border: " + borderStyle + "; " ); + style.append( "border-" + type + ": " + borderStyle + "; " ); } void buildStyle_font( HSSFWorkbook workbook, StringBuilder style, @@ -574,6 +574,8 @@ public class ExcelToHtmlConverter return; Element table = htmlDocumentFacade.createTable(); + table.setAttribute( "class", "t" ); + Element tableBody = htmlDocumentFacade.createTableBody(); final List emptyRowElements = new ArrayList( @@ -648,6 +650,9 @@ public class ExcelToHtmlConverter processSheet( workbook, sheet ); } + stylesElement + .appendChild( htmlDocumentFacade + .createText( "table.t{border-collapse:collapse;border-spacing:0;}\n" ) ); if ( !cssStyleToClass.isEmpty() ) { for ( Map.Entry entry : cssStyleToClass.entrySet() ) 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 0131b6f30f..4d64e5fcfe 100644 --- a/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlUtils.java +++ b/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlUtils.java @@ -85,7 +85,8 @@ public class ExcelToHtmlUtils public static String getColor( HSSFColor color ) { - StringBuilder stringBuilder = new StringBuilder(); + StringBuilder stringBuilder = new StringBuilder( 7 ); + stringBuilder.append( '#' ); for ( short s : color.getTriplet() ) { if ( s < 10 ) @@ -93,7 +94,21 @@ public class ExcelToHtmlUtils stringBuilder.append( Integer.toHexString( s ) ); } - return stringBuilder.toString(); + String result = stringBuilder.toString(); + + if ( result.equals( "#ffffff" ) ) + return "white"; + + if ( result.equals( "#c0c0c0" ) ) + return "silver"; + + if ( result.equals( "#808080" ) ) + return "gray"; + + if ( result.equals( "#000000" ) ) + return "black"; + + return result; } /** -- 2.39.5