I am loading the excel and trying to append more sheets and generate the output. We have used the concept of sharedstrings and CTStylesheet.
Issue that I am facing is. If I updated excel which has one sheet and the sheet contains tables and styles like background, borders.
When i load this excel to and do append generations, the table content of first sheet is also getting replaced with that of sheet and the styles are also overriden.
Is there any was we can restrict any modifications to the sheet we have uploaded ?
for Stylesheet
- Code: Select all
private Styles styles;
styles = new Styles(new PartName("/xl/styles.xml"));
CTStylesheet styleSheet = Context.getsmlObjectFactory().createCTStylesheet();
CTNumFmts formats = styleSheet.getNumFmts();
if (formats == null) {
formats = Context.getsmlObjectFactory().createCTNumFmts();
styleSheet.setNumFmts(formats);
}
styleSheet.getFonts().setCount((long) styleSheet.getFonts().getFont().size());
styleSheet.getFills().setCount((long) styleSheet.getFills().getFill().size());
styleSheet.getBorders().setCount((long) styleSheet.getBorders().getBorder().size());
styleSheet.getCellStyleXfs().setCount((long) styleSheet.getCellStyleXfs().getXf().size());
styleSheet.getCellXfs().setCount((long) styleSheet.getCellXfs().getXf().size());
styleSheet.getCellStyles().setCount((long) styleSheet.getCellStyles().getCellStyle().size());
styles.setJaxbElement(styleSheet);
sheet.getWorkbookPart().addTargetPart(styles);
and for sharedstrings
private SharedStrings sharedStrings;
private Part workBook;
long sharedStringsCount = -1L;
sharedStrings = new SharedStrings(new PartName("/xl/sharedStrings.xml"));
workBook = spreadsheetMLPackage.getParts().get(new PartName("/xl/workbook.xml"));
for each column, row we add the value to CTSst and then we add
workBook.addTargetPart(sharedStrings);
sharedStrings.setJaxbElement(ctst);