List of usage examples for org.apache.poi.hssf.usermodel HSSFSheet setActive
public void setActive(boolean sel)
From source file:com.servoy.extensions.plugins.excelxport.ExportSpecifyFilePanel.java
License:Open Source License
public static HSSFWorkbook populateWb(IFoundSet foundSet, String[] dataProviders, byte[] templateXLS, String[] outputColumnNames, String sheetName, int startRow, int startColumn) throws IOException { HSSFWorkbook hwb;//w w w. j a v a2s . c om if (templateXLS == null) { hwb = new HSSFWorkbook(); } else { InputStream buff = new ByteArrayInputStream(templateXLS); hwb = new HSSFWorkbook(buff); } if (sheetName == null) sheetName = "Servoy Data"; HSSFSheet sheet = hwb.getSheet(sheetName); if (sheet == null) sheet = hwb.createSheet(sheetName); sheet.setActive(true); if (outputColumnNames != null && outputColumnNames.length != dataProviders.length) { throw new RuntimeException( "The arrays 'output column names' and 'data provider ids' must have the same length."); //$NON-NLS-1$ } String[] columnNames = outputColumnNames != null ? outputColumnNames : dataProviders; HSSFRow header = sheet.createRow((short) 0 + startRow); for (int k = 0; k < columnNames.length; k++) { HSSFCell cell = header.createCell((short) (k + startColumn)); cell.setCellValue(columnNames[k]); } for (int i = 0; i < foundSet.getSize(); i++) { HSSFRow row = sheet.createRow((short) (i + 1 + startRow)); IRecord s = foundSet.getRecord(i); for (int k = 0; k < dataProviders.length; k++) { HSSFCell cell = row.createCell((short) (k + startColumn)); Object obj = s.getValue(dataProviders[k]); if (obj instanceof Date) { HSSFCellStyle cellStyle = hwb.createCellStyle(); cellStyle.setDataFormat((short) 16); cell.setCellValue((Date) obj); cell.setCellStyle(cellStyle); } else if (obj instanceof String) { cell.setCellValue((String) obj); } else if (obj instanceof Number) { cell.setCellValue(((Number) obj).doubleValue()); } else { cell.setCellValue(""); //$NON-NLS-1$ } } } return hwb; }