List of usage examples for org.apache.poi.ss.usermodel IndexedColors BLUE
IndexedColors BLUE
To view the source code for org.apache.poi.ss.usermodel IndexedColors BLUE.
Click Source Link
From source file:aco.Utilities.java
License:Open Source License
static void writeResultsExcel(int trialNumber, boolean saveIterCosts) { Row r, r1;//w w w .j a v a 2 s. c o m Cell c; int index1 = 0, index2 = 0, index3 = 0, index4 = 0, index5 = 0; //int index6 = 0; //the file already exists; we should add a new row as the last one in the Excel file if (new File(filePath).canRead()) { //System.out.println("File already exists.."); try { FileInputStream file = new FileInputStream(new File(filePath)); //Create Workbook instance holding reference to .xlsx file XSSFWorkbook workbook1 = new XSSFWorkbook(file); int startIndex = 0, rowIndex = 0; /*switch (VRPTW.m) { case 2: startIndex = 0; rowIndex = 4; break; case 3: startIndex = 2; rowIndex = 5; break; case 5: startIndex = 4; rowIndex = 7; break; case 7: startIndex = 6; rowIndex = 9; break; default: System.out.println("Unknown value for m"); break; }*/ //Get desired sheet from the workbook XSSFSheet sheet1 = workbook1.getSheetAt(startIndex); //for tours /*XSSFSheet sheet2 = workbook1.getSheetAt(startIndex + 1); //for number of assigned cities XSSFSheet sheet3 = workbook1.getSheetAt(startIndex + 2); //for cost of individual subtours XSSFSheet sheet4 = workbook1.getSheetAt(startIndex + 3); //for total cost of subtours XSSFSheet sheet5 = workbook1.getSheetAt(startIndex + 4); //for verbose output of total cost at each 5 iteration */ XSSFSheet sheet2 = workbook1.getSheetAt(startIndex + 1); //for verbose output of longest cost at each 5 iteration //define a cell style for bold font CellStyle style = workbook1.createCellStyle(); Font font = workbook1.createFont(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); style.setFont(font); //define style with bold font and blue color for font CellStyle styleBoldBlue = workbook1.createCellStyle(); font = workbook1.createFont(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); font.setColor(IndexedColors.BLUE.index); styleBoldBlue.setFont(font); index1 = 133; if (!saveIterCosts) { //write only once the name of the algorithm that was run if (trialNumber == 0) { r = sheet1.getRow(index1); if (r == null) { // First cell in the row, create //System.out.println("Empty row, create new one"); r = sheet1.createRow(index1); } c = r.getCell(0); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(0); } c.setCellValue( "Obtained solutions (values) after running new version (ACS MinMax global, voiajor si oras alesi simultan) with local search"); c.setCellStyle(styleBoldBlue); } //write only once the table header index1 = index1 + 3; r = sheet1.getRow(index1); if (r == null) { // First cell in the row, create //System.out.println("Empty row, create new one"); r = sheet1.createRow(index1); } c = r.getCell(0); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(0); } c.setCellValue("Run #"); c.setCellStyle(style); c = r.getCell(1); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(1); } c.setCellValue("MinMax (cost of longest subtour)"); c.setCellStyle(style); c = r.getCell(2); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(2); } c.setCellValue("Total Cost"); c.setCellStyle(style); c = r.getCell(3); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(3); } c.setCellValue("Amplitude"); c.setCellStyle(style); //write number of run index1 = 137 + trialNumber; r = sheet1.getRow(index1); if (r == null) { // First cell in the row, create //System.out.println("Empty row, create new one"); r = sheet1.createRow(index1); } c = r.getCell(0); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(0); } c.setCellValue(trialNumber + 1); //write MinMax (cost of longest subtour) double longestSubtour = getLongestSubtour(); c = r.getCell(1); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(1); } c.setCellValue(longestSubtour); //write total cost double totalCost = getTotalCost(); c = r.getCell(2); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(2); } c.setCellValue(totalCost); //write amplitude double amplitude = getAmplitude(); c = r.getCell(3); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(3); } c.setCellValue(amplitude); } index5 = 859; if (saveIterCosts) { //write only once the name of the algorithm that was run if (trialNumber == 0) { r = sheet2.getRow(index5); if (r == null) { // First cell in the row, create //System.out.println("Empty row, create new one"); r = sheet2.createRow(index5); } c = r.getCell(0); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(0); } c.setCellValue( "Longest cost of subtour at each 5 iteration after running new version (ACS MinMax global, voiajor si oras alesi simultan) with local search"); c.setCellStyle(styleBoldBlue); int tempIndex = index5 + 3; r = sheet2.getRow(tempIndex); if (r == null) { // First cell in the row, create //System.out.println("Empty row, create new one"); r = sheet2.createRow(tempIndex); } ArrayList<Integer> iterNumber = getIterNumber(); c = r.getCell(0); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(0); } c.setCellValue("Nr Iter"); c.setCellStyle(style); int indexTemp = 0; for (int j = 0; j < iterNumber.size(); j++) { indexTemp = tempIndex + 1 + j; r1 = sheet2.getRow(indexTemp); if (r1 == null) { // First cell in the row, create //System.out.println("Empty row, create new one"); r1 = sheet2.createRow(indexTemp); } c = r1.getCell(0); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r1.createCell(0); } c.setCellValue(iterNumber.get(j)); } } index5 = index5 + 3; r = sheet2.getRow(index5); if (r == null) { // First cell in the row, create //System.out.println("Empty row, create new one"); r = sheet2.createRow(index5); } //for each trial run save at each 5 iteration the best longest cost of a subtour so far ArrayList<Double> iterLongestCost = getIterLongestCost(); int index; //for each run write the table header cell c = r.getCell(trialNumber + 1); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(trialNumber + 1); } c.setCellValue("Run " + (trialNumber + 1)); c.setCellStyle(style); for (int j = 0; j < iterLongestCost.size(); j++) { index = index5 + 1 + j; r1 = sheet2.getRow(index); if (r1 == null) { // First cell in the row, create //System.out.println("Empty row, create new one"); r1 = sheet2.createRow(index); } c = r1.getCell(trialNumber + 1); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r1.createCell(trialNumber + 1); } c.setCellValue(iterLongestCost.get(j)); } } //Write the workbook in file system FileOutputStream out = new FileOutputStream(new File(filePath)); workbook1.write(out); out.close(); int nrOfRun = trialNumber + 1; System.out.println("\nRun #" + nrOfRun + " written successfully on disk.\n"); } catch (Exception e) { e.printStackTrace(); } } else { //Blank workbook System.out.println("File " + filePath + " doesn't exists.."); } }
From source file:aco.Utilities.java
License:Open Source License
static void writeExcelFinalSolution(int trial, double scalledValue) { Row r;/*w ww. ja va 2s. c o m*/ Cell c; int index1 = 0; //the file already exists; we should add a new row as the last one in the Excel file if (new File(filePath5).canRead()) { //System.out.println("File already exists.."); try { FileInputStream file = new FileInputStream(new File(filePath5)); //Create Workbook instance holding reference to .xlsx file XSSFWorkbook workbook1 = new XSSFWorkbook(file); //Get desired sheet from the workbook XSSFSheet sheet1 = workbook1.getSheetAt(0); //define a cell style for bold font CellStyle style = workbook1.createCellStyle(); Font font = workbook1.createFont(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); style.setFont(font); //define style with bold font and blue color for font CellStyle styleBoldBlue = workbook1.createCellStyle(); font = workbook1.createFont(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); font.setColor(IndexedColors.BLUE.index); styleBoldBlue.setFont(font); index1 = 8; //8 //26 index1 = index1 + trial; r = sheet1.getRow(index1); if (r == null) { // First cell in the row, create //System.out.println("Empty row, create new one"); r = sheet1.createRow(index1); } int nrOfRun = trial + 1; //write trial number (Run #) c = r.getCell(15); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(15); } c.setCellValue(nrOfRun); //write number of used vehicles c = r.getCell(16); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(16); } c.setCellValue(Ants.best_so_far_ant.usedVehicles); //write total traveled distance c = r.getCell(17); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(17); } c.setCellValue(scalledValue); //write the total number of feasible solutions c = r.getCell(18); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(18); } c.setCellValue(InOut.noSolutions); //Write the workbook in file system FileOutputStream out = new FileOutputStream(new File(filePath5)); workbook1.write(out); out.close(); System.out.println("\nRun #" + nrOfRun + " written successfully on disk.\n"); } catch (Exception e) { e.printStackTrace(); } } else { //Blank workbook System.out.println("File " + filePath5 + " doesn't exists.."); } }
From source file:com.b2international.snowowl.datastore.server.importer.AbstractTerminologyExcelExporter.java
License:Apache License
public AbstractTerminologyExcelExporter(final String userId, final IBranchPath branchPath, final Collection<String> componentIds) { super(userId, branchPath, componentIds); final Font headerFont = workbook.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); headerFont.setFontName(FONT_STYLE);/*from w w w . j av a 2 s.co m*/ final Font defaultFont = workbook.createFont(); defaultFont.setFontName(FONT_STYLE); final Font hyperlinkFont = workbook.createFont(); hyperlinkFont.setUnderline(Font.U_SINGLE); hyperlinkFont.setColor(IndexedColors.BLUE.getIndex()); centerBoldStyle = workbook.createCellStyle(); centerBoldStyle.setAlignment(CellStyle.ALIGN_CENTER); centerBoldStyle.setFont(headerFont); BOLD_STYLE = workbook.createCellStyle(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); BOLD_STYLE.setAlignment(CellStyle.ALIGN_LEFT); BOLD_STYLE.setFont(headerFont); // wrap needs to be enabled to accommodate multi-lines within a single cell wrapStyle = workbook.createCellStyle(); wrapStyle.setWrapText(true); wrapStyle.setFont(defaultFont); defaultStyle = workbook.createCellStyle(); defaultStyle.setFont(defaultFont); hyperlinkStyle = workbook.createCellStyle(); hyperlinkStyle.setFont(hyperlinkFont); }
From source file:com.b510.excel.client.BusinessPlan.java
License:Apache License
/** * create a library of cell styles/*from www.ja v a 2 s.c om*/ */ private static Map<String, CellStyle> createStyles(Workbook wb) { Map<String, CellStyle> styles = new HashMap<String, CellStyle>(); DataFormat df = wb.createDataFormat(); CellStyle style; Font headerFont = wb.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_CENTER); style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(headerFont); styles.put("header", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_CENTER); style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(headerFont); style.setDataFormat(df.getFormat("d-mmm")); styles.put("header_date", style); Font font1 = wb.createFont(); font1.setBoldweight(Font.BOLDWEIGHT_BOLD); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_LEFT); style.setFont(font1); styles.put("cell_b", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_CENTER); style.setFont(font1); styles.put("cell_b_centered", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_RIGHT); style.setFont(font1); style.setDataFormat(df.getFormat("d-mmm")); styles.put("cell_b_date", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_RIGHT); style.setFont(font1); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setDataFormat(df.getFormat("d-mmm")); styles.put("cell_g", style); Font font2 = wb.createFont(); font2.setColor(IndexedColors.BLUE.getIndex()); font2.setBoldweight(Font.BOLDWEIGHT_BOLD); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_LEFT); style.setFont(font2); styles.put("cell_bb", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_RIGHT); style.setFont(font1); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setDataFormat(df.getFormat("d-mmm")); styles.put("cell_bg", style); Font font3 = wb.createFont(); font3.setFontHeightInPoints((short) 14); font3.setColor(IndexedColors.DARK_BLUE.getIndex()); font3.setBoldweight(Font.BOLDWEIGHT_BOLD); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_LEFT); style.setFont(font3); style.setWrapText(true); styles.put("cell_h", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_LEFT); style.setWrapText(true); styles.put("cell_normal", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_CENTER); style.setWrapText(true); styles.put("cell_normal_centered", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_RIGHT); style.setWrapText(true); style.setDataFormat(df.getFormat("d-mmm")); styles.put("cell_normal_date", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_LEFT); style.setIndention((short) 1); style.setWrapText(true); styles.put("cell_indented", style); style = createBorderedStyle(wb); style.setFillForegroundColor(IndexedColors.BLUE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); styles.put("cell_blue", style); return styles; }
From source file:com.blackducksoftware.tools.commonframework.standard.datatable.writer.DataSetWriterExcel.java
License:Apache License
private void populateHyperlinkCell(Record record, FieldDef fieldDef, Cell cell) throws Exception { String cellValue = record.getHyperlinkFieldValue(fieldDef.getName()).getDisplayText(); cell.setCellValue(cellValue);//from www. ja v a2 s. c o m // cell style for hyperlinks // by default hyperlinks are blue and underlined CellStyle hlink_style = workbook.createCellStyle(); Font hlink_font = workbook.createFont(); hlink_font.setUnderline(Font.U_SINGLE); hlink_font.setColor(IndexedColors.BLUE.getIndex()); hlink_style.setFont(hlink_font); // Make it a hyperlink CreationHelper createHelper = workbook.getCreationHelper(); Hyperlink link = createHelper.createHyperlink(Hyperlink.LINK_URL); link.setAddress(record.getHyperlinkFieldValue(fieldDef.getName()).getHyperlinkText()); cell.setHyperlink(link); cell.setCellStyle(hlink_style); }
From source file:com.github.autoprimer3.Primer3ResultViewController.java
License:Open Source License
private void writePrimersToExcel(final File f) throws IOException { final Service<Void> service = new Service<Void>() { @Override/*ww w. j ava 2 s . co m*/ protected Task<Void> createTask() { return new Task<Void>() { @Override protected Void call() throws IOException { BufferedOutputStream bo = new BufferedOutputStream(new FileOutputStream(f)); Workbook wb = new XSSFWorkbook(); CellStyle hlink_style = wb.createCellStyle(); Font hlink_font = wb.createFont(); hlink_font.setUnderline(Font.U_SINGLE); hlink_font.setColor(IndexedColors.BLUE.getIndex()); hlink_style.setFont(hlink_font); CreationHelper createHelper = wb.getCreationHelper(); Sheet listSheet = wb.createSheet(); Sheet detailsSheet = wb.createSheet(); Row row = null; int rowNo = 0; int sheetNo = 0; wb.setSheetName(sheetNo++, "List"); wb.setSheetName(sheetNo++, "Details"); row = listSheet.createRow(rowNo++); String header[] = { "Primer", "Sequence", "Product Size (bp)" }; for (int col = 0; col < header.length; col++) { Cell cell = row.createCell(col); cell.setCellValue(header[col]); } updateMessage("Writing primers . . ."); updateProgress(0, data.size() * 3); int n = 0; for (Primer3Result r : data) { n++; updateMessage("Writing primer list " + n + " . . ."); row = listSheet.createRow(rowNo++); int col = 0; Cell cell = row.createCell(col++); cell.setCellValue(r.getName() + "F"); cell = row.createCell(col++); cell.setCellValue(r.getLeftPrimer()); cell = row.createCell(col++); cell.setCellValue(r.getProductSize()); updateProgress(n, data.size() * 3); updateMessage("Writing primer list " + n + " . . ."); row = listSheet.createRow(rowNo++); col = 0; cell = row.createCell(col++); cell.setCellValue(r.getName() + "R"); cell = row.createCell(col++); cell.setCellValue(r.getRightPrimer()); cell = row.createCell(col++); cell.setCellValue(r.getProductSize()); n++; updateProgress(n, data.size() * 3); } rowNo = 0; row = detailsSheet.createRow(rowNo++); ArrayList<String> detailsHeader = new ArrayList<>(Arrays.asList("Name", "Other IDs", "Left Primer", "Right Primer", "Product Size (bp)", "Region", "in-silico PCR")); if (ispcrResCol.isVisible()) { detailsHeader.add("in-silico PCR Results"); } for (int col = 0; col < detailsHeader.size(); col++) { Cell cell = row.createCell(col); cell.setCellValue(detailsHeader.get(col)); } int m = 0; for (Primer3Result r : data) { m++; updateMessage("Writing details for pair " + m + " . . ."); row = detailsSheet.createRow(rowNo++); int col = 0; Cell cell = row.createCell(col++); cell.setCellValue(r.getName()); cell = row.createCell(col++); cell.setCellValue(r.getTranscripts()); cell = row.createCell(col++); cell.setCellValue(r.getLeftPrimer()); cell = row.createCell(col++); cell.setCellValue(r.getRightPrimer()); cell = row.createCell(col++); cell.setCellValue(r.getProductSize()); cell = row.createCell(col++); cell.setCellValue(r.getRegion()); cell = row.createCell(col++); if (r.getIsPcrUrl() != null) { cell.setCellValue("isPCR"); org.apache.poi.ss.usermodel.Hyperlink hl = createHelper .createHyperlink(org.apache.poi.ss.usermodel.Hyperlink.LINK_URL); hl.setAddress(r.getIsPcrUrl()); cell.setHyperlink(hl); cell.setCellStyle(hlink_style); } else { cell.setCellValue(""); } if (ispcrResCol.isVisible()) { cell = row.createCell(col++); if (r.getIsPcrResults() != null) { cell.setCellValue(r.getIsPcrResults()); } else { cell.setCellValue(""); } } updateProgress(n + m, data.size() * 3); } updateMessage("Wrote " + data.size() + " primer pairs to file."); wb.write(bo); bo.close(); return null; } }; } }; service.setOnSucceeded(new EventHandler<WorkerStateEvent>() { @Override public void handle(WorkerStateEvent e) { Action response = Dialogs.create().title("Done").masthead("Finished writing") .message("Primers successfully written to " + f.getAbsolutePath() + "\n\nDo you want to open " + "this file now?") .actions(Dialog.ACTION_YES, Dialog.ACTION_NO).styleClass(Dialog.STYLE_CLASS_NATIVE) .showConfirm(); if (response == Dialog.ACTION_YES) { try { openFile(f); } catch (IOException ex) { Action openFailed = Dialogs.create().title("Open failed") .masthead("Could not open output file") .message("Exception encountered when attempting to open " + "the saved file. See below:") .styleClass(Dialog.STYLE_CLASS_NATIVE).showException(ex); } } progressBar.progressProperty().unbind(); progressBar.setVisible(false); summaryLabel.textProperty().unbind(); summaryLabel.setText(summary); closeButton.setDisable(false); closeMenuItem.setDisable(false); setCheckIsPcrButton(); } }); service.setOnCancelled(new EventHandler<WorkerStateEvent>() { @Override public void handle(WorkerStateEvent e) { Dialogs writeCancelled = Dialogs.create().title("Writing Cancelled") .masthead("Cancelled writing to file").message("User cancelled writing primers to file.") .styleClass(Dialog.STYLE_CLASS_NATIVE); writeCancelled.showInformation(); progressBar.progressProperty().unbind(); progressBar.setVisible(false); summaryLabel.textProperty().unbind(); summaryLabel.setText(summary); closeButton.setDisable(false); closeMenuItem.setDisable(false); setCheckIsPcrButton(); } }); service.setOnFailed(new EventHandler<WorkerStateEvent>() { @Override public void handle(WorkerStateEvent e) { Action writeFailed = Dialogs.create().title("Writing failed") .masthead("Could not write primers to file") .message("Exception encountered when attempting to write " + "primers to file. See below:") .styleClass(Dialog.STYLE_CLASS_NATIVE).showException(e.getSource().getException()); progressBar.progressProperty().unbind(); progressBar.setVisible(false); summaryLabel.textProperty().unbind(); summaryLabel.setText(summary); closeButton.setDisable(false); closeMenuItem.setDisable(false); setCheckIsPcrButton(); } }); progressBar.setVisible(true); progressBar.progressProperty().bind(service.progressProperty()); summaryLabel.textProperty().bind(service.messageProperty()); closeButton.setDisable(true); closeMenuItem.setDisable(true); checkIsPcrButton.setText("Cancel"); checkIsPcrButton.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent actionEvent) { service.cancel(); } }); service.start(); }
From source file:com.hp.amss.util.HyperlinkExample.java
License:Apache License
public static void main(String[] args) throws Exception { Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook(); CreationHelper createHelper = wb.getCreationHelper(); //cell style for hyperlinks //by default hyperlinks are blue and underlined CellStyle hlink_style = wb.createCellStyle(); Font hlink_font = wb.createFont(); hlink_font.setUnderline(Font.U_SINGLE); hlink_font.setColor(IndexedColors.BLUE.getIndex()); hlink_style.setFont(hlink_font);//from w ww .ja v a 2s. co m Cell cell; Sheet sheet = wb.createSheet("Hyperlinks"); //URL cell = sheet.createRow(0).createCell((short) 0); cell.setCellValue("URL Link"); Hyperlink link = createHelper.createHyperlink(Hyperlink.LINK_URL); link.setAddress("http://poi.apache.org/"); cell.setHyperlink(link); cell.setCellStyle(hlink_style); //link to a file in the current directory cell = sheet.createRow(1).createCell((short) 0); cell.setCellValue("File Link"); link = createHelper.createHyperlink(Hyperlink.LINK_FILE); link.setAddress("link1.xls"); cell.setHyperlink(link); cell.setCellStyle(hlink_style); //e-mail link cell = sheet.createRow(2).createCell((short) 0); cell.setCellValue("Email Link"); link = createHelper.createHyperlink(Hyperlink.LINK_EMAIL); //note, if subject contains white spaces, make sure they are url-encoded link.setAddress("mailto:poi@apache.org?subject=Hyperlinks"); cell.setHyperlink(link); cell.setCellStyle(hlink_style); //TODO cell.setCellValue(createHelper.createRichTextString("")); cell.setCellType(Cell.CELL_TYPE_STRING); //link to a place in this workbook //create a target sheet and cell Sheet sheet2 = wb.createSheet("Target Sheet"); sheet2.createRow(0).createCell((short) 0).setCellValue("Target Cell"); cell = sheet.createRow(3).createCell((short) 0); cell.setCellValue("Worksheet Link"); Hyperlink link2 = createHelper.createHyperlink(Hyperlink.LINK_DOCUMENT); link2.setAddress("'Target Sheet'!A1"); cell.setHyperlink(link2); cell.setCellStyle(hlink_style); FileOutputStream out = new FileOutputStream("C:\\hyperinks.xlsx"); wb.write(out); out.close(); }
From source file:com.lwr.software.reporter.restservices.ReportExportService.java
License:Open Source License
public Response exportExcel(Report toExport, Set<ReportParameter> reportParams) { Workbook wb = new XSSFWorkbook(); Font boldFont = wb.createFont(); boldFont.setBold(true);/*from w w w . java2 s . c o m*/ CellStyle headerStyle = wb.createCellStyle(); headerStyle.setBorderBottom(BorderStyle.THIN); headerStyle.setBorderTop(BorderStyle.THIN); headerStyle.setBorderRight(BorderStyle.THIN); headerStyle.setBorderLeft(BorderStyle.THIN); headerStyle.setFillBackgroundColor(IndexedColors.BLUE.getIndex()); headerStyle.setFont(boldFont); CellStyle cellStyle = wb.createCellStyle(); cellStyle.setBorderBottom(BorderStyle.THIN); cellStyle.setBorderTop(BorderStyle.THIN); cellStyle.setBorderRight(BorderStyle.THIN); cellStyle.setBorderLeft(BorderStyle.THIN); CellStyle titleStyle = wb.createCellStyle(); titleStyle.setBorderBottom(BorderStyle.THIN); titleStyle.setBorderTop(BorderStyle.THIN); titleStyle.setBorderRight(BorderStyle.THIN); titleStyle.setBorderLeft(BorderStyle.THIN); List<RowElement> rows = toExport.getRows(); int sheetIndex = 0; for (RowElement rowElement : rows) { List<Element> elements = rowElement.getElements(); for (Element element : elements) { try { element.setParams(reportParams); element.init(); } catch (Exception e) { logger.error("Unable to init '" + element.getTitle() + "' element of report '" + toExport.getTitle() + "' Error " + e.getMessage(), e); return Response.serverError().entity("Unable to init '" + element.getTitle() + "' element of report '" + toExport.getTitle() + "' Error " + e.getMessage()).build(); } String sheetName = element.getTitle().substring(0, element.getTitle().length() > 30 ? 30 : element.getTitle().length()) + (sheetIndex++); Sheet sheet = wb.createSheet(sheetName); Row reportTitleRow = sheet.createRow(0); Cell reportTitleHeader = reportTitleRow.createCell(0); reportTitleHeader.setCellStyle(headerStyle); reportTitleHeader.setCellValue("Report Title:"); Cell reportTitleCell = reportTitleRow.createCell(1); reportTitleCell.setCellStyle(titleStyle); reportTitleCell.setCellValue(toExport.getTitle()); Row elementTitleRow = sheet.createRow(1); Cell elementTitleHeader = elementTitleRow.createCell(0); elementTitleHeader.setCellStyle(headerStyle); elementTitleHeader.setCellValue("Element Title:"); Cell elementTitleCell = elementTitleRow.createCell(1); elementTitleCell.setCellStyle(titleStyle); elementTitleCell.setCellValue(element.getTitle()); List<List<Object>> dataToExport = element.getData(); int rowIndex = 3; Row headerRow = sheet.createRow(rowIndex++); List<Object> unifiedHeaderRow = element.getHeader(); for (int i = 0; i < unifiedHeaderRow.size(); i++) { Cell headerCell = headerRow.createCell(i); String headerCellValue = unifiedHeaderRow.get(i).toString(); headerCell.setCellValue(headerCellValue); headerCell.setCellStyle(headerStyle); } for (int i = 0; i < dataToExport.size(); i++) { Row row = sheet.createRow(rowIndex++); List<Object> unifiedRow = dataToExport.get(i); int cellIndex = 0; for (Object cellValue : unifiedRow) { Cell cell = row.createCell(cellIndex); cell.setCellStyle(cellStyle); try { double val = Double.parseDouble(cellValue.toString()); cell.setCellValue(val); } catch (NumberFormatException e) { cell.setCellValue(cellValue.toString()); } cellIndex++; } } } } try { File file = new File(DashboardConstants.APPLN_TEMP_DIR + System.nanoTime()); logger.info("Export CSV temp file path is " + file.getAbsoluteFile()); wb.write(new FileOutputStream(file)); wb.close(); ResponseBuilder responseBuilder = Response.ok((Object) file); responseBuilder.header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); responseBuilder.header("Content-Transfer-Encoding", "binary"); responseBuilder.header("Content-Disposition", "attachment;filename=" + file.getName()); responseBuilder.header("Content-Length", file.length()); Response responseToSend = responseBuilder.build(); file.deleteOnExit(); return responseToSend; } catch (Exception e1) { return Response.serverError() .entity("Unable to export " + toExport.getTitle() + " report " + e1.getMessage()).build(); } }
From source file:com.netxforge.netxstudio.models.export.MasterDataExporterRevenge_sxssf.java
License:Open Source License
private void _generateID(Sheet sheet) { // Generate name. {// w w w .j a v a 2 s . co m // Style, cell color. CellStyle attributeStyle = workBook.createCellStyle(); attributeStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); attributeStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); // Style, font Font attributeFont = workBook.createFont(); attributeFont.setFontName("Verdana"); attributeFont.setColor(IndexedColors.BLUE.getIndex()); attributeStyle.setFont(attributeFont); // Style, border. attributeStyle.setBorderBottom(CellStyle.BORDER_MEDIUM); Row row = sheet.getRow(0); if (row == null) { row = sheet.createRow(0); } short lastCellNum = row.getLastCellNum(); if (lastCellNum == -1) { lastCellNum = 0; } Cell cell = row.createCell(lastCellNum); cell.setCellValue("ID"); cell.setCellStyle(attributeStyle); } // Generate type { CellStyle typeStyle = workBook.createCellStyle(); typeStyle.setBorderBottom(CellStyle.BORDER_MEDIUM); Row row = sheet.getRow(1); if (row == null) { row = sheet.createRow(1); } short lastCellNum = row.getLastCellNum(); if (lastCellNum == -1) { lastCellNum = 0; } Cell cell = row.createCell(lastCellNum); cell.setCellStyle(typeStyle); } }
From source file:com.netxforge.netxstudio.models.export.MasterDataExporterRevenge_sxssf.java
License:Open Source License
private void _generateCell(EAttribute eAttribute, Sheet sheet) { // Generate name. {//from ww w. ja v a2s . c om // Style, cell color. CellStyle attributeStyle = workBook.createCellStyle(); attributeStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); attributeStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); // Style, font Font attributeFont = workBook.createFont(); attributeFont.setFontName("Verdana"); attributeFont.setColor(IndexedColors.BLUE.getIndex()); attributeStyle.setFont(attributeFont); // Style, border. attributeStyle.setBorderBottom(CellStyle.BORDER_MEDIUM); Row row = sheet.getRow(0); if (row == null) { row = sheet.createRow(0); } short lastCellNum = row.getLastCellNum(); if (lastCellNum == -1) { lastCellNum = 0; } Cell cell = row.createCell(lastCellNum); cell.setCellValue(StringUtils.capitalize(eAttribute.getName())); cell.setCellStyle(attributeStyle); } // Generate type { CellStyle typeStyle = workBook.createCellStyle(); typeStyle.setBorderBottom(CellStyle.BORDER_MEDIUM); Row row = sheet.getRow(1); if (row == null) { row = sheet.createRow(1); } short lastCellNum = row.getLastCellNum(); if (lastCellNum == -1) { lastCellNum = 0; } Cell cell = row.createCell(lastCellNum); cell.setCellValue(eAttribute.getEType().getName()); cell.setCellStyle(typeStyle); } }