I've recently had to change from an HSSF workbook to an XSSF for password
support. Some methods don't appear to work in XSSF that worked fine in HSSF.
I've checked the online documents and it looks like all this should work.
Significant code snippets pulled from our source (we're using enums with int
columnNumber String columnName for columns):
import org.apache.poi.poifs.crypt.EncryptionInfo;
import org.apache.poi.poifs.crypt.EncryptionMode;
import org.apache.poi.poifs.crypt.Encryptor;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.Drawing;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Picture;
import org.apache.poi.ss.usermodel.PrintSetup;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.IOUtils;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
...
Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
Font rowFont = wb.createFont();
rowFont.setFontName("Arial");
...
CellStyle style = createBorderedStyle(wb);
style.setAlignment(CellStyle.ALIGN_LEFT);
style.setVerticalAlignment(CellStyle.VERTICAL_TOP);
style.setWrapText(true);
style.setFont(rowFont);
styles.put("cell", style);
...
Workbook wb = new XSSFWorkbook();
...
Sheet sheet = wb.createSheet("test");
...
Row headerRow = setSheetPropertiesAndReturnHeaderRow(wb, sheet, styles,
ClientColumn.values().length);
// Cell headerCell;
for (ClientColumn column : ClientColumn.values()) {
createCell(headerRow, column.columnNumber, column.columnName, styles);
}
Row row = sheet.createRow(headerRow.getRowNum() + 1);
for (ClientColumn column : ClientColumn.values()) {
Cell cell = row.createCell(column.columnNumber);
cell.setCellStyle(styles.get("cell"));
....
}
// Adjust columns widths to fit using ClientColumn enum
for (ClientColumn column : ClientColumn.values()) {
sheet.autoSizeColumn(column.columnNumber); // also tried
sheet.autoSizeColumn((short)column.columnNumber);
}
...
When the spreadsheet is viewed, the font is not set, and the columns have not
been autosized when using XSSF. When using HSSF, it works fine.
What am I missing?
Thanks
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]