List of usage examples for org.apache.poi.hssf.usermodel HSSFFont BOLDWEIGHT_BOLD
short BOLDWEIGHT_BOLD
To view the source code for org.apache.poi.hssf.usermodel HSSFFont BOLDWEIGHT_BOLD.
Click Source Link
From source file:gov.guilin.ExcelView.java
License:Open Source License
/** * ?Excel/*from w w w .j a v a 2s .c o m*/ * * @param model * ? * @param workbook * workbook * @param request * request * @param response * response */ public void buildExcelDocument(Map<String, Object> model, HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse response) throws Exception { Assert.notEmpty(properties); HSSFSheet sheet; if (StringUtils.isNotEmpty(sheetName)) { sheet = workbook.createSheet(sheetName); } else { sheet = workbook.createSheet(); } int rowNumber = 0; if (titles != null && titles.length > 0) { HSSFRow header = sheet.createRow(rowNumber); header.setHeight((short) 400); for (int i = 0; i < properties.length; i++) { HSSFCell cell = header.createCell(i); HSSFCellStyle cellStyle = workbook.createCellStyle(); cellStyle.setFillForegroundColor(HSSFColor.LIGHT_CORNFLOWER_BLUE.index); cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); HSSFFont font = workbook.createFont(); font.setFontHeightInPoints((short) 11); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); cellStyle.setFont(font); cell.setCellStyle(cellStyle); if (i == 0) { HSSFPatriarch patriarch = sheet.createDrawingPatriarch(); HSSFComment comment = patriarch .createComment(new HSSFClientAnchor(0, 0, 0, 0, (short) 1, 1, (short) 4, 4)); comment.setString(new HSSFRichTextString("P" + "o" + "w" + "e" + "r" + "e" + "d" + " " + "B" + "y" + " " + "S" + "H" + "O" + "P" + "+" + "+")); cell.setCellComment(comment); } if (titles.length > i && titles[i] != null) { cell.setCellValue(titles[i]); } else { cell.setCellValue(properties[i]); } if (widths != null && widths.length > i && widths[i] != null) { sheet.setColumnWidth(i, widths[i]); } else { sheet.autoSizeColumn(i); } } rowNumber++; } if (data != null) { for (Object item : data) { HSSFRow row = sheet.createRow(rowNumber); for (int i = 0; i < properties.length; i++) { HSSFCell cell = row.createCell(i); if (converters != null && converters.length > i && converters[i] != null) { Class<?> clazz = PropertyUtils.getPropertyType(item, properties[i]); ConvertUtils.register(converters[i], clazz); cell.setCellValue(BeanUtils.getProperty(item, properties[i])); ConvertUtils.deregister(clazz); if (clazz.equals(Date.class)) { DateConverter dateConverter = new DateConverter(); dateConverter.setPattern(DEFAULT_DATE_PATTERN); ConvertUtils.register(dateConverter, Date.class); } } else { cell.setCellValue(BeanUtils.getProperty(item, properties[i])); } if (rowNumber == 0 || rowNumber == 1) { if (widths != null && widths.length > i && widths[i] != null) { sheet.setColumnWidth(i, widths[i]); } else { sheet.autoSizeColumn(i); } } } rowNumber++; } } if (contents != null && contents.length > 0) { rowNumber++; for (String content : contents) { HSSFRow row = sheet.createRow(rowNumber); HSSFCell cell = row.createCell(0); HSSFCellStyle cellStyle = workbook.createCellStyle(); HSSFFont font = workbook.createFont(); font.setColor(HSSFColor.GREY_50_PERCENT.index); cellStyle.setFont(font); cell.setCellStyle(cellStyle); cell.setCellValue(content); rowNumber++; } } response.setContentType("application/force-download"); if (StringUtils.isNotEmpty(filename)) { response.setHeader("Content-disposition", "attachment; filename=" + URLEncoder.encode(filename, "UTF-8")); } else { response.setHeader("Content-disposition", "attachment"); } }
From source file:gov.nih.nci.cananolab.service.publication.impl.PublicationExporter.java
License:BSD License
/** * Output Excel report for sample publication summary report. * * @param summaryBean/*from w w w . ja v a2 s . co m*/ * @param wb */ private static void exportSummarySheet(PublicationSummaryViewBean summaryBean, HSSFWorkbook wb) { HSSFRow row = null; HSSFFont headerFont = wb.createFont(); headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); HSSFCellStyle headerStyle = wb.createCellStyle(); headerStyle.setFont(headerFont); Set<String> categories = summaryBean.getPublicationCategories(); if (categories != null && !categories.isEmpty()) { for (String category : categories) { int rowIndex = 0; // Create one work sheet for each category. HSSFSheet sheet = wb.createSheet(category); row = sheet.createRow(rowIndex++); // Output header of report ExportUtils.createCell(row, 0, headerStyle, BIBLIOBRAPHY_INFO); ExportUtils.createCell(row, 1, headerStyle, RESEARCH_CATEGORY); ExportUtils.createCell(row, 2, headerStyle, DESCRIPTION); ExportUtils.createCell(row, 3, headerStyle, PUB_STATUS); // Output data of report SortedMap<String, List<PublicationBean>> pubs = summaryBean.getCategory2Publications(); if (pubs != null && !pubs.isEmpty()) { List<PublicationBean> pubBeans = pubs.get(category); if (pubBeans != null && !pubBeans.isEmpty()) { for (PublicationBean pubBean : pubBeans) { Publication pub = (Publication) pubBean.getDomainFile(); row = sheet.createRow(rowIndex++); // Bibliography Info: cell index = 0. ExportUtils.createCell(row, 0, getBibliographyInfo(pubBean)); // Research Category: cell index = 1. ExportUtils.createCell(row, 1, pub.getResearchArea()); // Description: cell index = 2. if (!StringUtils.isEmpty(pub.getDescription())) { ExportUtils.createCell(row, 2, pub.getDescription()); } // Publication Status: cell index = 3. ExportUtils.createCell(row, 3, pub.getStatus()); } } } } } }
From source file:gov.nih.nci.cananolab.service.publication.impl.PublicationExporter.java
License:BSD License
private static int setDetailSheet(PublicationBean aPub, HSSFWorkbook wb, HSSFSheet sheet, HSSFPatriarch patriarch, int rowIndex) { HSSFFont headerFont = wb.createFont(); headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); HSSFCellStyle headerStyle = wb.createCellStyle(); headerStyle.setFont(headerFont);/*from ww w. j av a 2s. c o m*/ Publication publication = (Publication) aPub.getDomainFile(); HSSFRow row = null; HSSFCell cell = null; // PubMedID Long pubMedId = publication.getPubMedId(); row = sheet.createRow(rowIndex++); int cellIndex = 0; cell = row.createCell(cellIndex++); cell.setCellStyle(headerStyle); cell.setCellValue(new HSSFRichTextString("Publication Identifier")); if (pubMedId != null && pubMedId.intValue() > 0) { row.createCell(cellIndex++).setCellValue(new HSSFRichTextString(pubMedId.toString())); } else { String oid = publication.getDigitalObjectId(); if (!StringUtils.isEmpty(oid)) { row.createCell(cellIndex++).setCellValue(new HSSFRichTextString(oid)); } else { // row.createCell(cellIndex++).setCellValue( // new HSSFRichTextString("")); } } // publication type row = sheet.createRow(rowIndex++); cellIndex = 0; cell = row.createCell(cellIndex++); cell.setCellStyle(headerStyle); cell.setCellValue(new HSSFRichTextString("Publication Type")); row.createCell(cellIndex++).setCellValue(new HSSFRichTextString(publication.getCategory())); // publication status row = sheet.createRow(rowIndex++); cellIndex = 0; cell = row.createCell(cellIndex++); cell.setCellStyle(headerStyle); cell.setCellValue(new HSSFRichTextString(PUB_STATUS)); row.createCell(cellIndex++).setCellValue(new HSSFRichTextString(publication.getStatus())); // Authors String rowHeader = "Authors"; StringBuffer sb = new StringBuffer(); if (publication.getAuthorCollection() != null) { List<Author> authorslist = new ArrayList<Author>(publication.getAuthorCollection()); Collections.sort(authorslist, new Comparator<Author>() { public int compare(Author o1, Author o2) { return (int) (o1.getCreatedDate().compareTo(o2.getCreatedDate())); } }); for (Author author : authorslist) { sb.append(author.getFirstName()); sb.append(' '); sb.append(author.getInitial()); sb.append(' '); sb.append(author.getLastName()); row = sheet.createRow(rowIndex++); cellIndex = 0; cell = row.createCell(cellIndex++); cell.setCellStyle(headerStyle); cell.setCellValue(new HSSFRichTextString(rowHeader)); row.createCell(cellIndex++).setCellValue(new HSSFRichTextString(sb.toString())); rowHeader = ""; sb.setLength(0); } } // research area row = sheet.createRow(rowIndex++); cellIndex = 0; cell = row.createCell(cellIndex++); cell.setCellStyle(headerStyle); cell.setCellValue(new HSSFRichTextString(RESEARCH_CATEGORY)); row.createCell(cellIndex++).setCellValue(new HSSFRichTextString(publication.getResearchArea())); // Title row = sheet.createRow(rowIndex++); cellIndex = 0; cell = row.createCell(cellIndex++); cell.setCellStyle(headerStyle); cell.setCellValue(new HSSFRichTextString("Title")); row.createCell(cellIndex++).setCellValue(new HSSFRichTextString(publication.getTitle())); // Journal row = sheet.createRow(rowIndex++); cellIndex = 0; cell = row.createCell(cellIndex++); cell.setCellStyle(headerStyle); cell.setCellValue(new HSSFRichTextString("Journal")); row.createCell(cellIndex++).setCellValue(new HSSFRichTextString(publication.getJournalName())); // Year row = sheet.createRow(rowIndex++); cellIndex = 0; cell = row.createCell(cellIndex++); cell.setCellStyle(headerStyle); cell.setCellValue(new HSSFRichTextString("Year")); int year = 0; if (publication.getYear() != null) year = publication.getYear(); if (year > 0) { row.createCell(cellIndex++).setCellValue(new HSSFRichTextString(Integer.toString(year))); } // Volume row = sheet.createRow(rowIndex++); cellIndex = 0; cell = row.createCell(cellIndex++); cell.setCellStyle(headerStyle); cell.setCellValue(new HSSFRichTextString("Volume")); row.createCell(cellIndex++).setCellValue(new HSSFRichTextString(publication.getVolume())); // Pages row = sheet.createRow(rowIndex++); cellIndex = 0; cell = row.createCell(cellIndex++); cell.setCellStyle(headerStyle); cell.setCellValue(new HSSFRichTextString("Pages")); String startPage = publication.getStartPage(); String endPage = publication.getEndPage(); if ((!StringUtils.isEmpty(startPage)) || (!StringUtils.isEmpty(endPage))) { row.createCell(cellIndex++).setCellValue(new HSSFRichTextString(publication.getJournalName())); } // Description row = sheet.createRow(rowIndex++); cellIndex = 0; cell = row.createCell(cellIndex++); cell.setCellStyle(headerStyle); cell.setCellValue(new HSSFRichTextString(DESCRIPTION)); row.createCell(cellIndex++).setCellValue(new HSSFRichTextString(publication.getDescription())); // Uploaded Publication URI row = sheet.createRow(rowIndex++); cellIndex = 0; cell = row.createCell(cellIndex++); cell.setCellStyle(headerStyle); cell.setCellValue(new HSSFRichTextString("Publication URI")); row.createCell(cellIndex++).setCellValue(new HSSFRichTextString(publication.getUri())); return rowIndex; }
From source file:gov.nih.nci.cananolab.service.sample.impl.CharacterizationExporter.java
License:BSD License
/** * Output Sample Characterization Summary report (==> * bodyCharacterizationSummaryPrintViewTable.jsp) * * @param summaryBean/* w ww. ja v a 2s. c o m*/ * @param wb * @throws IOException */ private static void outputSummarySheet(List<String> charTypes, CharacterizationSummaryViewBean summaryBean, String downloadURL, HSSFWorkbook wb) throws IOException { HSSFFont headerFont = wb.createFont(); headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); HSSFCellStyle headerStyle = wb.createCellStyle(); headerStyle.setFont(headerFont); HSSFCellStyle hlinkStyle = wb.createCellStyle(); HSSFFont hlinkFont = wb.createFont(); hlinkFont.setUnderline(HSSFFont.U_SINGLE); hlinkFont.setColor(HSSFColor.BLUE.index); hlinkStyle.setFont(hlinkFont); int charCount = 1; Map<String, SortedSet<CharacterizationBean>> charBeanMap = summaryBean.getType2Characterizations(); for (String type : charTypes) { // Output data of report SortedSet<CharacterizationBean> charBeans = charBeanMap.get(type); if (charBeans != null && !charBeans.isEmpty()) { for (CharacterizationBean charBean : charBeans) { int rowIndex = 0; // Create one work sheet for each Characterization. HSSFSheet sheet = wb.createSheet(charCount++ + "." + charBean.getCharacterizationName()); HSSFPatriarch patriarch = sheet.createDrawingPatriarch(); // 1. Output Characterization type at (0, 0). rowIndex = outputHeader(charBean, sheet, headerStyle, rowIndex); // 2. Output Assay Type (2, 0). rowIndex = outputAssayType(charBean, sheet, headerStyle, rowIndex); // 3. Output POC at (3, 0). rowIndex = outputPOC(charBean, sheet, headerStyle, rowIndex); // 4. Output Characterization Date at (4, 0). rowIndex = outputCharDate(charBean, sheet, headerStyle, rowIndex); // 5. Output Protocol at (5, 0). rowIndex = outputProtocol(charBean, sheet, headerStyle, rowIndex); // 6. Output Properties at (6, 0). rowIndex = outputProperties(charBean, sheet, headerStyle, rowIndex); // 7. Output Design Description at (7, 0). rowIndex = outputDesignDescription(charBean, sheet, headerStyle, rowIndex); // 8. Output Technique and Instruments at (8, 0). rowIndex = outputTechInstruments(charBean, sheet, headerStyle, rowIndex); // 9. Output Characterization Results at (9, 0). rowIndex = outputCharResults(charBean, downloadURL, wb, sheet, headerStyle, hlinkStyle, patriarch, rowIndex); // 10.Output Analysis and Conclusion at (10, 0). rowIndex = outputConclusion(charBean, sheet, headerStyle, rowIndex); } } } }
From source file:gov.nih.nci.cananolab.service.sample.impl.CompositionExporter.java
License:BSD License
/** * Output sample Composition Summary report => * bodyCompositionSummaryView.jsp// ww w. j a va2s. c o m * * @param compBean * @param wb */ private static void outputSummarySheet(CompositionBean compBean, String downloadURL, HSSFWorkbook wb) throws IOException { HSSFFont headerFont = wb.createFont(); headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); HSSFCellStyle headerStyle = wb.createCellStyle(); headerStyle.setFont(headerFont); HSSFCellStyle hlinkStyle = wb.createCellStyle(); HSSFFont hlinkFont = wb.createFont(); hlinkFont.setUnderline(HSSFFont.U_SINGLE); hlinkFont.setColor(HSSFColor.BLUE.index); hlinkStyle.setFont(hlinkFont); int entityCount = 1; entityCount = outputNanomaterialEntities(compBean, wb, headerStyle, hlinkStyle, entityCount, downloadURL); entityCount = outputFunctionalEntities(compBean, wb, headerStyle, hlinkStyle, entityCount, downloadURL); entityCount = outputChemicalEntities(compBean, wb, headerStyle, hlinkStyle, entityCount, downloadURL); outputFilesEntities(compBean, wb, headerStyle, hlinkStyle, entityCount, downloadURL); }
From source file:gov.nih.nci.cananolab.service.sample.impl.SampleExporter.java
License:BSD License
/** * Output advance sample summary report, representing, * bodyAdvancedSampleSearchResult.jsp//from w w w . j a v a2s . co m * * @param searchBean * @param wb */ private static void outputSummarySheet(AdvancedSampleSearchBean searchBean, List<AdvancedSampleBean> sampleBeans, String viewSampleUrl, HSSFWorkbook wb) throws IOException { HSSFFont headerFont = wb.createFont(); headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); HSSFCellStyle headerStyle = wb.createCellStyle(); headerStyle.setFont(headerFont); HSSFCellStyle hlinkStyle = wb.createCellStyle(); HSSFFont hlinkFont = wb.createFont(); hlinkFont.setUnderline(HSSFFont.U_SINGLE); hlinkFont.setColor(HSSFColor.BLUE.index); hlinkStyle.setFont(hlinkFont); int rowIndex = 0; HSSFSheet sheet = wb.createSheet("Advanced Sample Search Report"); // 1.Output Search Criteria. comment out as per Sharon. // rowIndex = outputCriteria(searchBean, sheet, headerStyle, rowIndex); // 2.Output table column headers. rowIndex = outputHeader(sampleBeans.get(0), sheet, headerStyle, rowIndex); // 3.Output each table row. for (AdvancedSampleBean sampleBean : sampleBeans) { rowIndex = outputRow(sampleBean, viewSampleUrl, sheet, hlinkStyle, rowIndex); } }
From source file:gov.nih.nci.evs.app.neopl.CSVtoExcel.java
License:Open Source License
public void runHSSF(String inputfile) { int size = checkSpecialCharacters(inputfile); int n = inputfile.lastIndexOf("."); String outputfile = getOutputFile(inputfile, "xls"); try {//from w w w .j ava2 s . c o m HSSFWorkbook wb = new HSSFWorkbook(); HSSFCellStyle cellStyle = wb.createCellStyle(); //cellStyle.setFillBackgroundColor(HSSFColor.GREY_25_PERCENT.index); //cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); HSSFFont font = wb.createFont(); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); //font.setColor(HSSFColor.WHITE.index); cellStyle.setFont(font); HSSFCellStyle linkCellStyle = wb.createCellStyle(); //cellStyle.setFillBackgroundColor(HSSFColor.GREY_25_PERCENT.index); //cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); HSSFFont linkfont = wb.createFont(); linkfont.setColor(HSSFColor.LIGHT_BLUE.index); linkCellStyle.setFont(linkfont); //CreationHelper helper = wb.getCreationHelper(); CSVReader reader = new CSVReader(new FileReader(inputfile));//CSV file String[] line; int r = 0; Cell cell = null; //"C7419","Acanthoma","C0846967","Acanthoma","MDR","Acanthoma","10059394","LT" // skip heading HSSFHyperlink url_link = new HSSFHyperlink(HSSFHyperlink.LINK_URL); HSSFSheet sheet = null; int page_num = 1; Row row = null; line = reader.readNext(); int lcv = 0; int row_count = 0; Vector w = new Vector(); while ((line = reader.readNext()) != null) { if (lcv % PAGE_SIZE == 0) { r = 0; String sheetLabel = SHEET_LABEL; if (size > PAGE_SIZE) { sheetLabel = sheetLabel + " (Page " + page_num + ")"; } sheet = wb.createSheet(sheetLabel); for (int j = 0; j < HEADINGS.length; j++) { sheet.autoSizeColumn(j); } row = sheet.createRow((short) r); for (int i = 0; i < HEADINGS.length; i++) { String heading = HEADINGS[i]; cell = row.createCell(i); cell.setCellValue(heading); cell.setCellStyle(cellStyle); } sheet.createFreezePane(0, 1); // this will freeze the header row page_num++; } String s4 = (String) line[4]; if (s4.compareTo("NCI") == 0) { w.add("NCI Line number: " + r); } else if (s4.compareTo("NCI") != 0) { r++; row = sheet.createRow((short) r); row_count++; row = sheet.createRow((short) r); row_count++; for (int i = 0; i < HEADINGS.length; i++) { cell = row.createCell(i); int codeCol = codeColumn[i]; cell.setCellValue(line[i]); if (NCIT_LINK && codeCol == LINK_NCIT) { url_link = new HSSFHyperlink(HSSFHyperlink.LINK_URL); String code = line[i]; url_link.setAddress(getNCItHyperlink(code)); cell.setHyperlink(url_link); cell.setCellStyle(linkCellStyle); } else if (NCIM_LINK && codeCol == LINK_NCIM) { url_link = new HSSFHyperlink(HSSFHyperlink.LINK_URL); String code = line[i]; url_link.setAddress(getNCImHyperlink(code)); cell.setHyperlink(url_link); cell.setCellStyle(linkCellStyle); } else if (SOURCE_LINK && codeCol == LINK_OTHER) { url_link = new HSSFHyperlink(HSSFHyperlink.LINK_URL); String code = line[i]; String source = line[SOURCE_INDEX]; if (localNameMap.containsKey(source)) { url_link.setAddress(getSourceHyperlink(source, code)); cell.setHyperlink(url_link); cell.setCellStyle(linkCellStyle); } } } } lcv++; } // Write the output to a file FileOutputStream fileOut = new FileOutputStream(outputfile); wb.write(fileOut); fileOut.close(); System.out.println("Output file " + outputfile + " generated."); System.out.println("row_count: " + row_count); System.out.println("NCI: " + w.size()); for (int i = 0; i < w.size(); i++) { String t = (String) w.elementAt(i); System.out.println(t); } } catch (Exception ex) { ex.printStackTrace(); } }
From source file:gov.nih.nci.evs.app.neopl.CSVtoExcel.java
License:Open Source License
public void runHSSF(Vector data_vec, String outputfile) { if (codeColumn == null) { setDefault();/* w w w . j a v a2s.c o m*/ } //int size = 0;//checkSpecialCharacters(inputfile); int size = data_vec.size(); String[] line = null; try { HSSFWorkbook wb = new HSSFWorkbook(); HSSFCellStyle cellStyle = wb.createCellStyle(); //cellStyle.setFillBackgroundColor(HSSFColor.GREY_25_PERCENT.index); //cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); HSSFFont font = wb.createFont(); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); //font.setColor(HSSFColor.WHITE.index); cellStyle.setFont(font); HSSFCellStyle linkCellStyle = wb.createCellStyle(); //cellStyle.setFillBackgroundColor(HSSFColor.GREY_25_PERCENT.index); //cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); HSSFFont linkfont = wb.createFont(); linkfont.setColor(HSSFColor.LIGHT_BLUE.index); linkCellStyle.setFont(linkfont); //CreationHelper helper = wb.getCreationHelper(); //CSVReader reader = new CSVReader(new FileReader(inputfile));//CSV file int r = 0; Cell cell = null; //"C7419","Acanthoma","C0846967","Acanthoma","MDR","Acanthoma","10059394","LT" // skip heading HSSFHyperlink url_link = new HSSFHyperlink(HSSFHyperlink.LINK_URL); HSSFSheet sheet = null; int page_num = 1; Row row = null; //line = reader.readNext(); int lcv = 0; int row_count = 0; Vector w = new Vector(); String nextLine = null; Vector values = null; for (int k = 0; k < data_vec.size(); k++) { nextLine = (String) data_vec.elementAt(k); int k1 = k + 1; line = toArray(nextLine); //if (lcv % PAGE_SIZE == 0) { if (lcv == 0) { r = 0; String sheetLabel = SHEET_LABEL; if (size > PAGE_SIZE) { sheetLabel = sheetLabel;// + " (Page " + page_num + ")"; } sheet = wb.createSheet(sheetLabel); for (int j = 0; j < HEADINGS.length; j++) { sheet.autoSizeColumn(j); } row = sheet.createRow((short) r); for (int i = 0; i < HEADINGS.length; i++) { String heading = HEADINGS[i]; cell = row.createCell(i); cell.setCellValue(heading); cell.setCellStyle(cellStyle); } sheet.createFreezePane(0, 1); // this will freeze the header row page_num++; } String s4 = line[4]; if (s4.compareTo("NCI") == 0) { w.add("NCI Line number: " + r); } else { //if (s4.compareTo("NCI") != 0) { r++; row = sheet.createRow((short) r); row_count++; for (int i = 0; i < HEADINGS.length; i++) { cell = row.createCell(i); int codeCol = codeColumn[i]; cell.setCellValue(line[i]); if (NCIT_LINK && codeCol == LINK_NCIT) { url_link = new HSSFHyperlink(HSSFHyperlink.LINK_URL); String code = line[i]; url_link.setAddress(getNCItHyperlink(code)); cell.setHyperlink(url_link); cell.setCellStyle(linkCellStyle); } else if (NCIM_LINK && codeCol == LINK_NCIM) { url_link = new HSSFHyperlink(HSSFHyperlink.LINK_URL); String code = line[i]; url_link.setAddress(getNCImHyperlink(code)); cell.setHyperlink(url_link); cell.setCellStyle(linkCellStyle); } else if (SOURCE_LINK && codeCol == LINK_OTHER) { url_link = new HSSFHyperlink(HSSFHyperlink.LINK_URL); String code = line[i]; String source = line[SOURCE_INDEX]; if (localNameMap.containsKey(source)) { url_link.setAddress(getSourceHyperlink(source, code)); cell.setHyperlink(url_link); cell.setCellStyle(linkCellStyle); } } } } lcv++; } // Write the output to a file FileOutputStream fileOut = new FileOutputStream(outputfile); wb.write(fileOut); fileOut.close(); System.out.println("Output file " + outputfile + " generated."); } catch (Exception ex) { ex.printStackTrace(); } }
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./*from w w w . j a va2s. co 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;/*from w w w . java 2 s . co m*/ 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>"); }