From 71ce2d99c325c48c1242c6b42b077d1a4eaca024 Mon Sep 17 00:00:00 2001 From: Thomas Gutmann <41593722+speckyspooky@users.noreply.github.com> Date: Tue, 7 May 2024 12:51:33 +0200 Subject: [PATCH] Enhance the excel output to get the formatting option of text-indent (#1667) * Enhance the excel output to get the formatting option of text indent (#1666) * Add a new option to define the indent mode for the internal calculation --- .../birt/emitters/excel/BirtStyle.java | 41 ++++++ .../excel/ClientAnchorConversions.java | 18 ++- .../birt/emitters/excel/ExcelEmitter.java | 15 +++ .../co/spudsoft/birt/emitters/excel/README.md | 69 +++++++--- .../birt/emitters/excel/StyleManager.java | 42 +++++- .../emitters/excel/StyleManagerUtils.java | 46 +++++++ .../excel/handlers/CellContentHandler.java | 127 +++++++++++++++++- 7 files changed, 333 insertions(+), 25 deletions(-) diff --git a/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/BirtStyle.java b/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/BirtStyle.java index 23f4ccf811..529720439c 100644 --- a/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/BirtStyle.java +++ b/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/BirtStyle.java @@ -66,6 +66,8 @@ public class BirtStyle { private IStyle elemStyle; private CSSValue[] propertyOverride = new CSSValue[BirtStyle.NUMBER_OF_STYLES]; private CSSEngine cssEngine; + private boolean useTextIndent = true; + private String textIndentMode = ""; /** * Constructor 01 @@ -219,6 +221,10 @@ protected BirtStyle clone() { private static BitSet PrepareSpecialOverlayProperties() { BitSet result = new BitSet(BirtStyle.NUMBER_OF_STYLES); + result.set(StyleConstants.STYLE_MARGIN_LEFT); + result.set(StyleConstants.STYLE_MARGIN_RIGHT); + result.set(StyleConstants.STYLE_PADDING_LEFT); + result.set(StyleConstants.STYLE_PADDING_RIGHT); result.set(StyleConstants.STYLE_BACKGROUND_COLOR); result.set(StyleConstants.STYLE_BORDER_BOTTOM_STYLE); result.set(StyleConstants.STYLE_BORDER_BOTTOM_WIDTH); @@ -337,4 +343,39 @@ public String toString() { return result.toString(); } + /** + * Set the flag if the text indent is in use + * + * @param useTextIndent flag to define is the text indent is in use + */ + public void setTextIndentInUse(boolean useTextIndent) { + this.useTextIndent = useTextIndent; + } + + /** + * Get the result if the text indent is in use + * + * @return Return true if the text indent is in use + */ + public boolean isTextIndentInUse() { + return this.useTextIndent; + } + + /** + * Set the text indent mode + * + * @param textIndentMode type of the text indent mode + */ + public void setTextIndentMode(String textIndentMode) { + this.textIndentMode = textIndentMode; + } + + /** + * Get the text indent mode + * + * @return Return the text indent mode + */ + public String getTextIndentMode() { + return this.textIndentMode; + } } diff --git a/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/ClientAnchorConversions.java b/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/ClientAnchorConversions.java index 583cad4a93..8126a01d04 100644 --- a/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/ClientAnchorConversions.java +++ b/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/ClientAnchorConversions.java @@ -2,13 +2,13 @@ * Copyright (c) 2011, 2012, 2013 James Talbut. * jim-emitters@spudsoft.co.uk * - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * https://www.eclipse.org/legal/epl-2.0/. - * + * * SPDX-License-Identifier: EPL-2.0 - * + * * Contributors: * James Talbut - Initial implementation. ************************************************************************************/ @@ -40,6 +40,7 @@ public class ClientAnchorConversions { private static final short EXCEL_COLUMN_WIDTH_FACTOR = 256; private static final int UNIT_OFFSET_LENGTH = 7; private static final int[] UNIT_OFFSET_MAP = { 0, 36, 73, 109, 146, 182, 219 }; + private static final double MILLIMETRE_INDENT_FACTOR = 2.38; /** * Convert a measure in column width units (1/256th of a character) to a measure @@ -69,6 +70,17 @@ public static int millimetres2WidthUnits(double millimetres) { return widthUnits; } + /** + * Convert a measure of millimetres to indent units. + * + * @param millimetres The size in millimetres. + * @return The size in indent units. + */ + public static int millimetres2IndentUnits(double millimetres) { + int indentUnits = (int) Math.round(millimetres / MILLIMETRE_INDENT_FACTOR); + return indentUnits; + } + /** * Convert a measure of pixels to millimetres (for column widths). * diff --git a/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/ExcelEmitter.java b/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/ExcelEmitter.java index 3ae0be9b9f..7b357e8f98 100644 --- a/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/ExcelEmitter.java +++ b/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/ExcelEmitter.java @@ -172,6 +172,12 @@ public abstract class ExcelEmitter implements IContentEmitter { /** property: ExcelEmitter.PagePreview */ public static final String PAGE_PREVIEW = "ExcelEmitter.PagePreview"; + /** property: ExcelEmitter.DisplayTextIndent */ + public static final String DISPLAY_TEXT_INDENT = "ExcelEmitter.DisplayTextIndent"; + + /** property: ExcelEmitter.TextIndentMode */ + public static final String TEXT_INDENT_MODE = "ExcelEmitter.TextIndentMode"; + /** property: minimum zoom value of excel sheet */ public static final short poiExcelDisplaySheetZoomScaleMin = 10; @@ -190,6 +196,15 @@ public abstract class ExcelEmitter implements IContentEmitter { /** property: minimum zoom value of excel sheet */ public static final String poiExcelPreviewPageBreak = "PageBreak"; + /** property: text indent mode, spacing based on cell */ + public static final String TEXT_INDENT_MODE_SPACING_CELL = "SpacingCell"; + + /** property: text indent mode, spacing based on element */ + public static final String TEXT_INDENT_MODE_SPACING_ELEMENT = "SpacingElement"; + + /** property: text indent mode, spacing based on cell & element */ + public static final String TEXT_INDENT_MODE_SPACING_ALL = "SpacingAll"; + /** * Logger. */ diff --git a/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/README.md b/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/README.md index f8c7d4e4bd..164ba1c3c6 100644 --- a/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/README.md +++ b/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/README.md @@ -222,23 +222,6 @@ The following list get an overview of all supported user properties, the content false, hide cell value of zero Default true -**ExcelEmitter.ValueAsFormula** - - Content the content on an element will be added as excel-formula, for calculation teh string must be start with "="-sign - Location text-element of cell - Data type boolean - Values true, use content like formula - false, use content like text - Default false - -**ExcelEmitter.Formula** - - Content the content of this property will be added as excel-formula, for calculation teh string must be start with "="-sign - Location text-element of cell - Data type string - Values fixed text or formula for excel cell - Default empty (null) - **ExcelEmitter.TemplateFile** Content define an excel-template to create the excel @@ -255,6 +238,26 @@ The following list get an overview of all supported user properties, the content Values true, activate the streaming output method false, standard output handling based on DOM will be used Default false + Since 4.13 + +**ExcelEmitter.ValueAsFormula** + + Content the content on an element will be added as excel-formula, for calculation the string must be start with "="-sign + Location text-element of cell + Data type boolean + Values true, use content like formula + false, use content like text + Default false + Since 4.16 + +**ExcelEmitter.Formula** + + Content the content of this property will be added as excel-formula, for calculation the string must be start with "="-sign + Location text-element of cell + Data type string + Values fixed text or formula for excel cell + Default empty (null) + Since 4.16 **ExcelEmitter.ForceRecalculation** @@ -264,6 +267,7 @@ The following list get an overview of all supported user properties, the content Values true, activate the recalculation option false, no recalculation Default false + Since 4.16 **ExcelEmitter.PrintGridlines** @@ -273,6 +277,7 @@ The following list get an overview of all supported user properties, the content Values true, activate grid line print out false, without grid line print out Default false + Since 4.16 **ExcelEmitter.PrintRowColHeadings** @@ -282,7 +287,8 @@ The following list get an overview of all supported user properties, the content Values true, activate print out of the row and column heading labels false, without print out of the row and column heading labels Default false - + Since 4.16 + **ExcelEmitter.PrintFitToPage** Content the page will be fit to center of the print out @@ -291,6 +297,7 @@ The following list get an overview of all supported user properties, the content Values true, fit the page to center false, no fitting of the page Default false + Since 4.16 **ExcelEmitter.DisplaySheetZoom** @@ -299,6 +306,7 @@ The following list get an overview of all supported user properties, the content Data type number, integer Values the zoom value must be -1 (= off) or between 10 and 400 Default -1 + Since 4.16 **ExcelEmitter.PagePreview** @@ -308,3 +316,28 @@ The following list get an overview of all supported user properties, the content Values PageLayout, display the page layout preview PageBreak, display the page break preview Default Normal + Since 4.16 + +**ExcelEmitter.DisplayTextIndent** + + Content define if the text-indent will be used based on the margin & padding of the text-element, the indent is dependent at the text-alignment: + - alignment left: use the left-margin and left-padding + - alignment right: use the right-margin and right-padding + Location report, table, grid, list, row, text-element + Data type boolean + Values true, text-indent will be used + false, avoid the usage of the text indent + Default true + Since 4.16 + + +**ExcelEmitter.TextIndentMode** + + Content define the indent calculation mode and with it the element spacing which will be used + Location report, table, grid, list, row, text-element + Data type string + Values SpacingCell, indent calculated based on cell padding + SpacingElement, indent calculated based on element padding & margin + SpacingAll, indent calculated based on cell padding & element padding & margin + Default SpacingAll + Since 4.16 diff --git a/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/StyleManager.java b/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/StyleManager.java index db7a113444..ca0d28f40f 100644 --- a/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/StyleManager.java +++ b/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/StyleManager.java @@ -31,6 +31,7 @@ import org.eclipse.birt.report.engine.css.engine.value.DataFormatValue; import org.eclipse.birt.report.engine.css.engine.value.FloatValue; import org.eclipse.birt.report.engine.css.engine.value.css.CSSConstants; +import org.eclipse.birt.report.engine.ir.DimensionType; import org.w3c.dom.css.CSSValue; import uk.co.spudsoft.birt.emitters.excel.framework.Logger; @@ -114,7 +115,8 @@ public CSSEngine getCssEngine() { StyleConstants.STYLE_BORDER_DIAGONAL_WIDTH, StyleConstants.STYLE_BORDER_DIAGONAL_COLOR, StyleConstants.STYLE_BORDER_ANTIDIAGONAL_NUMBER, StyleConstants.STYLE_BORDER_ANTIDIAGONAL_STYLE, StyleConstants.STYLE_BORDER_ANTIDIAGONAL_WIDTH, StyleConstants.STYLE_BORDER_ANTIDIAGONAL_COLOR, - StyleConstants.STYLE_WHITE_SPACE, StyleConstants.STYLE_VERTICAL_ALIGN, }; + StyleConstants.STYLE_WHITE_SPACE, StyleConstants.STYLE_VERTICAL_ALIGN, StyleConstants.STYLE_MARGIN_LEFT, + StyleConstants.STYLE_MARGIN_RIGHT, StyleConstants.STYLE_PADDING_LEFT, StyleConstants.STYLE_PADDING_RIGHT, }; /** * Test whether two BIRT styles are equivalent, as far as the attributes @@ -146,9 +148,11 @@ private boolean stylesEquivalent(BirtStyle style1, BirtStyle style2) { // Number format // Font if (!StyleManagerUtils.objectsEqual(style1.getProperty(BirtStyle.TEXT_ROTATION), - style2.getProperty(BirtStyle.TEXT_ROTATION)) || !StyleManagerUtils.dataFormatsEquivalent( + style2.getProperty(BirtStyle.TEXT_ROTATION)) + || !StyleManagerUtils.dataFormatsEquivalent( (DataFormatValue) style1.getProperty(StyleConstants.STYLE_DATA_FORMAT), - (DataFormatValue) style2.getProperty(StyleConstants.STYLE_DATA_FORMAT)) || !FontManager.fontsEquivalent(style1, style2)) { + (DataFormatValue) style2.getProperty(StyleConstants.STYLE_DATA_FORMAT)) + || !FontManager.fontsEquivalent(style1, style2)) { // System.out.println( "Differ on font" ); return false; } @@ -177,6 +181,38 @@ private CellStyle createStyle(BirtStyle birtStyle) { // Background colour smu.addBackgroundColourToStyle(workbook, poiStyle, birtStyle.getString(StyleConstants.STYLE_BACKGROUND_COLOR)); + // Indent, based on the text margin & padding + // excel supports for indent the text-align LEFT / RIGHT + if (birtStyle.isTextIndentInUse() && alignment != null + && !(alignment.equals(HorizontalAlignment.CENTER) + || alignment.equals(HorizontalAlignment.CENTER_SELECTION))) { + short indent = 0; + CSSValue marginCSSValue; + CSSValue paddingCSSValue; + String marginCSS = ""; + String paddingCSS = ""; + if (alignment.equals(HorizontalAlignment.RIGHT)) { + marginCSSValue = birtStyle.getProperty(StyleConstants.STYLE_MARGIN_RIGHT); + paddingCSSValue = birtStyle.getProperty(StyleConstants.STYLE_PADDING_RIGHT); + } else { + marginCSSValue = birtStyle.getProperty(StyleConstants.STYLE_MARGIN_LEFT); + paddingCSSValue = birtStyle.getProperty(StyleConstants.STYLE_PADDING_LEFT); + } + marginCSS = (marginCSSValue != null) ? marginCSSValue.getCssText() : "0"; + paddingCSS = (paddingCSSValue != null) ? paddingCSSValue.getCssText() : "0"; + double marginIndent = smu.convertDimensionToMillimetres(DimensionType.parserUnit(marginCSS)); + double paddingIndent = smu.convertDimensionToMillimetres(DimensionType.parserUnit(paddingCSS)); + int tmpIndent = smu.poiIndentUnit(new DimensionType(marginIndent + paddingIndent, DimensionType.UNITS_MM)); + if (tmpIndent < 0) { + indent = 0; + } else if (tmpIndent > Short.MAX_VALUE) { + indent = Short.MAX_VALUE; + } else { + indent = (short) tmpIndent; + } + poiStyle.setIndention(indent); + } + if (smu instanceof StyleManagerXUtils) { // border will be applied at once diff --git a/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/StyleManagerUtils.java b/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/StyleManagerUtils.java index fa240dfd03..ec8de0c08c 100644 --- a/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/StyleManagerUtils.java +++ b/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/StyleManagerUtils.java @@ -230,6 +230,52 @@ public int poiColumnWidthFromDimension(DimensionType dim) { return 0; } + /** + * Calculation of millimetres based on dimension + * + * @param dim The BIRT dimension, which must be in absolute units. + * @return The calculated millimetres unit + */ + public double convertDimensionToMillimetres(DimensionType dim) { + if (dim != null) { + double mmWidth = dim.getMeasure(); + if ((DimensionType.UNITS_CM.equals(dim.getUnits())) || (DimensionType.UNITS_IN.equals(dim.getUnits())) + || (DimensionType.UNITS_PT.equals(dim.getUnits())) + || (DimensionType.UNITS_PC.equals(dim.getUnits()))) { + mmWidth = dim.convertTo("mm"); + } else if ((DimensionType.UNITS_PX.equals(dim.getUnits()))) { + mmWidth = ClientAnchorConversions.pixels2Millimetres(mmWidth); + } + return mmWidth; + } + return 0; + } + + /** + * Converting from millimetres to indent width + * + * @param mmWidth The BIRT millimetres + * @return The calculated indent with unit + */ + public int poiIndentUnit(double mmWidth) { + return ClientAnchorConversions.millimetres2IndentUnits(mmWidth); + } + + /** + * Converting from millimetres to indent width + * + * @param dim The BIRT dimension millimetres + * @return The calculated indent with unit + */ + public int poiIndentUnit(DimensionType dim) { + if (dim != null) { + double mmWidth = dim.getMeasure(); + if (DimensionType.UNITS_MM.equals(dim.getUnits())) { + return ClientAnchorConversions.millimetres2IndentUnits(mmWidth); + } + } + return 0; + } /** * Object a POI font weight from a BIRT string. * diff --git a/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/handlers/CellContentHandler.java b/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/handlers/CellContentHandler.java index 3137225400..4383bc8f72 100644 --- a/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/handlers/CellContentHandler.java +++ b/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/handlers/CellContentHandler.java @@ -43,8 +43,10 @@ import org.eclipse.birt.report.engine.api.impl.Action; import org.eclipse.birt.report.engine.content.ICellContent; import org.eclipse.birt.report.engine.content.IContent; +import org.eclipse.birt.report.engine.content.IForeignContent; import org.eclipse.birt.report.engine.content.IHyperlinkAction; import org.eclipse.birt.report.engine.content.IImageContent; +import org.eclipse.birt.report.engine.content.IStyle; import org.eclipse.birt.report.engine.css.engine.StyleConstants; import org.eclipse.birt.report.engine.css.engine.value.StringValue; import org.eclipse.birt.report.engine.css.engine.value.css.CSSConstants; @@ -139,6 +141,8 @@ public class CellContentHandler extends AbstractHandler { private static final String URL_PROTOCOL_TYPE_DATA_UTF8 = ";utf8,"; private static final String URL_PROTOCOL_URL_ENCODED_SPACE = "%20"; + private static final String STYLE_OVERLAY_DEFAULT_UNIT = "mm"; + /** * Constructor * @@ -170,8 +174,9 @@ public void startCell(HandlerState state, ICellContent cell) throws BirtExceptio protected void endCellContent(HandlerState state, ICellContent birtCell, IContent element, Cell cell, Area area) { StyleManager sm = state.getSm(); StyleManagerUtils smu = state.getSmu(); - BirtStyle birtCellStyle = null; + boolean isStyleExactCopy = false; + if (birtCell != null) { birtCellStyle = new BirtStyle(birtCell); if (element != null) { @@ -180,6 +185,7 @@ protected void endCellContent(HandlerState state, ICellContent birtCell, IConten } } else if (element != null) { birtCellStyle = new BirtStyle(element); + isStyleExactCopy = true; } else { birtCellStyle = new BirtStyle(state.getSm().getCssEngine()); } @@ -191,6 +197,10 @@ protected void endCellContent(HandlerState state, ICellContent birtCell, IConten birtCellStyle.setProperty(StyleConstants.STYLE_BACKGROUND_COLOR, parent.getBackgroundColour()); } } + birtCellStyle.setTextIndentInUse(EmitterServices.booleanOption(state.getRenderOptions(), element, + ExcelEmitter.DISPLAY_TEXT_INDENT, true)); + birtCellStyle.setTextIndentMode(EmitterServices.stringOption(state.getRenderOptions(), element, + ExcelEmitter.TEXT_INDENT_MODE, ExcelEmitter.TEXT_INDENT_MODE_SPACING_ALL)); if (hyperlinkUrl != null) { Hyperlink hyperlink = cell.getSheet().getWorkbook().getCreationHelper() @@ -320,6 +330,8 @@ protected void endCellContent(HandlerState state, ICellContent birtCell, IConten StyleManagerUtils.setNumberFormat(birtCellStyle, ExcelEmitter.CUSTOM_NUMBER_FORMAT + customNumberFormat, null); } + + overlayBirtCellStyleSpacing(smu, birtCellStyle, element, isStyleExactCopy); setCellStyle(sm, cell, birtCellStyle, lastValue); } @@ -372,6 +384,119 @@ protected void endCellContent(HandlerState state, ICellContent birtCell, IConten richTextRuns.clear(); } + /* + * Overlay to set the margin and padding spacing for the BirtStyle of the excel + * cell + */ + private BirtStyle overlayBirtCellStyleSpacing(StyleManagerUtils smu, BirtStyle birtCellStyle, IContent element, + boolean isStyleExactCopy) { + + // Overlay of spacing + if (element != null && element.getStyle() != null) { + IStyle elemStyle = element.getStyle(); + IContent fc = null; + double paddingLeftValueElementContent = 0.0; + double paddingRightValueElementContent = 0.0; + + // Computed style: values of html-typed elements won't be inherited + // Foreign content: original container of the html-elements + try { + fc = (IContent) element.getParent().getParent(); + } catch (Exception e) { + /* do nothing */ + } + if (fc != null && fc instanceof IForeignContent && fc.getStyle() != null) { + elemStyle = fc.getStyle(); + } + + // Padding calculation: cell content and element content + + // Avoid the element usage if the birtCellStyle is a copy of the element + if (!isStyleExactCopy) { + + // Element content: padding left/right of the cell + String paddingLeftElementContent = (elemStyle.getProperty(StyleConstants.STYLE_PADDING_LEFT) != null) + ? elemStyle.getProperty(StyleConstants.STYLE_PADDING_LEFT).getCssText() + : ("0" + STYLE_OVERLAY_DEFAULT_UNIT); + String paddingRightElementContent = (elemStyle.getProperty(StyleConstants.STYLE_PADDING_RIGHT) != null) + ? elemStyle.getProperty(StyleConstants.STYLE_PADDING_RIGHT).getCssText() + : ("0" + STYLE_OVERLAY_DEFAULT_UNIT); + + // Element padding values + paddingLeftValueElementContent = smu + .convertDimensionToMillimetres(DimensionType.parserUnit(paddingLeftElementContent)); + paddingRightValueElementContent = smu + .convertDimensionToMillimetres(DimensionType.parserUnit(paddingRightElementContent)); + } + // Element content: margin left/right of the element + CSSValue marginLeftElementContent = elemStyle.getProperty(StyleConstants.STYLE_MARGIN_LEFT); + CSSValue marginRightElementContent = elemStyle.getProperty(StyleConstants.STYLE_MARGIN_RIGHT); + + // Calculation the sum of the cell & element padding + + // Cell content: padding left/right of the cell + String paddingLeftCellContent = (birtCellStyle.getProperty(StyleConstants.STYLE_PADDING_LEFT) != null) + ? birtCellStyle.getProperty(StyleConstants.STYLE_PADDING_LEFT).getCssText() + : ("0" + STYLE_OVERLAY_DEFAULT_UNIT); + String paddingRightCellContent = (birtCellStyle.getProperty(StyleConstants.STYLE_PADDING_RIGHT) != null) + ? birtCellStyle.getProperty(StyleConstants.STYLE_PADDING_RIGHT).getCssText() + : ("0" + STYLE_OVERLAY_DEFAULT_UNIT); + + // Cell padding values + double paddingLeftValueCellContent = smu.convertDimensionToMillimetres(DimensionType + .parserUnit(paddingLeftCellContent)); + double paddingRightValueCellContent = smu.convertDimensionToMillimetres(DimensionType + .parserUnit(paddingRightCellContent)); + + // Validation of the text indent mode + if (birtCellStyle.getTextIndentMode().equals(ExcelEmitter.TEXT_INDENT_MODE_SPACING_CELL)) { + + // use cell padding to calculate the indent (reset element spacing) + marginLeftElementContent = new StringValue(CSSPrimitiveValue.CSS_STRING, + "0" + STYLE_OVERLAY_DEFAULT_UNIT); + marginRightElementContent = new StringValue(CSSPrimitiveValue.CSS_STRING, + "0" + STYLE_OVERLAY_DEFAULT_UNIT); + + paddingLeftValueElementContent = 0.0; + paddingRightValueElementContent = 0.0; + + } else if (birtCellStyle.getTextIndentMode().equals(ExcelEmitter.TEXT_INDENT_MODE_SPACING_ELEMENT)) { + // use element padding & margin to calculate the indent (reset cell spacing) + paddingLeftValueCellContent = 0.0; + paddingRightValueCellContent = 0.0; + + } else { + // use cell padding & element padding & element margin to calculate the indent + } + + // Sum of padding values rounded based on 4 decimals + double paddingLeftValueNew = Math + .round((paddingLeftValueElementContent + paddingLeftValueCellContent) * 1000.0) / 1000.0; + double paddingRightValueNew = Math + .round((paddingRightValueElementContent + paddingRightValueCellContent) * 1000.0) / 1000.0; + + // Set the margin and padding for the finalized cell style + birtCellStyle.setProperty(StyleConstants.STYLE_MARGIN_LEFT, marginLeftElementContent); + birtCellStyle.setProperty(StyleConstants.STYLE_MARGIN_RIGHT, marginRightElementContent); + birtCellStyle.setProperty(StyleConstants.STYLE_PADDING_LEFT, + new StringValue(CSSPrimitiveValue.CSS_STRING, paddingLeftValueNew + STYLE_OVERLAY_DEFAULT_UNIT)); + birtCellStyle.setProperty(StyleConstants.STYLE_PADDING_RIGHT, + new StringValue(CSSPrimitiveValue.CSS_STRING, paddingRightValueNew + STYLE_OVERLAY_DEFAULT_UNIT)); + + // Override based on the original color content values + if (elemStyle.getProperty(StyleConstants.STYLE_BACKGROUND_COLOR) != null) { + birtCellStyle.setProperty(StyleConstants.STYLE_BACKGROUND_COLOR, + elemStyle.getProperty(StyleConstants.STYLE_BACKGROUND_COLOR)); + } + if (elemStyle.getProperty(StyleConstants.STYLE_COLOR) != null) { + birtCellStyle.setProperty(StyleConstants.STYLE_COLOR, + elemStyle.getProperty(StyleConstants.STYLE_COLOR)); + } + } + + return birtCellStyle; + } + /** * Calculate the width of a set of columns, in millimetres. *