List of usage examples for org.apache.poi.hssf.usermodel HSSFCell getStringCellValue
public String getStringCellValue()
From source file:fitlibrary.runner.SpreadsheetRunner.java
License:Open Source License
@SuppressWarnings("deprecation") private String value(HSSFCell cell) { switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_BLANK: return ""; case HSSFCell.CELL_TYPE_BOOLEAN: return "" + cell.getBooleanCellValue(); case HSSFCell.CELL_TYPE_ERROR: return "ERROR"; case HSSFCell.CELL_TYPE_FORMULA: if (Double.isNaN(cell.getNumericCellValue())) { try { return "" + cell.getBooleanCellValue(); } catch (NumberFormatException ex) { return cell.getStringCellValue(); }//from w ww . ja va 2s . co m } return number(cell); case HSSFCell.CELL_TYPE_NUMERIC: return number(cell); case HSSFCell.CELL_TYPE_STRING: return cell.getStringCellValue(); } return "UNKNOWN"; }
From source file:fr.univrouen.poste.services.ExcelParser.java
License:Apache License
public List<List<String>> getCells(InputStream xslFileInput) { List<List<String>> cellVectorHolder = new Vector<List<String>>(); try {// ww w .ja va 2 s .c om POIFSFileSystem fileSystem = new POIFSFileSystem(xslFileInput); HSSFWorkbook workBook = new HSSFWorkbook(fileSystem); HSSFSheet sheet = workBook.getSheetAt(0); Iterator<Row> rowIter = sheet.rowIterator(); while (rowIter.hasNext()) { HSSFRow myRow = (HSSFRow) rowIter.next(); List<String> cellStoreVector = new Vector<String>(); // take care of blank cell ! // @see http://stackoverflow.com/questions/4929646/how-to-get-an-excel-blank-cell-value-in-apache-poi int max = myRow.getLastCellNum(); for (int i = 0; i < max; i++) { HSSFCell myCell = (HSSFCell) myRow.getCell(i, Row.CREATE_NULL_AS_BLANK); if (Cell.CELL_TYPE_STRING == myCell.getCellType()) cellStoreVector.add(myCell.getStringCellValue()); else if ((Cell.CELL_TYPE_NUMERIC == myCell.getCellType())) cellStoreVector.add(Long.toString(new Double(myCell.getNumericCellValue()).longValue())); else if ((Cell.CELL_TYPE_BLANK == myCell.getCellType())) cellStoreVector.add(""); else { logger.debug("This cell is not numeric or string ... : " + myCell + " \n ... cellType : " + myCell.getCellType()); cellStoreVector.add(""); } } cellVectorHolder.add(cellStoreVector); } } catch (Exception e) { logger.error("Error during parsing the XSL File", e); throw new RuntimeException("Error during parsing the XSL File", e); } return cellVectorHolder; }
From source file:framework.retrieval.engine.index.create.impl.file.parse.ExcelFileContentParser.java
License:Apache License
public String getContent(RFileDocument document, String charsetName) { InputStream fileInputStream = null; StringBuffer content = new StringBuffer(); try {/*from ww w . j a v a 2 s. co m*/ fileInputStream = new FileInputStream(document.getFile()); HSSFWorkbook workbook = new HSSFWorkbook(fileInputStream);// Excel if (workbook != null) { int numSheetsNumber = workbook.getNumberOfSheets(); for (int numSheets = 0; numSheets < numSheetsNumber; numSheets++) { HSSFSheet aSheet = workbook.getSheetAt(numSheets);// sheet if (aSheet != null) { int lastRowNum = aSheet.getLastRowNum(); for (int rowNumOfSheet = 0; rowNumOfSheet <= lastRowNum; rowNumOfSheet++) { HSSFRow aRow = aSheet.getRow(rowNumOfSheet); // if (aRow != null) { int lastCellNum = aRow.getLastCellNum(); for (int cellNumOfRow = 0; cellNumOfRow <= lastCellNum; cellNumOfRow++) { HSSFCell aCell = aRow.getCell(cellNumOfRow);// if (aCell != null) { int cellType = aCell.getCellType(); if (cellType == HSSFCell.CELL_TYPE_STRING) { String value = StringClass.getString(aCell.getStringCellValue()); content.append(value); } } } } } } } } } catch (Exception e) { RetrievalUtil.errorLog(log, document.getFile().getAbsolutePath(), e); } finally { if (fileInputStream != null) { try { fileInputStream.close(); } catch (Exception e) { } } } return content.toString(); }
From source file:gov.nih.nci.cabig.caaers.dataimport.AgentSpecificTermsImporter.java
License:BSD License
public Map<String, Object> importFile() throws Exception { POIFSFileSystem poifs;//w w w . j av a 2 s . co m HSSFWorkbook wb; HSSFSheet sh = null; boolean isExcel = file.getName().endsWith(".xls"); boolean isCSV = file.getName().endsWith(".csv"); Map<String, Object> results = new HashMap<String, Object>(); int rowCount = 0; int columnsCount = 0; Map<String, Agent> agents = new HashMap<String, Agent>(); Map<String, Agent> missingAgents = new HashMap<String, Agent>(); Set<String> missingTerms = new HashSet<String>(); Map<String, String> asaelCache = new HashMap<String, String>(); int asael; // wipe out the table agentSpecificTermDao.deleteAll(); studyDao.deleteAllExpectedTerms(); // if (true) return null; // get needed headers if (isExcel) { poifs = new POIFSFileSystem(new FileInputStream(file)); wb = new HSSFWorkbook(poifs); sh = wb.getSheetAt(0); rowCount = sh.getLastRowNum(); columnsCount = sh.getRow(0).getLastCellNum(); for (byte i = 0; i < columnsCount; i++) { HSSFCell cell = sh.getRow(0).getCell(i); if (headers.containsKey(cell.getStringCellValue())) { headers.remove(cell.getStringCellValue()); headers.put(cell.getStringCellValue(), Short.valueOf(i)); } } } InputStream ir = null; Reader r = null; BufferedReader br = null; if (isCSV) { // readLines rowCount = 0; ir = new FileInputStream(file); r = new InputStreamReader(ir); br = new BufferedReader(r); String s = br.readLine(); while (s != null) { if (rowCount == 0) { String[] _s = s.split("[\\|]{1}"); for (byte j = 0; j < _s.length; j++) { // System.out.println(_s[j]); if (headers.containsKey(_s[j])) { headers.remove(_s[j]); headers.put(_s[j], Short.valueOf(j)); } } } rowCount++; s = br.readLine(); } br.close(); r.close(); ir.close(); ir = new FileInputStream(file); r = new InputStreamReader(ir); br = new BufferedReader(r); } /* System.out.println(rowCount); for (Map.Entry e : headers.entrySet()) { System.out.println(e.getKey() + "=>" + e.getValue()); } */ agents.clear(); missingTerms.clear(); missingAgents.clear(); asael = 0; int duplicateAgentTerms = 0; // String nsc = ""; String ctcae_category = ""; String ctcae_version = "0.0"; String ae_term = ""; String other_toxicity = ""; // Loading ASAE list // if (true) { return null; } int i = 1; while (i <= rowCount) { nsc = ""; if (isExcel) { HSSFRow row = sh.getRow(i); if (row != null) { nsc = getCellData("", i, row.getCell((short) headers.get("NSC"))); ctcae_category = getCellData("", i, row.getCell((short) headers.get("CTCAE_CATEGORY"))); ctcae_version = getCellData("", i, row.getCell((short) headers.get("CTCAE_VERSION"))); ae_term = getCellData("", i, row.getCell((short) headers.get("AE_TERM"))); other_toxicity = getCellData("", i, row.getCell((short) headers.get("OTHER_TOXICITY"))); } } else { String s; s = br.readLine(); if (s != null) { String[] _s = s.split("[\\|]{1}"); if (i > 1 && _s.length > 1) { nsc = _s[headers.get("NSC")]; ctcae_category = _s[headers.get("CTCAE_CATEGORY")]; try { ctcae_version = _s[headers.get("CTCAE_VERSION")].trim(); } catch (NumberFormatException e) { // System.out.println(s); return null; } ae_term = _s[headers.get("AE_TERM")]; if (_s.length - 1 >= headers.get("OTHER_TOXICITY")) other_toxicity = _s[headers.get("OTHER_TOXICITY")]; else other_toxicity = ""; } } } if (nsc.trim().equals("")) { i++; continue; } else { // System.out.println(String.format("%s). NSC:%s, V:%s, C:%s, T:%s", i, nsc, ctcae_version, ctcae_category, ae_term)); } Agent a = agents.get(nsc); if (a == null) { a = agentDao.getByNscNumber(nsc); // System.out.println(asael + ". OK. Found agent [" + a.getName() + "] for NSC: [" + nsc + "]"); agents.put(nsc, a); } if (a != null) { AgentSpecificCtcTerm t = new AgentSpecificCtcTerm(); t.setAgent(a); t.setOtherToxicity(other_toxicity); List<CtcTerm> list = terminologyRepository.getCtcTerm(ctcae_category, ctcae_version, ae_term); if (list.size() == 0) { // System.out.println("<ERROR>: Term not found: " + ae_term + ", Category: " + ctcae_category + ", CTCAE Version: " + ctcae_version); missingTerms.add("Term not found: " + ae_term + ", Category: " + ctcae_category + ", CTCAE Version: " + ctcae_version); } else { t.setCtcTerm(list.get(0)); if (persistASAE(t)) asael++; else duplicateAgentTerms++; } agentSpecificTermDao.evict(t); } else { if (!missingAgents.containsKey(nsc)) { // System.out.println("<ERROR>: The agent was not found by its NSC: " + nsc); missingAgents.put(nsc, null); } } i++; } if (isCSV) { br.close(); r.close(); ir.close(); } results.put(KEY_MISSING_TERMS, missingTerms); results.put(KEY_PROCESSED_AGENTS, agents.size() - missingAgents.size()); results.put(KEY_PROCESSED_AGENTTERMS, asael); results.put(KEY_MISSING_AGENTS, missingAgents); results.put(KEY_DUPLICATE_AGENT_TERMS, duplicateAgentTerms); return results; }
From source file:gov.nih.nci.cabig.caaers.dataimport.AgentSpecificTermsImporter.java
License:BSD License
private String getCellData(String sheetname, int rowNum, HSSFCell cell) { if (cell == null) return ""; int cellType = cell.getCellType(); if (cellType == 0) { if (cell.getNumericCellValue() == 0) return ""; return (Integer.toString((int) cell.getNumericCellValue())).trim(); } else if (cellType == 1) { return cell.getStringCellValue().trim(); } else {/*from w w w . j a v a 2s . c o m*/ return ""; } }
From source file:gov.nih.nci.cabig.caaers.tools.ExcelProcessor.java
License:BSD License
private String getCellData(String sheetname, int rowNum, HSSFCell cell) { if (cell == null) throw new CaaersSystemException("Invalid data or Blank cell at following location: \n Sheet: " + sheetname + "\n Row: " + (rowNum + 1)); int cellType = cell.getCellType(); if (cellType == 0) { if (cell.getNumericCellValue() == 0) throw new CaaersSystemException("Invalid data or Blank cell at following location: \n Sheet: " + sheetname + "\n Row: " + (rowNum + 1) + "\n Cell: " + ((cell.getCellNum()) + 1)); return (Integer.toString((int) cell.getNumericCellValue())).trim(); } else if (cellType == 1) { if (cell.getStringCellValue().equals("")) throw new CaaersSystemException("Invalid data or Blank cell at following location: \n Sheet: " + sheetname + "\n Row: " + (rowNum + 1) + "\n Cell: " + ((cell.getCellNum()) + 1)); return cell.getStringCellValue().trim(); } else {/*from w ww . jav a 2 s .c o m*/ throw new CaaersSystemException("Invalid data or Blank cell at following location: \n Sheet: " + sheetname + "\n Row: " + (rowNum + 1) + "\n Cell: " + ((cell.getCellNum()) + 1)); } }
From source file:gov.nih.nci.evs.browser.utils.ExcelUtil.java
License:Open Source License
public static String getHSSFHeader(String file, int sheet) { StringBuffer buf = new StringBuffer(); try {//ww w . j a v a2 s . com FileInputStream fis = new FileInputStream(new File(file)); //Get the workbook instance for XLS file HSSFWorkbook workbook = new HSSFWorkbook(fis); try { fis.close(); } catch (Exception ex) { ex.printStackTrace(); } //Get first sheet from the workbook HSSFSheet hSSFSheet = workbook.getSheetAt(sheet); HSSFRow row = hSSFSheet.getRow(0); int cells = row.getPhysicalNumberOfCells(); for (int c = 0; c < cells; c++) { HSSFCell cell = row.getCell(c); String value = null; switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_FORMULA: value = cell.getCellFormula(); break; case HSSFCell.CELL_TYPE_NUMERIC: value = "" + cell.getNumericCellValue(); break; case HSSFCell.CELL_TYPE_STRING: value = cell.getStringCellValue(); break; default: } buf.append(value); if (c < cells - 1) { buf.append("|"); } } } catch (Exception ex) { ex.printStackTrace(); } return buf.toString(); }
From source file:gov.nih.nci.evs.browser.utils.ResolvedValueSetIteratorHolder.java
License:Open Source License
private void table(final HSSFSheet sheet, int startIndex, int col, String code, boolean cdisc) { resolvedValueSetList = new ArrayList(); if (sheet == null) { return;//from w ww. j a v a 2s .com } if (sheet.getDrawingPatriarch() != null) { final List<HSSFShape> shapes = sheet.getDrawingPatriarch().getChildren(); for (int i = 0; i < shapes.size(); ++i) { if (shapes.get(i) instanceof HSSFPicture) { try { // Gain access to private field anchor. final HSSFShape pic = shapes.get(i); final Field f = HSSFShape.class.getDeclaredField("anchor"); f.setAccessible(true); final HSSFClientAnchor anchor = (HSSFClientAnchor) f.get(pic); // Store picture cell row, column and picture data. if (!pix.containsKey(anchor.getRow1())) { pix.put(anchor.getRow1(), new HashMap<Short, List<HSSFPictureData>>()); } if (!pix.get(anchor.getRow1()).containsKey(anchor.getCol1())) { pix.get(anchor.getRow1()).put(anchor.getCol1(), new ArrayList<HSSFPictureData>()); } pix.get(anchor.getRow1()).get(anchor.getCol1()) .add(book.getAllPictures().get(((HSSFPicture) pic).getPictureIndex())); } catch (final Exception e) { throw new RuntimeException(e); } } } } out.append("<table id=\"" + "rvs_table" + "\" width=\"915\" class=\"mt\">\n"); tr(sheet.getRow(0)); StringBuffer buf = new StringBuffer(); tr(sheet.getRow(0), buf); String t = buf.toString(); resolvedValueSetList.add(t); int rows = sheet.getPhysicalNumberOfRows(); for (int i = startIndex; i <= rows; i++) { HSSFRow row = sheet.getRow(i); if (row != null) { if (col != -1) { HSSFCell cell = row.getCell(col); if (cell != null) { String value = null; switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_FORMULA: value = cell.getCellFormula(); break; case HSSFCell.CELL_TYPE_NUMERIC: value = "" + cell.getNumericCellValue(); break; case HSSFCell.CELL_TYPE_STRING: value = cell.getStringCellValue(); break; default: } if ((cdisc && i == startIndex) || (value != null && value.compareTo(code) == 0)) { tr(row); buf = new StringBuffer(); tr(row, buf); t = buf.toString(); resolvedValueSetList.add(t); } } } else { tr(row); buf = new StringBuffer(); tr(row, buf); t = buf.toString(); resolvedValueSetList.add(t); } } } out.append("</table>\n"); resolvedValueSetIterator = resolvedValueSetList.listIterator(); }
From source file:gov.nih.nci.evs.browser.utils.ResolvedValueSetIteratorHolder.java
License:Open Source License
/** * (Each Excel sheet cell becomes an HTML table cell) Generates an HTML * table cell which has the same font styles, alignments, colours and * borders as the Excel cell.//w ww. j a v a 2 s . c o m * * @param cell * The Excel cell. */ private void td(final HSSFCell cell) { int colspan = 1; if (colIndex == mergeStart) { // First cell in the merging region - set colspan. colspan = mergeEnd - mergeStart + 1; } else if (colIndex == mergeEnd) { // Last cell in the merging region - no more skipped cells. mergeStart = -1; mergeEnd = -1; return; } else if (mergeStart != -1 && mergeEnd != -1 && colIndex > mergeStart && colIndex < mergeEnd) { // Within the merging region - skip the cell. return; } //KLO 05022018 //out.append("<td "); out.append("<td height=\"15\" "); if (colspan > 1) { out.append("colspan='").append(colspan).append("' "); } if (cell == null) { out.append("/>\n"); return; } out.append("style='"); final HSSFCellStyle style = cell.getCellStyle(); // Text alignment switch (style.getAlignment()) { case CellStyle.ALIGN_LEFT: out.append("text-align: left; "); break; case CellStyle.ALIGN_RIGHT: out.append("text-align: right; "); break; case CellStyle.ALIGN_CENTER: out.append("text-align: center; "); break; default: break; } // Font style, size and weight final HSSFFont font = style.getFont(book); if (font == null) return; if (font.getBoldweight() == HSSFFont.BOLDWEIGHT_BOLD) { out.append("font-weight: bold; "); } if (font.getItalic()) { out.append("font-style: italic; "); } if (font.getUnderline() != HSSFFont.U_NONE) { out.append("text-decoration: underline; "); } out.append("font-size: ").append(Math.floor(font.getFontHeightInPoints() * 0.8)).append("pt; "); // Cell background and font colours final short[] backRGB = style.getFillForegroundColorColor().getTriplet(); final HSSFColor foreColor = palette.getColor(font.getColor()); if (foreColor != null) { final short[] foreRGB = foreColor.getTriplet(); if (foreRGB[0] != 0 || foreRGB[1] != 0 || foreRGB[2] != 0) { out.append("color: rgb(").append(foreRGB[0]).append(',').append(foreRGB[1]).append(',') .append(foreRGB[2]).append(");"); } } if (backRGB[0] != 0 || backRGB[1] != 0 || backRGB[2] != 0) { out.append("background-color: rgb(").append(backRGB[0]).append(',').append(backRGB[1]).append(',') .append(backRGB[2]).append(");"); } // Border if (style.getBorderTop() != HSSFCellStyle.BORDER_NONE) { out.append("border-top-style: solid; "); } if (style.getBorderRight() != HSSFCellStyle.BORDER_NONE) { out.append("border-right-style: solid; "); } if (style.getBorderBottom() != HSSFCellStyle.BORDER_NONE) { out.append("border-bottom-style: solid; "); } if (style.getBorderLeft() != HSSFCellStyle.BORDER_NONE) { out.append("border-left-style: solid; "); } out.append("'>"); String val = ""; try { switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_STRING: val = cell.getStringCellValue(); break; case HSSFCell.CELL_TYPE_NUMERIC: // POI does not distinguish between integer and double, thus: final double original = cell.getNumericCellValue(), rounded = Math.round(original); if (Math.abs(rounded - original) < 0.00000000000000001) { val = String.valueOf((int) rounded); } else { val = String.valueOf(original); } break; case HSSFCell.CELL_TYPE_FORMULA: final CellValue cv = evaluator.evaluate(cell); if (cv == null) return; switch (cv.getCellType()) { case Cell.CELL_TYPE_BOOLEAN: out.append(cv.getBooleanValue()); break; case Cell.CELL_TYPE_NUMERIC: out.append(cv.getNumberValue()); break; case Cell.CELL_TYPE_STRING: out.append(cv.getStringValue()); break; case Cell.CELL_TYPE_BLANK: break; case Cell.CELL_TYPE_ERROR: break; default: break; } break; default: // Neither string or number? Could be a date. try { val = sdf.format(cell.getDateCellValue()); } catch (final Exception e1) { } } } catch (final Exception e) { val = e.getMessage(); } if ("null".equals(val)) { val = ""; } if (pix.containsKey(rowIndex)) { if (pix.get(rowIndex).containsKey(colIndex)) { for (final HSSFPictureData pic : pix.get(rowIndex).get(colIndex)) { out.append("<img alt='Image in Excel sheet' src='data:"); out.append(pic.getMimeType()); out.append(";base64,"); try { out.append(new String(Base64.encodeBase64(pic.getData()), "US-ASCII")); } catch (final UnsupportedEncodingException e) { throw new RuntimeException(e); } out.append("'/>"); } } } if (isCode(val) && this.URL != null) { val = getHyperLink(val); } out.append(val); out.append("</td>\n"); }
From source file:gov.nih.nci.evs.browser.utils.ResolvedValueSetIteratorHolder.java
License:Open Source License
private void td(final HSSFCell cell, StringBuffer buf) { int colspan = 1; if (colIndex == mergeStart) { // First cell in the merging region - set colspan. colspan = mergeEnd - mergeStart + 1; } else if (colIndex == mergeEnd) { // Last cell in the merging region - no more skipped cells. mergeStart = -1;/* ww w. j av a 2 s .com*/ mergeEnd = -1; return; } else if (mergeStart != -1 && mergeEnd != -1 && colIndex > mergeStart && colIndex < mergeEnd) { // Within the merging region - skip the cell. return; } //KLO 05022018 //buf.append("<td "); buf.append("<td height=\"15\" "); if (colspan > 1) { buf.append("colspan='").append(colspan).append("' "); } if (cell == null) { buf.append("/>"); return; } buf.append("style='"); final HSSFCellStyle style = cell.getCellStyle(); // Text alignment switch (style.getAlignment()) { case CellStyle.ALIGN_LEFT: buf.append("text-align: left; "); break; case CellStyle.ALIGN_RIGHT: buf.append("text-align: right; "); break; case CellStyle.ALIGN_CENTER: buf.append("text-align: center; "); break; default: break; } // Font style, size and weight final HSSFFont font = style.getFont(book); if (font == null) return; if (font.getBoldweight() == HSSFFont.BOLDWEIGHT_BOLD) { buf.append("font-weight: bold; "); } if (font.getItalic()) { buf.append("font-style: italic; "); } if (font.getUnderline() != HSSFFont.U_NONE) { buf.append("text-decoration: underline; "); } buf.append("font-size: ").append(Math.floor(font.getFontHeightInPoints() * 0.8)).append("pt; "); // Cell background and font colours final short[] backRGB = style.getFillForegroundColorColor().getTriplet(); final HSSFColor foreColor = palette.getColor(font.getColor()); if (foreColor != null) { final short[] foreRGB = foreColor.getTriplet(); if (foreRGB[0] != 0 || foreRGB[1] != 0 || foreRGB[2] != 0) { buf.append("color: rgb(").append(foreRGB[0]).append(',').append(foreRGB[1]).append(',') .append(foreRGB[2]).append(");"); } } if (backRGB[0] != 0 || backRGB[1] != 0 || backRGB[2] != 0) { buf.append("background-color: rgb(").append(backRGB[0]).append(',').append(backRGB[1]).append(',') .append(backRGB[2]).append(");"); } // Border if (style.getBorderTop() != HSSFCellStyle.BORDER_NONE) { buf.append("border-top-style: solid; "); } if (style.getBorderRight() != HSSFCellStyle.BORDER_NONE) { buf.append("border-right-style: solid; "); } if (style.getBorderBottom() != HSSFCellStyle.BORDER_NONE) { buf.append("border-bottom-style: solid; "); } if (style.getBorderLeft() != HSSFCellStyle.BORDER_NONE) { buf.append("border-left-style: solid; "); } buf.append("'>"); String val = ""; try { switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_STRING: val = cell.getStringCellValue(); break; case HSSFCell.CELL_TYPE_NUMERIC: // POI does not distinguish between integer and double, thus: final double original = cell.getNumericCellValue(), rounded = Math.round(original); if (Math.abs(rounded - original) < 0.00000000000000001) { val = String.valueOf((int) rounded); } else { val = String.valueOf(original); } break; case HSSFCell.CELL_TYPE_FORMULA: final CellValue cv = evaluator.evaluate(cell); if (cv == null) return; switch (cv.getCellType()) { case Cell.CELL_TYPE_BOOLEAN: buf.append(cv.getBooleanValue()); break; case Cell.CELL_TYPE_NUMERIC: buf.append(cv.getNumberValue()); break; case Cell.CELL_TYPE_STRING: buf.append(cv.getStringValue()); break; case Cell.CELL_TYPE_BLANK: break; case Cell.CELL_TYPE_ERROR: break; default: break; } break; default: // Neither string or number? Could be a date. try { val = sdf.format(cell.getDateCellValue()); } catch (final Exception e1) { } } } catch (final Exception e) { val = e.getMessage(); } if ("null".equals(val)) { val = ""; } if (pix.containsKey(rowIndex)) { if (pix.get(rowIndex).containsKey(colIndex)) { for (final HSSFPictureData pic : pix.get(rowIndex).get(colIndex)) { buf.append("<img alt='Image in Excel sheet' src='data:"); buf.append(pic.getMimeType()); buf.append(";base64,"); try { buf.append(new String(Base64.encodeBase64(pic.getData()), "US-ASCII")); } catch (final UnsupportedEncodingException e) { throw new RuntimeException(e); } buf.append("'/>"); } } } if (isCode(val) && this.URL != null) { val = getHyperLink(val); } buf.append(val); buf.append("</td>"); }