Hmm, they should behave very similar, only if you run it on different machines there might be differences due to the number of fonts found on the machine.
Does one break if you leave out the other, i.e. without setting the Font, does autosize work and vice versa? Can you pack that up into a self-contained unit test and report it at https://issues.apache.org/bugzilla/ Dominik. On Thu, Feb 5, 2015 at 4:52 PM, Larry Wilson <[email protected]> wrote: > 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] > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
