1 11 package com.tonbeller.jpivot.excel; 12 13 import org.w3c.dom.Element ; 14 15 import com.tonbeller.jpivot.olap.model.Cell; 16 import com.tonbeller.jpivot.table.CellBuilder; 17 import com.tonbeller.jpivot.table.CellBuilderDecorator; 18 import com.tonbeller.wcf.component.RendererParameters; 19 import com.tonbeller.wcf.controller.RequestContext; 20 21 24 public class ExcelCellBuilderDecorator extends CellBuilderDecorator { 25 26 protected boolean excelMode; 27 28 public void startBuild(RequestContext context) { 29 super.startBuild(context); 30 this.excelMode= RendererParameters.isExcelMode(context); 31 } 32 33 public ExcelCellBuilderDecorator(CellBuilder delegate) { 34 super(delegate); 35 } 36 42 public Element build(Cell cell, boolean even) { 43 Element cellElem = super.build(cell, even); 44 if (excelMode && !cell.isNull() && (cell.getValue() instanceof Number )) { 46 Object value = cell.getValue(); 47 com.tonbeller.jpivot.olap.model.NumberFormat nf = cell.getFormat(); 48 String rawValue = value.toString(); 49 cellElem.setAttribute("rawvalue", rawValue); 50 Number num = (Number ) cell.getValue(); 51 String numFormat = "\\#\\#0"; 52 53 numFormat = (nf.isGrouping() ? "\\#\\," + numFormat : numFormat); 54 if (nf.getFractionDigits() > 0) { 55 numFormat = numFormat + "."; 56 for (int x = 0; x < nf.getFractionDigits(); x++) 57 numFormat = numFormat + "#"; 58 } 59 String msoformat = nf.isPercent() ? "Percent" : numFormat; 60 cellElem.setAttribute("mso-number-format", msoformat); 61 } 62 return cellElem; 64 } 65 } | Popular Tags |