List of usage examples for org.apache.poi.hssf.usermodel HSSFSheet getWorkbook
@Override
public HSSFWorkbook getWorkbook()
From source file:bd.gov.forms.web.FormBuilder.java
License:Open Source License
@RequestMapping(value = "/excelExport", method = RequestMethod.GET) public String excelExport(@RequestParam(value = "formId", required = true) String formId, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "colName", required = false) String colName, @RequestParam(value = "colVal", required = false) String colVal, @RequestParam(value = "sortCol", required = false) String sortCol, @RequestParam(value = "sortDir", required = false) String sortDir, ModelMap model, HttpServletResponse response, HttpServletRequest request) throws IOException { String access = UserAccessChecker.check(request); if (access != null) { return access; }/*from www . ja va 2 s .c o m*/ if (page == null) { page = 1; } Form form = formDao.getFormWithFields(formId); List<HashMap> list = formDao.getEntryList(form, page, colName, colVal, sortCol, sortDir, false); List<String> headers = getEntryListHeaders(form); response.setContentType("application/vnd.ms-excel"); // TODO: file name HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet("Excel Report"); int r = 0; HSSFRow row = sheet.createRow((short) r++); int count = 0; for (String header : headers) { HSSFCell cell = row.createCell(count++); cell.setCellValue(header); } for (HashMap hashmap : list) { row = sheet.createRow((short) r++); count = 0; HSSFCell cell = row.createCell(count++); cell.setCellValue((String) hashmap.get("entry_date")); cell = row.createCell(count++); cell.setCellValue((String) hashmap.get("entry_time")); cell = row.createCell(count++); cell.setCellValue((String) hashmap.get("entry_status")); for (Field field : form.getFields()) { cell = row.createCell(count++); cell.setCellValue((String) hashmap.get(field.getColName())); } } String fileName = "Report-" + formId + ".xls"; response.setHeader("Content-Disposition", "inline; filename=" + fileName); response.setContentType("application/vnd.ms-excel"); ServletOutputStream outputStream = response.getOutputStream(); sheet.getWorkbook().write(outputStream); outputStream.flush(); return null; }
From source file:com.dawg6.web.dhcalc.server.ExportExcel.java
License:Open Source License
private Cell createTableHeader(HSSFSheet sheet, int col, String label) { int n = sheet.getPhysicalNumberOfRows(); Row row = null;// w w w . j a v a 2 s . com if (n < 1) row = sheet.createRow(0); else row = sheet.getRow(0); Cell cell = row.createCell(col); cell.setCellValue(label); cell.setCellStyle(boldStyle); CellUtil.setAlignment(cell, sheet.getWorkbook(), CellStyle.ALIGN_CENTER); return cell; }
From source file:com.elbeesee.poink.transreptor.HSSFSheetToXML.java
License:Open Source License
public void onTransrept(INKFRequestContext aContext) throws Exception { IHSSFSheetRepresentation aIHSSFSheetRepresentation = (IHSSFSheetRepresentation) aContext .sourcePrimary(IHSSFSheetRepresentation.class); HSSFSheet vSheet = aIHSSFSheetRepresentation.getSheetReadOnly(); String vSheetName = vSheet.getSheetName(); StringBuilder vSheetXML = new StringBuilder(); vSheetXML.append("<sheet sheetName=\""); vSheetXML.append(XMLUtils.escape(vSheetName)); vSheetXML.append("\" sheetIndex=\""); vSheetXML.append(vSheet.getWorkbook().getSheetIndex(vSheetName)); vSheetXML.append("\" numRows=\""); vSheetXML.append(vSheet.getPhysicalNumberOfRows()); vSheetXML.append("\">"); // do the rows int i = 0;//w w w . j av a 2 s . c o m for (Iterator<Row> vRowIterator = vSheet.rowIterator(); vRowIterator.hasNext();) { HSSFRow vHSSFRow = (HSSFRow) vRowIterator.next(); IHSSFRowRepresentation vHSSFRowRepresentation = new HSSFRowImplementation(vHSSFRow); String vRowXML = aContext.transrept(vHSSFRowRepresentation, String.class); vSheetXML.append(vRowXML); i = i + 1; } // vSheetXML.append("</sheet>"); INKFResponse vResponse = aContext.createResponseFrom(vSheetXML.toString()); vResponse.setExpiry(INKFResponse.EXPIRY_DEPENDENT); }
From source file:com.haulmont.yarg.formatters.impl.inline.AbstractInliner.java
License:Apache License
@Override public void inlineToXls(HSSFPatriarch patriarch, HSSFCell resultCell, Object paramValue, Matcher paramsMatcher) {/*from w w w.j a v a 2 s . co m*/ try { Image image = new Image(paramValue, paramsMatcher); if (image.isValid()) { HSSFSheet sheet = resultCell.getSheet(); HSSFWorkbook workbook = sheet.getWorkbook(); int pictureIdx = workbook.addPicture(image.imageContent, Workbook.PICTURE_TYPE_JPEG); CreationHelper helper = workbook.getCreationHelper(); ClientAnchor anchor = helper.createClientAnchor(); anchor.setCol1(resultCell.getColumnIndex()); anchor.setRow1(resultCell.getRowIndex()); anchor.setCol2(resultCell.getColumnIndex()); anchor.setRow2(resultCell.getRowIndex()); if (patriarch == null) { throw new IllegalArgumentException(String.format( "No HSSFPatriarch object provided. Charts on this sheet could cause this effect. Please check sheet %s", resultCell.getSheet().getSheetName())); } HSSFPicture picture = patriarch.createPicture(anchor, pictureIdx); Dimension size = ImageUtils.getDimensionFromAnchor(picture); double actualHeight = size.getHeight() / EMU_PER_PIXEL; double actualWidth = size.getWidth() / EMU_PER_PIXEL; picture.resize((double) image.width / actualWidth, (double) image.height / actualHeight); } } catch (IllegalArgumentException e) { throw new ReportFormattingException("An error occurred while inserting bitmap to xls file", e); } }
From source file:com.haulmont.yarg.formatters.impl.xls.hints.CustomCellStyleHint.java
License:Apache License
private void fixLeftCell(HSSFSheet sheet, int rowIndex, int columnIndex, HSSFCellStyle cellStyle) { HSSFCell leftCell = sheet.getRow(rowIndex).getCell(columnIndex); if (leftCell != null) { HSSFCellStyle leftCellStyle = leftCell.getCellStyle(); if (leftCellStyle.getBorderRight() != cellStyle.getBorderLeft() || leftCellStyle.getRightBorderColor() != cellStyle.getLeftBorderColor()) { HSSFCellStyle draftLeftStyle = HSSFWorkbookHelper.createDetachedCellStyle(sheet.getWorkbook()); XslStyleHelper.cloneStyleRelations(leftCellStyle, draftLeftStyle); draftLeftStyle.setBorderRight(cellStyle.getBorderLeft()); draftLeftStyle.setRightBorderColor(cellStyle.getLeftBorderColor()); HSSFCellStyle newLeftStyle = styleCache.getCellStyleByTemplate(draftLeftStyle); if (newLeftStyle == null) { newLeftStyle = HSSFWorkbookHelper.adoptDetachedCellStyle(sheet.getWorkbook(), draftLeftStyle); styleCache.processCellStyle(newLeftStyle); }/*www . j a v a2 s .c om*/ leftCell.setCellStyle(newLeftStyle); } } }
From source file:com.haulmont.yarg.formatters.impl.xls.hints.CustomCellStyleHint.java
License:Apache License
private void fixRightCell(HSSFSheet sheet, int rowIndex, int columnIndex, HSSFCellStyle cellStyle) { HSSFCell rightCell = sheet.getRow(rowIndex).getCell(columnIndex); if (rightCell != null) { HSSFCellStyle rightCellStyle = rightCell.getCellStyle(); if (rightCellStyle.getBorderLeft() != cellStyle.getBorderRight() || rightCellStyle.getLeftBorderColor() != cellStyle.getRightBorderColor()) { HSSFCellStyle draftRightStyle = HSSFWorkbookHelper.createDetachedCellStyle(sheet.getWorkbook()); XslStyleHelper.cloneStyleRelations(rightCellStyle, draftRightStyle); draftRightStyle.setBorderLeft(cellStyle.getBorderRight()); draftRightStyle.setLeftBorderColor(cellStyle.getRightBorderColor()); HSSFCellStyle newRightStyle = styleCache.getCellStyleByTemplate(draftRightStyle); if (newRightStyle == null) { newRightStyle = HSSFWorkbookHelper.adoptDetachedCellStyle(sheet.getWorkbook(), draftRightStyle); styleCache.processCellStyle(newRightStyle); }/* ww w .j a va 2 s .c o m*/ rightCell.setCellStyle(newRightStyle); } } }
From source file:com.haulmont.yarg.formatters.impl.xls.hints.CustomCellStyleHint.java
License:Apache License
private void fixUpCell(HSSFSheet sheet, int rowIndex, int columnIndex, HSSFCellStyle cellStyle) { HSSFCell upCell = sheet.getRow(rowIndex).getCell(columnIndex); if (upCell != null) { HSSFCellStyle upCellStyle = upCell.getCellStyle(); if (upCellStyle.getBorderBottom() != cellStyle.getBorderTop() || upCellStyle.getBottomBorderColor() != cellStyle.getTopBorderColor()) { HSSFCellStyle draftUpStyle = HSSFWorkbookHelper.createDetachedCellStyle(sheet.getWorkbook()); XslStyleHelper.cloneStyleRelations(upCellStyle, draftUpStyle); draftUpStyle.setBorderBottom(cellStyle.getBorderTop()); draftUpStyle.setBottomBorderColor(cellStyle.getTopBorderColor()); HSSFCellStyle newUpStyle = styleCache.getCellStyleByTemplate(draftUpStyle); if (newUpStyle == null) { newUpStyle = HSSFWorkbookHelper.adoptDetachedCellStyle(sheet.getWorkbook(), draftUpStyle); styleCache.processCellStyle(newUpStyle); }//from w w w . java 2 s.c om upCell.setCellStyle(newUpStyle); } } }
From source file:com.haulmont.yarg.formatters.impl.xls.hints.CustomCellStyleHint.java
License:Apache License
private void fixDownCell(HSSFSheet sheet, int rowIndex, int columnIndex, HSSFCellStyle cellStyle) { HSSFRow nextRow = sheet.getRow(rowIndex); if (nextRow != null) { HSSFCell downCell = nextRow.getCell(columnIndex); if (downCell != null) { HSSFCellStyle downCellStyle = downCell.getCellStyle(); if (downCellStyle.getBorderTop() != cellStyle.getBorderBottom() || downCellStyle.getTopBorderColor() != cellStyle.getBottomBorderColor()) { HSSFCellStyle draftDownStyle = HSSFWorkbookHelper.createDetachedCellStyle(sheet.getWorkbook()); XslStyleHelper.cloneStyleRelations(downCellStyle, draftDownStyle); draftDownStyle.setBorderTop(cellStyle.getBorderBottom()); draftDownStyle.setTopBorderColor(cellStyle.getBottomBorderColor()); HSSFCellStyle newDownStyle = styleCache.getCellStyleByTemplate(draftDownStyle); if (newDownStyle == null) { newDownStyle = HSSFWorkbookHelper.adoptDetachedCellStyle(sheet.getWorkbook(), draftDownStyle); styleCache.processCellStyle(newDownStyle); }/* w ww . j ava 2s . c o m*/ downCell.setCellStyle(newDownStyle); } } } }
From source file:com.iana.dver.controller.DverAdminController.java
License:Open Source License
private void write(HttpServletResponse response, HSSFSheet worksheet) throws IOException { logger.info("Writing excel report to the response stream..."); // Retrieve the output stream ServletOutputStream outputStream = response.getOutputStream(); // Write to the output stream worksheet.getWorkbook().write(outputStream); // Flush the stream outputStream.flush();/*from w w w .j a va 2 s.c o m*/ }
From source file:com.qcadoo.mes.assignmentToShift.print.xls.AssignmentToShiftXlsStyleHelper.java
License:Open Source License
public void setGreyDataStyleAlignLeftBold(final HSSFSheet sheet, final HSSFCell cell) { cell.setCellStyle(getHeaderStyle(sheet.getWorkbook(), HSSFCellStyle.BORDER_NONE, HSSFCellStyle.BORDER_NONE, HSSFCellStyle.ALIGN_LEFT, Font.BOLDWEIGHT_BOLD)); }