use of org.docx4j.openpackaging.parts.SpreadsheetML.Styles in project jmix by jmix-framework.
the class XlsxGenerator method generatePackage.
@Override
protected OpcPackage generatePackage(ReportData reportData) throws Docx4JException, JAXBException {
SpreadsheetMLPackage pkg = SpreadsheetMLPackage.createPackage();
// String sheetInternalName = ((Messages) AppBeans.get(Messages.NAME)).getMessage(getClass(), SHEET);
WorksheetPart sheet = pkg.createWorksheetPart(new PartName("/xl/worksheets/" + SHEET + ".xml"), SHEET, 1);
SheetData sheetData = sheet.getJaxbElement().getSheetData();
ObjectFactory factory = org.xlsx4j.jaxb.Context.getsmlObjectFactory();
CTCalcPr ctCalcPr = factory.createCTCalcPr();
ctCalcPr.setCalcMode(STCalcMode.AUTO);
pkg.getWorkbookPart().getJaxbElement().setCalcPr(ctCalcPr);
Styles styles = new Styles(new PartName("/xl/styles.xml"));
styles.setJaxbElement(generateStyleSheet(factory));
DefinedNames definedNames = factory.createDefinedNames();
// first row of sheet is '1'
long rowNum = 1;
long startedRowForRegion;
long endedRowForRegion;
int maxColCount = 0;
for (ReportRegion reportRegion : reportData.getReportRegions()) {
if (reportRegion.isTabulatedRegion()) {
// insert empty row before table
rowNum++;
// first column of sheet is '1'
int colNum = 1;
for (RegionProperty regionProperty : reportRegion.getRegionProperties()) {
sheetData.getRow().add(createRow(factory, regionProperty.getHierarchicalLocalizedNameExceptRoot(), colNum++, rowNum));
}
rowNum++;
startedRowForRegion = rowNum;
colNum = 1;
for (RegionProperty regionProperty : reportRegion.getRegionProperties()) {
sheetData.getRow().add(createRow(factory, reportTemplatePlaceholder.getPlaceholderValue(regionProperty.getHierarchicalNameExceptRoot(), reportRegion), colNum++, rowNum));
}
endedRowForRegion = rowNum;
maxColCount = maxColCount > colNum ? maxColCount : colNum;
rowNum++;
// insert empty row after table
rowNum++;
} else {
startedRowForRegion = rowNum;
for (RegionProperty regionProperty : reportRegion.getRegionProperties()) {
Row row = factory.createRow();
row.setR(rowNum);
row.getC().add(createCell(factory, regionProperty.getHierarchicalLocalizedNameExceptRoot() + ":", 1, rowNum));
row.getC().add(createCell(factory, reportTemplatePlaceholder.getPlaceholderValue(regionProperty.getHierarchicalNameExceptRoot(), reportRegion), 2, rowNum));
sheetData.getRow().add(row);
rowNum++;
}
endedRowForRegion = rowNum - 1;
maxColCount = maxColCount > 2 ? maxColCount : 2;
}
addDefinedNames(SHEET, factory, definedNames, startedRowForRegion, endedRowForRegion, reportRegion);
}
List<Cols> lstCols = sheet.getJaxbElement().getCols();
Cols cols = factory.createCols();
for (int i = 0; i < maxColCount; i++) {
Col col = factory.createCol();
col.setMin(i + 1);
col.setMax(i + 1);
col.setBestFit(Boolean.TRUE);
col.setCustomWidth(true);
col.setWidth(30.);
cols.getCol().add(col);
}
lstCols.add(cols);
pkg.getWorkbookPart().getJaxbElement().setDefinedNames(definedNames);
sheet.addTargetPart(styles);
Parts parts = pkg.getParts();
Part workBook = parts.get(new PartName("/xl/workbook.xml"));
workBook.addTargetPart(styles);
return pkg;
}
use of org.docx4j.openpackaging.parts.SpreadsheetML.Styles in project docx4j by plutext.
the class CellUtils method getNumberFormatIndex.
// /**
// * Get the index of the number format (numFmt) record used by this cell format.
// *
// * @return the index of the number format
// */
// public long getDataFormatIndexZZZ(CTCellStyle cellStyle) {
// CTXf xf = this.stylesPart.getXfByIndex(cellStyle.getXfId());
// if (xf == null) {
// throw new RuntimeException("xf unexpectedly null");
// }
//
// System.out.println("Using NumFmtId " + xf.getNumFmtId());
//
// return xf.getNumFmtId();
// //(short)_cellXf.getNumFmtId();
// }
/**
* Get the index of the number format (numFmt) record used by this cell format.
*
* @return the index of the number format
*/
public static long getNumberFormatIndex(Cell _cell) {
Styles stylesPart = WorksheetPart.getWorksheetPart(_cell).getWorkbookPart().getStylesPart();
CTXf xf = stylesPart.getXfByIndex(_cell.getS());
if (xf == null) {
throw new RuntimeException("xf unexpectedly null");
}
log.debug("Using NumFmtId " + xf.getNumFmtId());
return xf.getNumFmtId();
// (short)_cellXf.getNumFmtId();
}
use of org.docx4j.openpackaging.parts.SpreadsheetML.Styles in project docx4j by plutext.
the class CellUtils method getCellStyle.
/**
* Return the cell's style.
*
* @return the cell's style.</code>
*/
public static CTCellStyle getCellStyle(Cell _cell) {
Styles stylesPart = WorksheetPart.getWorksheetPart(_cell).getWorkbookPart().getStylesPart();
CTXf xf = stylesPart.getXfByIndex(_cell.getS());
if (xf == null) {
throw new RuntimeException("xf unexpectedly null");
}
return stylesPart.getStyleByIndex(xf.getXfId());
}
Aggregations