// 1. containing row
// 2. optional containing table section (header, footer or body)
// 3. (great) containing table
// 4. original cell
StylesMerger merger = stylingFactory.getStylesMerger();
Styles cellStyles = cell.getStyles();
Styles mergedStyles;
String[] attributes = getPreserveStyleAttributes();
Element row = cell.getParent();
Element tableSection = row.getParent();
// 1. containing row
preserveStyleAttributes(cell, row, attributes);
mergedStyles = merger.merge(cellStyles, row.getStyles());
if (tableSection != table) {
// 2. optional containing table section
preserveStyleAttributes(cell, tableSection, attributes);
mergedStyles = merger.merge(mergedStyles, tableSection.getStyles());
}
// 3. containing table
preserveStyleAttributes(cell, table, attributes);
mergedStyles = merger.merge(mergedStyles, table.getStyles());
// 4. original cell
preserveStyleAttributes(cell, originalCell, attributes);
if (firstRow) {
mergeSizeAttribute(cell, originalCell, "width",
StylePropertyDetails.WIDTH, numberOfCells);
}
if (firstColumn) {
mergeSizeAttribute(cell, originalCell, "height",
StylePropertyDetails.HEIGHT, numberOfCells);
}
StyleValue calculatedWidth = cell.getStyles().getPropertyValues()
.getStyleValue(StylePropertyDetails.WIDTH);
StyleValue calculatedHeight = cell.getStyles().getPropertyValues()
.getStyleValue(StylePropertyDetails.HEIGHT);
mergedStyles = merger.merge(mergedStyles, originalCell.getStyles());
// update the cell with the merged styles
MutablePropertyValues mergedValues =
mergedStyles.getPropertyValues();