List of usage examples for org.apache.poi.ss.usermodel Cell getHyperlink
Hyperlink getHyperlink();
From source file:org.spdx.spdxspreadsheet.LicenseSheet.java
License:Apache License
/** * Retrieve the text from a license text cell either through the hyperlink * to a text file in a directory local to the spreadsheet or from the cell * itself if there is no hyperlink present * @param textCell// w w w . j a v a2 s . c om * @return */ public static String getLicenseTemplateText(Cell textCell, String textFilePath) { String localFileName = null; File licenseTemplateTextFile = null; Hyperlink cellHyperlink = textCell.getHyperlink(); if (cellHyperlink != null && cellHyperlink.getAddress() != null) { localFileName = cellHyperlink.getAddress(); licenseTemplateTextFile = new File(textFilePath + File.separator + localFileName); if (!licenseTemplateTextFile.exists()) { // try without the workbook path licenseTemplateTextFile = new File(localFileName); } if (!licenseTemplateTextFile.exists()) { licenseTemplateTextFile = null; } } if (licenseTemplateTextFile == null && textCell.getStringCellValue() != null && textCell.getStringCellValue().toUpperCase().endsWith(".TXT")) { localFileName = textCell.getStringCellValue(); licenseTemplateTextFile = new File(textFilePath + File.separator + localFileName); } if (localFileName != null) { if (!licenseTemplateTextFile.exists()) { logger.warn("Can not find linked license text file " + licenseTemplateTextFile.getName()); return ("WARNING: Could not find license text file " + licenseTemplateTextFile.getName()); } if (!licenseTemplateTextFile.canRead()) { logger.warn("Can not read linked license text file " + licenseTemplateTextFile.getName()); return ("WARNING: Could not read license text file " + licenseTemplateTextFile.getName()); } try { InputStream in = new FileInputStream(licenseTemplateTextFile); BufferedReader reader = new BufferedReader(new InputStreamReader(in, ENCODING)); try { StringBuilder sb = new StringBuilder(); String line = null; String newLine = System.getProperty("line.separator"); line = reader.readLine(); if (line != null) { sb.append(line); } while ((line = reader.readLine()) != null) { sb.append(newLine); sb.append(line); } return sb.toString(); } finally { reader.close(); } } catch (IOException e) { logger.warn("Error reading linked license template text file " + licenseTemplateTextFile.getName() + ": " + e.getMessage()); return ("WARNING: Error reading license template text file " + licenseTemplateTextFile.getName()); } } else { // no file name return textCell.getStringCellValue(); } }
From source file:org.tiefaces.components.websheet.utility.CellUtility.java
License:MIT License
/** * set up cell style./*from w w w .j a v a2 s . c o m*/ * * @param destSheet * dest sheet. * @param sourceCell * source cell. * @param newCell * new cell. */ @SuppressWarnings("deprecation") private static void copyCellSetStyle(final Sheet destSheet, final Cell sourceCell, final Cell newCell) { CellStyle newCellStyle = getCellStyleFromSourceCell(destSheet, sourceCell); newCell.setCellStyle(newCellStyle); // If there is a cell hyperlink, copy if (sourceCell.getHyperlink() != null) { newCell.setHyperlink(sourceCell.getHyperlink()); } // Set the cell data type newCell.setCellType(sourceCell.getCellTypeEnum()); }