Thanks for your fast reply!
My xlsx document (that I want to use as a template) is not a java object, it's a plain *.xlsx file in filesystem, and I need to get it's representation in my project to modify it and save as another file. As I understand it, method clone() is not suitable fot it. I found this way:
- Code: Select all
SpreadsheetMLPackage opcPackagepkg = SpreadsheetMLPackage.load(new File("myXlsxFile.xlsx"));
WorksheetPart sheet = (WorksheetPart) opcPackagepkg.getParts().get(new PartName("/xl/worksheets/sheet1.xml"));
Worksheet sheetfinal = sheet.getJaxbElement();
SheetData sheetData = sheetfinal.getSheetData();
And then add values to concrete rows:
- Code: Select all
sheetData.getRow().get(3).getC().add(1, createCell("12"));
sheetData.getRow().get(3).getC().add(2, createCell("235gf2"));
sheetData.getRow().get(3).getC().add(3, createCell("gf2"));
sheetData.getRow().get(3).getC().add(4, createCell("2gf2"));
sheetData.getRow().get(3).getC().add(5, createCell("2gjf2"));
sheetData.getRow().get(3).getC().add(6, createCell("2gf2"));
sheetData.getRow().get(3).getC().add(7, createCell("2gffh2"));
sheetData.getRow().get(3).getC().add(8, createCell("2gf2"));
createCell() is a method from example:
https://github.com/plutext/docx4j/blob/ ... sheet.javaAnd then I add footer:
- Code: Select all
sheetData.getRow().get(4).getC().addAll(0, getFooter());
sheetData.getRow().get(4).setHt(250.0);
sheetData.getRow().get(4).setCustomHeight(Boolean.TRUE);
Footer is allways the same but I don't know how much rows will be there before it.
I don't undestand why if I set row heigth this way
- Code: Select all
Row row3 = Context.getsmlObjectFactory().createRow();
row3.getC().addAll(getFooter());
row3.setHt(250.0);
row3.setCustomHeight(Boolean.TRUE);
sheetData.getRow().add(row3);
It sets heigth of previos row and I need to do this:
- Code: Select all
Row row3 = Context.getsmlObjectFactory().createRow();
row3.getC().addAll(getFooter());
sheetData.getRow().add(row3);
Row row4 = Context.getsmlObjectFactory().createRow();
row4.setHt(250.0);
row4.setCustomHeight(Boolean.TRUE);
sheetData.getRow().add(row4);