public CellSettings( CellType cellType, HSSFCellStyle cellStyle, Object cellValue, String formula, Hyperlink link ) { this.cellType = cellType; this.cellStyle = cellStyle; this.cellValue = cellValue; this.formula = formula; this.link = link; }
public void importValues( CellType cellType, HSSFCellStyle cellStyle, Object cellValue, String formula, Hyperlink link ) { this.cellType = cellType; this.cellStyle = cellStyle; this.cellValue = cellValue; this.formula = formula; this.link = link; }
/** * Set a link to a cell. The link type should one of {@link Hyperlink} * * @param wb * the workbook which contains the cell * @param cell * the cell where the link is stored * @param address * the cell destination address * @param linkType * the type selected among {@link Hyperlink} */ public static void setLink(Workbook wb, HSSFCell cell, String address, int linkType) { CreationHelper helper = wb.getCreationHelper(); CellStyle style = wb.createCellStyle(); Font font = wb.createFont(); font.setUnderline(Font.U_SINGLE); font.setColor(IndexedColors.BLUE.getIndex()); style.setFont(font); Hyperlink link = helper.createHyperlink(linkType); link.setAddress(address); cell.setHyperlink(link); cell.setCellStyle(style); }
/** * セルにハイパーリンクを設定する。 * * @param cell セル * @param type リンクタイプ * @param address ハイパーリンクアドレス * @see org.apache.poi.common.usermodel.Hyperlink */ public static void setHyperlink( Cell cell, HyperlinkType hyperlinkType, String address) { Workbook wb = cell.getRow().getSheet().getWorkbook(); CreationHelper createHelper = wb.getCreationHelper(); Hyperlink link = createHelper.createHyperlink( hyperlinkType); if ( link instanceof HSSFHyperlink) { (( HSSFHyperlink) link).setTextMark( address); } else if ( link instanceof XSSFHyperlink) { (( XSSFHyperlink) link).setAddress( address); } cell.setHyperlink( link); }
/** * セルに設定されているハイパーリンクを削除する。 * <p>POIのバージョンによって、{@link Cell#removeHyperlink()}のネイティブのメソッドを呼び出す。 * @since 0.4 * @param cell * @return true: ハイパーリンクが設定されており削除できた場合。false:ハイパーリンクが設定されていない場合。 * @throws IllegalArgumentException cell == null. */ public static boolean removeHyperlink(final Cell cell) { ArgUtils.notNull(cell, "cell"); final Hyperlink link = cell.getHyperlink(); if(link == null) { return false; } if(AVAILABLE_METHOD_CELL_REMOVE_HYPERLINK) { cell.removeHyperlink(); return true; } else { // 既存のハイパーリンクのURLをクリアし、再設定する。 link.setAddress(""); cell.setHyperlink(link); return true; } }
public String getFormula2(Point point, Cell cell) { if(Utils.equals(comment, "空文字")) { return null; } // ダミーでリンクも設定する final CreationHelper helper = cell.getSheet().getWorkbook().getCreationHelper(); final Hyperlink link = helper.createHyperlink(Hyperlink.LINK_URL); link.setAddress(comment); cell.setHyperlink(link); final int rowNumber = point.y + 1; return String.format("HYPERLINK(D%s,\"リンク\"&A%s)", rowNumber, rowNumber); }
/** * Validates the attributes for this <code>Tag</code>. This tag must be * bodiless. The type must be valid. */ @SuppressWarnings("unchecked") public void validateAttributes() throws TagParseException { super.validateAttributes(); if (!isBodiless()) throw new TagParseException("Hyperlink tags must not have a body."); TagContext context = getContext(); Map<String, Object> beans = context.getBeans(); Map<String, RichTextString> attributes = getAttributes(); String type = AttributeUtil.evaluateStringSpecificValues(attributes.get(ATTR_TYPE), beans, ATTR_TYPE, Arrays.asList(TYPE_URL, TYPE_EMAIL, TYPE_FILE, TYPE_DOC), TYPE_URL); if (TYPE_URL.equals(type)) myLinkType = Hyperlink.LINK_URL; else if (TYPE_EMAIL.equals(type)) myLinkType = Hyperlink.LINK_EMAIL; else if (TYPE_FILE.equals(type)) myLinkType = Hyperlink.LINK_FILE; else if (TYPE_DOC.equals(type)) myLinkType = Hyperlink.LINK_DOCUMENT; myAddress = AttributeUtil.evaluateStringNotNull(attributes.get(ATTR_ADDRESS), beans, ATTR_ADDRESS, null); myValue = attributes.get(ATTR_VALUE); }
/** * <p>Place the Hyperlink in the Cell, which replaces any other value left * behind in the Cell.</p> * @return Whether the first <code>Cell</code> in the <code>Block</code> * associated with this <code>Tag</code> was processed. */ public boolean process() { TagContext context = getContext(); Sheet sheet = context.getSheet(); Block block = context.getBlock(); int left = block.getLeftColNum(); int top = block.getTopRowNum(); // It should exist in this Cell; this Tag was found in it. Row row = sheet.getRow(top); Cell cell = row.getCell(left); SheetUtil.setCellValue(cell, myValue); CreationHelper helper = sheet.getWorkbook().getCreationHelper(); Hyperlink hyperlink = helper.createHyperlink(myLinkType); hyperlink.setAddress(myAddress); cell.setHyperlink(hyperlink); BlockTransformer transformer = new BlockTransformer(); transformer.transform(context, getWorkbookContext()); return true; }
/** * Adds the footer. */ private void addFooter() { nextRow(); nextRow(); cell.setCellValue("Produced by gedantic"); Hyperlink link = wb.getCreationHelper().createHyperlink(org.apache.poi.common.usermodel.Hyperlink.LINK_URL); link.setAddress("http://gedantic.org"); cell.setHyperlink(link); cell.setCellStyle(styleHyperlink); }
private void writeWorkbook() throws java.io.IOException { Workbook wb = new XSSFWorkbook(); try { Sheet sheet = wb.createSheet("Sheet1"); Row row = sheet.createRow(0); Cell cell = row.createCell(0); cell.setCellValue("cell-1"); cell = row.createCell(1); cell.setCellValue("cell-2"); cell = row.createCell(2); cell.setCellValue("cell-3"); XSSFCellStyle style = (XSSFCellStyle) wb.createCellStyle(); style.setFillBackgroundColor(new XSSFColor(new org.apache.poi.java.awt.Color(1, 2, 3))); Hyperlink link = wb.getCreationHelper().createHyperlink(HyperlinkType.URL); link.setAddress("http://www.google.at"); link.setLabel("Google"); cell.setHyperlink(link); cell.setCellStyle(style); sheet.setPrintGridlines(true); OutputStream stream = openFileOutput("test.xlsx", Context.MODE_PRIVATE); try { wb.write(stream); } finally { stream.close(); } } finally { wb.close(); } }
private void populateRow(Row row, User user) { UserBinding binding = new UserBinding(user); int columnIndex = 0; addTextCell(row, columnIndex++, binding.userName().getSafely()); addTextCell(row, columnIndex++, binding.lastName().getSafely()); addTextCell(row, columnIndex++, binding.firstName().getSafely()); XSSFCreationHelper helper= (XSSFCreationHelper) workbook.getCreationHelper(); XSSFHyperlink emailLink = helper.createHyperlink(Hyperlink.LINK_EMAIL); String emailAddress = binding.email().getSafely(); emailLink.setAddress("mailto:" + emailAddress); addLinkToCell(addTextCell(row, columnIndex++, emailAddress), emailLink); if (binding.active().getSafely()) { addTextCell(row, columnIndex++, "Oui"); } else { addTextCell(row, columnIndex++, "Non"); } if (binding.creationDate().getSafely() != null) { addDateCell(row, columnIndex++, binding.creationDate().getSafely()); } else { addTextCell(row, columnIndex++, ""); } if (binding.lastUpdateDate().getSafely() != null) { addDateCell(row, columnIndex++, binding.lastUpdateDate().getSafely()); } else { addTextCell(row, columnIndex++, ""); } if (binding.lastLoginDate().getSafely() != null) { addDateCell(row, columnIndex++, binding.lastLoginDate().getSafely()); } else { addTextCell(row, columnIndex++, ""); } }
private Hyperlink setAttachmentURLLinks(SignupAttachment attach) { Hyperlink hsHyperlink = wb.getCreationHelper().createHyperlink(HyperlinkType.URL); String link = this.sakaiFacade.getServerConfigurationService().getServerUrl() + attach.getLocation(); hsHyperlink.setAddress(link); hsHyperlink.setLabel(attach.getFilename()); return hsHyperlink; }
public static int addBooleanCell(Sheet sheet, int col, int row, int width, int height, CellStyle cellStyle, Boolean value, Hyperlink link) { if (value == null) { return addBlankCell(sheet, col, row, width, height, cellStyle, link); } Cell cell = createCell(sheet, col, row, width, height, cellStyle, CELL_TYPE_BOOLEAN, link); cell.setCellValue(value.booleanValue()); return width; }
public static int addLabelCell(Sheet sheet, int col, int row, int width, int height, CellStyle cellStyle, String value, Hyperlink link) { if (value == null) { return addBlankCell(sheet, col, row, width, height, cellStyle, link); } Cell cell = createCell(sheet, col, row, width, height, cellStyle, CELL_TYPE_STRING, link); cell.setCellValue(value); return width; }
public static int addNumberCell(Sheet sheet, int col, int row, int width, int height, CellStyle cellStyle, Number value, Hyperlink link) { if (value == null) { return addBlankCell(sheet, col, row, width, height, cellStyle, link); } Cell cell = createCell(sheet, col, row, width, height, cellStyle, CELL_TYPE_NUMERIC, link); cell.setCellValue(value.doubleValue()); return width; }
public static int addDateTimeCell(Sheet sheet, int col, int row, int width, int height, CellStyle cellStyle, Date value, Hyperlink link) { if (value == null) { return addBlankCell(sheet, col, row, width, height, cellStyle, link); } Cell cell = createCell(sheet, col, row, width, height, cellStyle, CELL_TYPE_NUMERIC, link); cell.setCellValue(value); return width; }
public static int addDateTimeCell(Sheet sheet, int col, int row, int width, int height, CellStyle cellStyle, Calendar value, Hyperlink link) { if (value == null) { return addBlankCell(sheet, col, row, width, height, cellStyle, link); } Cell cell = createCell(sheet, col, row, width, height, cellStyle, CELL_TYPE_NUMERIC, link); cell.setCellValue(value); return width; }
public static int addFormulaCell(Sheet sheet, int col, int row, int width, int height, CellStyle cellStyle, String formula, Hyperlink link) { if (formula == null) { return addBlankCell(sheet, col, row, width, height, cellStyle, link); } Cell cell = createCell(sheet, col, row, width, height, cellStyle, CELL_TYPE_FORMULA, link); cell.setCellFormula(formula); return width; }
/** * Adds a row to the sheet. * * @param fields * an Iterable of Object * @return this {@link WorkbookWriter} */ public WorkbookWriter addRow(@NonNull Iterable<? extends Object> fields) { Row row; if (sheet.getLastRowNum() == 0 && sheet.getPhysicalNumberOfRows() == 0) row = sheet.createRow(0); else row = sheet.createRow(sheet.getLastRowNum() + 1); int i = 0; for (Object o : fields) { Cell cell = row.createCell(i); if (o != null) { if (o instanceof Boolean) cell.setCellValue((Boolean) o); else if (o instanceof Calendar) cell.setCellValue((Calendar) o); else if (o instanceof Date) cell.setCellValue((Date) o); else if (o instanceof Double) cell.setCellValue((Double) o); else if (o instanceof RichTextString) if ((o instanceof HSSFRichTextString && workbook instanceof HSSFWorkbook) || (o instanceof XSSFRichTextString && workbook instanceof XSSFWorkbook)) { cell.setCellValue((RichTextString) o); } else { cell.setCellValue(o.toString()); } else if (o instanceof Hyperlink) cell.setHyperlink((Hyperlink) o); else if (o instanceof Number) cell.setCellValue(((Number) o).doubleValue()); else cell.setCellValue(o.toString()); } i++; } return this; }
@Override public Hyperlink getHyperlink(CreationHelper creationHelper, T obj, String name, Object value) { return null; }
public Hyperlink getLink() { return link; }
public void setLink(Hyperlink link) { this.link = link; }
public void writeRow( ArrayList<IdentifiedFilesRow> identifiedFilesRowList) { for(IdentifiedFilesRow identifiedFilesRow:identifiedFilesRowList) { Row row = sheet.createRow(curRow++); Cell cell = row.createCell(ISheetTemplate.COL_A); cell.setCellValue(identifiedFilesRow.getProjectName()); cell.setCellStyle(normalStyle); cell = row.createCell(ISheetTemplate.COL_B); cell.setCellValue(identifiedFilesRow.getFullPath()); cell.setCellStyle(leftStyle); cell = row.createCell(ISheetTemplate.COL_C); cell.setCellValue(identifiedFilesRow.getComponent()); cell.setCellStyle(normalStyle); cell = row.createCell(ISheetTemplate.COL_D); cell.setCellValue(identifiedFilesRow.getLicense()); cell.setCellStyle(normalStyle); cell = row.createCell(ISheetTemplate.COL_E); cell.setCellValue(identifiedFilesRow.getDiscoveryType()); cell.setCellStyle(normalStyle); cell = row.createCell(ISheetTemplate.COL_F); cell.setCellStyle(normalStyle); String value = ""; String url = identifiedFilesRow.getUrl(); if(url != null && (url.length() != 0) && !"null".equals(url)) { Hyperlink link = wb.getCreationHelper().createHyperlink(Hyperlink.LINK_URL); link.setAddress(url); link.setLabel(url); cell.setHyperlink(link); cell.setCellStyle(getCellStyle(WHITE, getFont(BLUE,(short)10,false))); value = "Show Matched Code ("+(identifiedFilesRow.getCodeMatchCnt())+")"; } cell.setCellValue(value); cell = row.createCell(ISheetTemplate.COL_G); cell.setCellValue(identifiedFilesRow.getComment()); cell.setCellStyle(leftStyle); } }
public Hyperlink getHyperlink() { return hyperlink; }
public void setHyperlink(Hyperlink link) { throw new IllegalStateException("CellClone is not support setHyperlink(Hyperlink link)."); }
@Nullable public static Hyperlink getHyperlink (@Nullable final Cell aCell) { return aCell == null ? null : aCell.getHyperlink (); }
/** * Not supported */ @Override public Hyperlink getHyperlink(int i, int i1) { throw new UnsupportedOperationException(); }
/** * Not supported */ @Override public Hyperlink getHyperlink(CellAddress cellAddress) { throw new UnsupportedOperationException(); }
/** * Not supported */ @Override public List<? extends Hyperlink> getHyperlinkList() { throw new UnsupportedOperationException(); }
/** * Not supported */ @Override public Hyperlink getHyperlink() { throw new NotSupportedException(); }
/** * Not supported */ @Override public void setHyperlink(Hyperlink link) { throw new NotSupportedException(); }
@Override public Cell toCell(final FieldAdaptor adaptor, final URI targetValue, final Object targetBean, final Sheet sheet, final int column, final int row, final XlsMapperConfig config) throws XlsMapperException { final XlsConverter converterAnno = adaptor.getSavingAnnotation(XlsConverter.class); final XlsFormula formulaAnno = adaptor.getSavingAnnotation(XlsFormula.class); final boolean primaryFormula = formulaAnno == null ? false : formulaAnno.primary(); final Cell cell = POIUtils.getCell(sheet, column, row); // セルの書式設定 if(converterAnno != null) { POIUtils.wrapCellText(cell, converterAnno.wrapText()); POIUtils.shrinkToFit(cell, converterAnno.shrinkToFit()); } URI value = targetValue; // 既存のハイパーリンクを削除 // 削除しないと、Excelの見た目上はリンクは変わっているが、データ上は2重にリンクが設定されている。 POIUtils.removeHyperlink(cell); if(value != null && !primaryFormula) { final CreationHelper helper = sheet.getWorkbook().getCreationHelper(); final Hyperlink link = helper.createHyperlink(Hyperlink.LINK_URL); link.setAddress(value.toString()); cell.setHyperlink(link); cell.setCellValue(value.toString()); } else if(formulaAnno != null) { Utils.setupCellFormula(adaptor, formulaAnno, config, cell, targetBean); } else { cell.setCellType(Cell.CELL_TYPE_BLANK); } return cell; }
@Override public Cell toCell(final FieldAdaptor adaptor, final CellLink targetValue, final Object targetBean, final Sheet sheet, final int column, final int row, final XlsMapperConfig config) throws XlsMapperException { final XlsConverter converterAnno = adaptor.getSavingAnnotation(XlsConverter.class); final XlsFormula formulaAnno = adaptor.getSavingAnnotation(XlsFormula.class); final boolean primaryFormula = formulaAnno == null ? false : formulaAnno.primary(); final Cell cell = POIUtils.getCell(sheet, column, row); // セルの書式設定 if(converterAnno != null) { POIUtils.wrapCellText(cell, converterAnno.wrapText()); POIUtils.shrinkToFit(cell, converterAnno.shrinkToFit()); } final CellLink value = targetValue; // 既存のハイパーリンクを削除 // 削除しないと、Excelの見た目上はリンクは変わっているが、データ上は2重にリンクが設定されている。 POIUtils.removeHyperlink(cell); if(value != null && Utils.isNotEmpty(value.getLink()) && !primaryFormula) { final CreationHelper helper = sheet.getWorkbook().getCreationHelper(); final LinkType type = POIUtils.judgeLinkType(value.getLink()); final Hyperlink link = helper.createHyperlink(type.poiType()); link.setAddress(value.getLink()); cell.setHyperlink(link); cell.setCellValue(value.getLabel()); } else if(value != null && Utils.isNotEmpty(value.getLabel()) && !primaryFormula) { // 見出しのみ設定されている場合 cell.setCellValue(value.getLabel()); } else if(formulaAnno != null) { Utils.setupCellFormula(adaptor, formulaAnno, config, cell, targetBean); } else { cell.setCellType(Cell.CELL_TYPE_BLANK); } return cell; }
public static int addBlankCell(Sheet sheet, int col, int row, CellStyle cellStyle, Hyperlink link) { return addBlankCell(sheet, col, row, 1, cellStyle, link); }
public static int addBlankCell(Sheet sheet, int col, int row, int width, CellStyle cellStyle, Hyperlink link) { return addBlankCell(sheet, col, row, width, 1, cellStyle, link); }
public static int addBlankCell(Sheet sheet, int col, int row, int width, int height, CellStyle cellStyle, Hyperlink link) { createCell(sheet, col, row, width, height, cellStyle, CELL_TYPE_BLANK, link); return width; }
public static int addBooleanCell(Sheet sheet, int col, int row, CellStyle cellStyle, Boolean value, Hyperlink link) { return addBooleanCell(sheet, col, row, 1, cellStyle, value, link); }
public static int addBooleanCell(Sheet sheet, int col, int row, int width, CellStyle cellStyle, Boolean value, Hyperlink link) { return addBooleanCell(sheet, col, row, width, 1, cellStyle, value, link); }