This is driving me crazy, so I'd appreciate some guidance. Briefly, I am loading in a pre-existing Excel 2007 file, and looking to add some data in a couple of worksheets: just basic content row-by-row. The file I load contains things like sharedStrings and styles, and that's where I'm coming un-stuck, in terms of adding content.
Every approach I've tried so far results in a crippled file that has to be repaired by Excel as it's opened. This repair involves the wholesale removal of any data I tried to add, plus a report that the styles file had mismatched tags (e.g. "ns2:ext" at the start, but "ns7:ext" at the end), so I'm on a loser.
For example, if I understand things correctly, in order to write a string value to a cell, I need to do something like this (pseudo-ish code obviously!):
- Code: Select all
Cell myCell = Context.getsmlObjectFactory().createCell();
myCell.setV(CELL VALUE INDEX FROM SHAREDSTRINGS);
myCell.setT(STCellType.S); // Tells Excel it's a shared string
myCell.setR(CELL REFERENCE); // cell's ref in worksheet (e.g. A3)
row.getC().add(myCell);
Is that right? And if so, what's a good approach to handling sharedstrings and pushing IDs to and from them? It's that bit that confuses me...