Hi,
I'm using
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.5-beta6</version>
</dependency>
I'm trying to copy cells, including their cell styles, from one workbook to
another. When I create the new workbook, I copy the styles over like so ...
for (short i=0; i<oldWorkbook.getNumCellStyles(); i++) {
final CellStyle oldCellStyle =
oldWorkbook.getCellStyleAt(i);
final CellStyle newCellStyle =
newWorkbook.createCellStyle();
newCellStyle.cloneStyleFrom(oldCellStyle);
} // for
but when I create a new cell in the new workbook, I don't know how to find
the appropriate style to assign to it. I'm trying this ...
private void copyCell(final Cell oldCell, final Cell newCell, final
XSSFWorkbook oldWorkbook, final XSSFWorkbook newWorkbook) {
final String cellValue = getCellValue(oldCell);
newCell.setCellValue(cellValue);
final CellStyle oldCellStyle = oldCell.getCellStyle();
for (short i=0; i<newWorkbook.getNumCellStyles(); i++) {
final CellStyle newCellStyle =
newWorkbook.getCellStyleAt(i);
if (oldCellStyle.equals(newCellStyle)) {
newCell.setCellStyle(newCellStyle);
} // if
} // for
} // copyCell
but this doesn't work. In particular, the "equals" method between the
styles never evaluates to true. How do I copy styles from a cell in one
workbook to a cell in another? Thanks, - Dave
--
View this message in context:
http://apache-poi.1045710.n5.nabble.com/How-do-I-copy-cell-styles-tp5615723p5615723.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]