List of usage examples for org.apache.poi.xssf.usermodel XSSFClientAnchor XSSFClientAnchor
public XSSFClientAnchor(int dx1, int dy1, int dx2, int dy2, int col1, int row1, int col2, int row2)
From source file:apm.common.utils.excel.ExportExcel.java
License:Open Source License
/** * ?/*from w ww .j a v a 2s .co m*/ * @param title ? * @param headerList */ private void initialize(String title, List<String> headerList) { this.wb = new SXSSFWorkbook(500); this.sheet = wb.createSheet("Export"); this.styles = createStyles(wb); // Create title if (StringUtils.isNotBlank(title)) { Row titleRow = sheet.createRow(rownum++); titleRow.setHeightInPoints(30); Cell titleCell = titleRow.createCell(0); titleCell.setCellStyle(styles.get("title")); titleCell.setCellValue(title); sheet.addMergedRegion(new CellRangeAddress(titleRow.getRowNum(), titleRow.getRowNum(), titleRow.getRowNum(), headerList.size() - 1)); } // Create header if (headerList == null) { throw new RuntimeException("headerList not null!"); } Row headerRow = sheet.createRow(rownum++); headerRow.setHeightInPoints(16); for (int i = 0; i < headerList.size(); i++) { Cell cell = headerRow.createCell(i); cell.setCellStyle(styles.get("header")); String[] ss = StringUtils.split(headerList.get(i), "**", 2); if (ss.length == 2) { cell.setCellValue(ss[0]); Comment comment = this.sheet.createDrawingPatriarch() .createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) 3, 3, (short) 5, 6)); comment.setString(new XSSFRichTextString(ss[1])); cell.setCellComment(comment); } else { cell.setCellValue(headerList.get(i)); } sheet.autoSizeColumn(i); } for (int i = 0; i < headerList.size(); i++) { int colWidth = sheet.getColumnWidth(i) * 2; sheet.setColumnWidth(i, colWidth < 3000 ? 3000 : colWidth); } log.debug("Initialize success."); }
From source file:cn.afterturn.easypoi.excel.export.base.BaseExportService.java
License:Apache License
/** * Cell/*www.j a v a 2s. co m*/ */ public void createImageCell(Cell cell, double height, String imagePath, byte[] data) throws Exception { if (height > cell.getRow().getHeight()) { cell.getRow().setHeight((short) height); } ClientAnchor anchor; if (type.equals(ExcelType.HSSF)) { anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1), cell.getRow().getRowNum() + 1); } else { anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1), cell.getRow().getRowNum() + 1); } if (StringUtils.isNotEmpty(imagePath)) { data = ImageCache.getImage(imagePath); } if (data != null) { PoiExcelGraphDataUtil.getDrawingPatriarch(cell.getSheet()).createPicture(anchor, cell.getSheet().getWorkbook().addPicture(data, getImageType(data))); } }
From source file:cn.afterturn.easypoi.excel.export.base.BaseExportService.java
License:Apache License
/** * Cell//from w w w .j av a2 s. c o m */ public void createImageCell(Cell cell, double height, int rowspan, int colspan, String imagePath, byte[] data) throws Exception { if (height > cell.getRow().getHeight()) { cell.getRow().setHeight((short) height); } ClientAnchor anchor; if (type.equals(ExcelType.HSSF)) { anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + colspan), cell.getRow().getRowNum() + rowspan); } else { anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + colspan), cell.getRow().getRowNum() + rowspan); } if (StringUtils.isNotEmpty(imagePath)) { data = ImageCache.getImage(imagePath); } if (data != null) { PoiExcelGraphDataUtil.getDrawingPatriarch(cell.getSheet()).createPicture(anchor, cell.getSheet().getWorkbook().addPicture(data, getImageType(data))); } }
From source file:cn.bzvs.excel.export.base.ExcelExportBase.java
License:Apache License
/** * Cell// ww w. j a v a2s.com * * @param patriarch * @param entity * @param row * @param i * @param imagePath * @param obj * @throws Exception */ public void createImageCell(Drawing patriarch, ExcelExportEntity entity, Row row, int i, String imagePath, Object obj) throws Exception { row.setHeight((short) (50 * entity.getHeight())); row.createCell(i); ClientAnchor anchor; if (type.equals(ExcelType.HSSF)) { anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) i, row.getRowNum(), (short) (i + 1), row.getRowNum() + 1); } else { anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) i, row.getRowNum(), (short) (i + 1), row.getRowNum() + 1); } byte[] value = null; if (entity.getExportImageType() == 1) { if (StringUtils.isNotEmpty(imagePath)) { value = ImageCache.getImage(imagePath); } } else { value = (byte[]) (entity.getMethods() != null ? getFieldBySomeMethod(entity.getMethods(), obj) : entity.getMethod().invoke(obj, new Object[] {})); } if (value != null) { patriarch.createPicture(anchor, row.getSheet().getWorkbook().addPicture(value, getImageType(value))); } }
From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.generator.OnlineJobsReportForIPTranslatorGenerator.java
License:Apache License
private void addTotalsPerLang(Workbook p_workbook, Sheet p_sheet, final int p_sheetCategory, IntHolder p_row) throws Exception { Font subTotalFont = p_workbook.createFont(); subTotalFont.setBoldweight(Font.BOLDWEIGHT_BOLD); subTotalFont.setColor(IndexedColors.BLACK.getIndex()); subTotalFont.setUnderline(Font.U_NONE); subTotalFont.setFontName("Arial"); subTotalFont.setFontHeightInPoints((short) 10); CellStyle subTotalStyle = p_workbook.createCellStyle(); subTotalStyle.setFont(subTotalFont); String title = m_bundle.getString("lb_total_cost_per_lang"); int row = p_row.getValue() + 4; // skip a row ArrayList<String> locales = new ArrayList<String>(totalCost.keySet()); SortUtil.sort(locales);//from w ww . j a va 2 s . c om int col = m_data.getSumStartCol(); Row theRow = getRow(p_sheet, row); Cell cell_Title = getCell(theRow, col - 3); cell_Title.setCellValue(title); cell_Title.setCellStyle(subTotalStyle); File imgFile = File.createTempFile("GSJobChart", ".png"); JfreeCharUtil.drawPieChart2D("", totalCostDate, imgFile); Drawing patriarch = p_sheet.createDrawingPatriarch(); XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, 15, row - 1, 22, row + 24); ByteArrayOutputStream img_bytes = new ByteArrayOutputStream(); InputStream is = imgFile.toURI().toURL().openStream(); int b; while ((b = is.read()) != -1) { img_bytes.write(b); } is.close(); int i = p_workbook.addPicture(img_bytes.toByteArray(), SXSSFWorkbook.PICTURE_TYPE_PNG); patriarch.createPicture(anchor, i); for (String locale : locales) { List<Integer> indexs = totalCost.get(locale); StringBuffer values = new StringBuffer(); for (Integer index : indexs) { if (values.length() == 0) { values.append("SUM("); } else { values.append("+"); } values.append(totalCol).append(index); } values.append(")"); Row perRow = getRow(p_sheet, row); Cell cell_Locale = getCell(perRow, col - 1); cell_Locale.setCellValue(locale); cell_Locale.setCellStyle(getContentStyle(p_workbook)); Cell cell_Total = getCell(perRow, col); cell_Total.setCellFormula(values.toString()); cell_Total.setCellStyle(getMoneyStyle(p_workbook)); row++; } // Reset total column number for every sheet. totalCol = null; }
From source file:com.heimaide.server.common.utils.excel.ExportExcel.java
License:Open Source License
private void initialize(String title, List<String> headerList) { this.wb = new SXSSFWorkbook(500); this.sheet = wb.createSheet("Export"); this.styles = createStyles(wb); // Create title if (StringUtils.isNotBlank(title)) { Row titleRow = sheet.createRow(rownum++); titleRow.setHeightInPoints(30);//from ww w. j a v a 2s .co m Cell titleCell = titleRow.createCell(0); titleCell.setCellStyle(styles.get("title")); titleCell.setCellValue(title); sheet.addMergedRegion(new CellRangeAddress(titleRow.getRowNum(), titleRow.getRowNum(), titleRow.getRowNum(), headerList.size() - 1)); } // Create header if (headerList == null) { throw new RuntimeException("headerList not null!"); } Row headerRow = sheet.createRow(rownum++); headerRow.setHeightInPoints(16); for (int i = 0; i < headerList.size(); i++) { Cell cell = headerRow.createCell(i); cell.setCellStyle(styles.get("header")); String[] ss = StringUtils.split(headerList.get(i), "**", 2); if (ss.length == 2) { cell.setCellValue(ss[0]); Comment comment = this.sheet.createDrawingPatriarch() .createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) 3, 3, (short) 5, 6)); comment.setString(new XSSFRichTextString(ss[1])); cell.setCellComment(comment); } else { cell.setCellValue(headerList.get(i)); } sheet.autoSizeColumn(i); } for (int i = 0; i < headerList.size(); i++) { int colWidth = sheet.getColumnWidth(i) * 2; sheet.setColumnWidth(i, colWidth < 3000 ? 3000 : colWidth); } log.debug("Initialize success."); }
From source file:com.qihang.winter.poi.excel.export.base.ExcelExportBase.java
License:Apache License
/** * Cell/* w w w . ja v a 2 s . co m*/ * * @param patriarch * @param entity * @param row * @param i * @param imagePath * @param obj * @throws Exception */ public void createImageCell(Drawing patriarch, com.qihang.winter.poi.excel.entity.params.ExcelExportEntity entity, Row row, int i, String imagePath, Object obj) throws Exception { row.setHeight((short) (50 * entity.getHeight())); row.createCell(i); ClientAnchor anchor; if (type.equals(com.qihang.winter.poi.excel.entity.enmus.ExcelType.HSSF)) { anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) i, row.getRowNum(), (short) (i + 1), row.getRowNum() + 1); } else { anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) i, row.getRowNum(), (short) (i + 1), row.getRowNum() + 1); } if (StringUtils.isEmpty(imagePath)) { return; } if (entity.getExportImageType() == 1) { ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream(); BufferedImage bufferImg; try { String path = PoiPublicUtil.getWebRootPath(imagePath); path = path.replace("WEB-INF/classes/", ""); path = path.replace("file:/", ""); bufferImg = ImageIO.read(new File(path)); ImageIO.write(bufferImg, imagePath.substring(imagePath.indexOf(".") + 1, imagePath.length()), byteArrayOut); byte[] value = byteArrayOut.toByteArray(); patriarch.createPicture(anchor, row.getSheet().getWorkbook().addPicture(value, getImageType(value))); } catch (IOException e) { LOGGER.error(e.getMessage(), e); } } else { byte[] value = (byte[]) (entity.getMethods() != null ? getFieldBySomeMethod(entity.getMethods(), obj) : entity.getMethod().invoke(obj, new Object[] {})); if (value != null) { patriarch.createPicture(anchor, row.getSheet().getWorkbook().addPicture(value, getImageType(value))); } } }
From source file:com.vaadin.addon.spreadsheet.SpreadsheetFactory.java
License:Open Source License
/** * Copy-pasted from XSSFDrawing (private there) with slight modifications. * Used to get anchors from an XSSFShape's parent. *//*from ww w .j ava2 s .c om*/ private static XSSFClientAnchor getAnchorFromParent(XmlObject obj) { XSSFClientAnchor anchor = null; XmlObject parentXbean = null; XmlCursor cursor = obj.newCursor(); if (cursor.toParent()) { parentXbean = cursor.getObject(); } cursor.dispose(); if (parentXbean != null) { if (parentXbean instanceof CTTwoCellAnchor) { CTTwoCellAnchor ct = (CTTwoCellAnchor) parentXbean; anchor = new XSSFClientAnchor((int) ct.getFrom().getColOff(), (int) ct.getFrom().getRowOff(), (int) ct.getTo().getColOff(), (int) ct.getTo().getRowOff(), ct.getFrom().getCol(), ct.getFrom().getRow(), ct.getTo().getCol(), ct.getTo().getRow()); } else if (parentXbean instanceof CTOneCellAnchor) { CTOneCellAnchor ct = (CTOneCellAnchor) parentXbean; anchor = new XSSFClientAnchor((int) ct.getFrom().getColOff(), (int) ct.getFrom().getRowOff(), 0, 0, ct.getFrom().getCol(), ct.getFrom().getRow(), 0, 0); } } return anchor; }
From source file:com.vodafone.poms.ii.helpers.ExportManager.java
public void exportActivity() { try {/* w w w . java2s. co m*/ List<Activity> activities = activityController.getExportItems(fromDate, toDate); XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet("Master Track"); int imgPckId = addImageToWorkbook(workbook, "/home/poms/uploaded_data/pkg.png", Workbook.PICTURE_TYPE_PNG); String imgPckRelId = addImageToSheet(sheet, imgPckId, Workbook.PICTURE_TYPE_PNG); Row row = sheet.createRow(0); for (int i = 0; i < activityHeaders.length; i++) { row.createCell(i).setCellValue(activityHeaders[i]); } for (int i = 0; i < activities.size(); i++) { row = sheet.createRow(i + 1); row.createCell(0).setCellValue(activities.get(i).getSite().getSitePhysical()); row.createCell(1).setCellValue(activities.get(i).getAsp().getSubcontractorName()); row.createCell(2).setCellValue(activities.get(i).getArea().getAreaName()); row.createCell(3).setCellValue(activities.get(i).getVendorOwner().getOwnerName()); if (activities.get(i).getClaimStatus() != null) { row.createCell(4).setCellValue(activities.get(i).getClaimStatus().getClaimName()); } else { row.createCell(4).setCellValue(""); } if (activities.get(i).getApprovalStatus() != null) { row.createCell(5).setCellValue(activities.get(i).getApprovalStatus().getStatusName()); } else { row.createCell(5).setCellValue(""); } row.createCell(6).setCellValue(activities.get(i).getActivityType().getDomainName()); if (activities.get(i).getPhase() != null) { row.createCell(7).setCellValue(activities.get(i).getPhase().getPhaseName()); } else { row.createCell(7).setCellValue(""); } row.createCell(8).setCellValue(activities.get(i).getActivityDate()); row.createCell(9).setCellValue(activities.get(i).getAcMaterialId()); row.createCell(10).setCellValue(activities.get(i).getAcDescription()); row.createCell(11).setCellValue(activities.get(i).getActivityDetails()); row.createCell(12).setCellValue(activities.get(i).getQty()); row.createCell(13).setCellValue(activities.get(i).getAcVendorPrice()); row.createCell(14).setCellValue(activities.get(i).getTotalPriceVendor()); row.createCell(15).setCellValue(activities.get(i).getTotalPriceVendorTaxes()); row.createCell(16).setCellValue(activities.get(i).getAcSubcontractorPrice()); row.createCell(17).setCellValue(activities.get(i).getTotalPriceAsp()); row.createCell(18).setCellValue(activities.get(i).getTotalUm()); row.createCell(19).setCellValue(activities.get(i).getTotalUmPercent()); row.createCell(20).setCellValue(activities.get(i).getActivityComment()); row.createCell(21).setCellValue((activities.get(i).getAspPoCollection().isEmpty() ? "Uncorrelated" : ((AspPo) activities.get(i).getAspPoCollection().toArray()[0]).getPoNumber())); if (activities.get(i).getActivityAttachmentsCollection() != null) { if (activities.get(i).getActivityAttachmentsCollection().size() > 0) { Object[] attachments = activities.get(i).getActivityAttachmentsCollection().toArray(); for (int j = 0; j < attachments.length; j++) { XSSFClientAnchor imgAnchor1 = new XSSFClientAnchor(0, 0, 0, 0, (23 + j), row.getRowNum(), (23 + j + 1), row.getRowNum() + 1); String oleRelId1 = addFile(sheet, ((ActivityAttachments) attachments[j]).getAttachmentLocation(), (i + j + activities.get(i).getActivityId().intValue() + Math.random())); int shapeId1 = addImageToShape(sheet, imgAnchor1, imgPckId); addObjectToShape(sheet, imgAnchor1, shapeId1, oleRelId1, imgPckRelId, "Objekt-Manager-Shellobjekt"); } } } } FacesContext facesContext = FacesContext.getCurrentInstance(); ExternalContext externalContext = facesContext.getExternalContext(); externalContext.setResponseContentType("application/vnd.ms-excel"); externalContext.setResponseHeader("Content-Disposition", "attachment; filename=\"G-Cairo Region Extra Work.xlsx\""); try { workbook.write(externalContext.getResponseOutputStream()); externalContext.getResponseOutputStream().close(); } catch (IOException ex) { Logger.getLogger(ExportManager.class.getName()).log(Level.SEVERE, null, ex); } facesContext.responseComplete(); JsfUtil.addSuccessMessage("Activity Report is now exported"); } catch (InvalidFormatException ex) { Logger.getLogger(ExportManager.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ExportManager.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:it.eng.spagobi.engines.worksheet.exporter.WorkSheetXLSXExporter.java
License:Mozilla Public License
@Override protected ClientAnchor getClientAnchor(int col, int colend, int sheetRow, int height, int dx1, int dy1, int dx2, int dy2) { XSSFClientAnchor anchor = new XSSFClientAnchor(dx1, dy1, dx2, dy2, (short) col, sheetRow, (short) colend, sheetRow + height);/* w w w . jav a 2s . com*/ return anchor; }