I've come with another mystery for you Jason !
Here's my code :
- Code: Select all
SpreadsheetMLPackage pkg = SpreadsheetMLPackage.createPackage();
factory = Context.getsmlObjectFactory();
Styles styles = new Styles(new PartName("/xl/styles.xml"));
styles.setJaxbElement(createStyles());
pkg.addTargetPart(styles);
WorksheetPart sheet = pkg.createWorksheetPart(new PartName("/xl/worksheets/sheet1.xml"), "Sheet 1", 1);
SheetData sheetData = sheet.getJaxbElement().getSheetData();
for(int i = 0; i < 5; i++)
{
Row row = factory.createRow();
for(int j = 0; j < 5; j++)
{
Cell cell = factory.createCell();
if(i==0)
{
cell.setS(Long.valueOf(0)); //Style with id 0 is header cell
}
else
{
cell.setS(Long.valueOf(1)); //Style with id 1 is standard cell
}
cell.setV("value");
row.getC().add(cell);
}
sheetData.getRow().add(row);
}
SaveToZipFile saver = new SaveToZipFile(pkg);
saver.save(filepath);
For some reason, this gives me a perfectly good file but without styles.
When I look at the debug info in the console (sent as attachment), in the penultimate paragraph, there is this line bugging me :
- Code: Select all
13.04.2011 16:07:31 *DEBUG* PartName: Trying to create part name /xl/styles.xml (PartName.java, line 151)
This line also appears in the 3rd paragraph, which, if I understood correctly, is around the moment where I add my own styles.xml file.
So, to sum up, I add my own styles, then xlsx4j says "What the hell, I don't like you, I'll make my own styles.xml and ignore yours !!!"
What's wrong doctor ???