List of usage examples for org.apache.poi.xssf.usermodel XSSFWorkbook write
@SuppressWarnings("resource") public final void write(OutputStream stream) throws IOException
From source file:tr.org.liderahenk.liderconsole.core.utils.SWTResourceManager.java
License:Open Source License
/** * /*from w ww . j av a 2 s .c o m*/ * @param parent * @return */ public static TableViewer createTableViewer(final Composite parent, final IExportableTableViewer exportable) { final TableViewer tableViewer = new TableViewer(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER); configureTableLayout(tableViewer); if (exportable != null) { Button btnExport = new Button(exportable.getButtonComposite(), SWT.PUSH); btnExport.setText(Messages.getString("EXPORT_REPORT")); btnExport.setImage( SWTResourceManager.getImage(LiderConstants.PLUGIN_IDS.LIDER_CONSOLE_CORE, "icons/16/save.png")); btnExport.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); btnExport.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { try { // Ask target directory final DirectoryDialog dialog = new DirectoryDialog(Display.getDefault().getActiveShell(), SWT.OPEN); dialog.setMessage(Messages.getString("SELECT_DOWNLOAD_DIR")); String path = dialog.open(); if (path == null || path.isEmpty()) { return; } if (!path.endsWith("/")) { path += "/"; } // Generate report XSSFWorkbook workbook = createWorkbookFromTable(tableViewer, exportable.getSheetName()); // Save report to target directory FileOutputStream fos = new FileOutputStream(path + exportable.getReportName() + ".xlsx"); workbook.write(fos); fos.close(); Notifier.success(null, Messages.getString("REPORT_SAVED")); } catch (Exception e1) { logger.error(e1.getMessage(), e1); Notifier.error(null, Messages.getString("ERROR_ON_SAVE")); } } @Override public void widgetDefaultSelected(SelectionEvent e) { } }); } return tableViewer; }
From source file:trei_big.criar_planilha_excel.java
public criar_planilha_excel(String caminho_salvar, String nome_da_tabela) { //Blank workbook XSSFWorkbook workbook = new XSSFWorkbook(); //Create a blank sheet XSSFSheet sheet = workbook.createSheet(nome_da_tabela); //This data needs to be written (Object[]) Map<Integer, Object[]> data = new TreeMap<Integer, Object[]>(); Vector<Vector<String>> dados = banco.obter_dados_da_tabela(nome_da_tabela); data.put(0, banco.nome_colunas_consulta.toArray(new Object[] {})); for (int i = 0; i < dados.size(); i++) { Vector<String> get = dados.get(i); data.put((i + 1), get.toArray(new Object[] {})); }/*from www .j av a2 s. com*/ //Iterate over data and write to sheet Set<Integer> keyset = data.keySet(); int rownum = 0; for (Integer key : keyset) { Row row = sheet.createRow(rownum++); Object[] objArr = data.get(key); int cellnum = 0; for (Object obj : objArr) { Cell cell = row.createCell(cellnum++); if (obj instanceof String) { cell.setCellValue((String) obj); } else if (obj instanceof Integer) { cell.setCellValue((Integer) obj); } } } try { //Write the workbook in file system FileOutputStream out = new FileOutputStream(new File(caminho_salvar, nome_da_tabela + extensao)); workbook.write(out); out.close(); aviso.mensagem_sucesso("Planilha '" + nome_da_tabela + extensao + "' criada com sucesso!"); } catch (Exception e) { e.printStackTrace(); } }
From source file:tubessc.Dataset.java
public void calculateFluctuation(String InputFile, String OutputFile) throws FileNotFoundException, IOException { FileInputStream file = new FileInputStream(new File(InputFile)); XSSFWorkbook workbook = new XSSFWorkbook(file); XSSFSheet sheet = workbook.getSheetAt(0); XSSFWorkbook output = new XSSFWorkbook(); XSSFSheet sheetOutput = output.createSheet("new sheet"); FileOutputStream fileOut = new FileOutputStream(OutputFile); int rowStart = sheet.getFirstRowNum(); int rowEnd = sheet.getLastRowNum(); for (int i = rowStart; i <= rowEnd - 1; i++) { Row rowIn1 = sheet.getRow(i);//from ww w . ja v a 2s . c om Cell cellIn1 = rowIn1.getCell(0); Row rowIn2 = sheet.getRow(i + 1); Cell cellIn2 = rowIn2.getCell(0); double value1 = Double.parseDouble(String.valueOf(cellIn1.getNumericCellValue())); double value2 = Double.parseDouble(String.valueOf(cellIn2.getNumericCellValue())); Row rowOut = sheetOutput.createRow(i); Cell cellOut = rowOut.createCell(0); cellOut.setCellValue(value2 - value1); } output.write(fileOut); fileOut.close(); }
From source file:tubessc.Dataset.java
public void normalization(String InputFile, String outputFile, double minValue, double maxValue) throws FileNotFoundException, IOException { this.minValue = minValue; this.maxValue = maxValue; FileInputStream file = new FileInputStream(new File(InputFile)); XSSFWorkbook workbook = new XSSFWorkbook(file); XSSFSheet sheet = workbook.getSheetAt(0); XSSFWorkbook output = new XSSFWorkbook(); XSSFSheet sheetOutput = output.createSheet("new sheet"); FileOutputStream fileOut = new FileOutputStream(outputFile); int rowStart = sheet.getFirstRowNum(); int rowEnd = sheet.getLastRowNum(); Row row = sheet.getRow(rowStart);//from w w w . j ava2 s .c o m Cell cell = row.getCell(0); max = Double.parseDouble(String.valueOf(cell.getNumericCellValue())); min = Double.parseDouble(String.valueOf(cell.getNumericCellValue())); for (int i = rowStart + 1; i <= rowEnd; i++) { row = sheet.getRow(i); cell = row.getCell(0); double value = Double.parseDouble(String.valueOf(cell.getNumericCellValue())); if (value > max) { max = value; } if (value < min) { min = value; } } for (int i = rowStart; i <= rowEnd; i++) { row = sheet.getRow(i); cell = row.getCell(0); double value = Double.parseDouble(String.valueOf(cell.getNumericCellValue())); double newValue = minValue + ((value - min) * (maxValue - minValue) / (max - min)); Row rowOut = sheetOutput.createRow(i); Cell cellOut = rowOut.createCell(0); cellOut.setCellValue(newValue); } output.write(fileOut); fileOut.close(); }
From source file:tubessc.TubesSC.java
public static void main(String[] args) { // TODO code application logic here try {/*from ww w.j a v a2s . co m*/ int x = 0; XSSFWorkbook output = new XSSFWorkbook(); XSSFSheet sheetOutput = output.createSheet("new sheet"); FileOutputStream fileOut = new FileOutputStream("F:\\JST\\dataset\\goldPrice\\HasilFINAL.xlsx"); ds = new Dataset(); ds.calculateFluctuation("F:\\JST\\dataset\\goldPrice\\training.xlsx", "F:\\JST\\dataset\\goldPrice\\trainingFluctuation.xlsx"); ds.normalization("F:\\JST\\dataset\\goldPrice\\trainingFluctuation.xlsx", "F:\\JST\\dataset\\goldPrice\\trainingNormalization.xlsx", 0.1, 0.9); ds.calculateFluctuation("F:\\JST\\dataset\\goldPrice\\testing.xlsx", "F:\\JST\\dataset\\goldPrice\\testingFluctuation.xlsx"); ds.normalization("F:\\JST\\dataset\\goldPrice\\testingFluctuation.xlsx", "F:\\JST\\dataset\\goldPrice\\testingNormalization.xlsx", 0.1, 0.9); int totalCombination = varInput.length * varHidden.length * varPop.length * times; int progress = 0; for (int i = 0; i < varInput.length; i++) { input = varInput[i]; ds.clearDatasetTraining(); ds.clearDatasetTesting(); ds.addDataSetTrainingExcel("F:\\JST\\dataset\\goldPrice\\trainingNormalization.xlsx", TubesSC.input); ds.addDataSetTestingExcel("F:\\JST\\dataset\\goldPrice\\testingNormalization.xlsx", TubesSC.input); for (int j = 0; j < varHidden.length; j++) { neuron = varHidden[j]; nhidden = ((input + bias) * neuron); noutput = (neuron + bias); total = nhidden + noutput; batas = total - noutput; for (int k = 0; k < varPop.length; k++) { numOfGen = varGen[k]; numOfPop = varPop[k]; for (int l = 0; l < times; l++) { Row r = sheetOutput.createRow(progress); Kromosom fittest = null; double fittestBefore = 0; Populasi pop = new Populasi(numOfPop, true, ds); for (int y = 0; y < numOfGen; y++) { pop = EP.Evolution(pop); fittest = pop.getFittest(); System.out.println(fittest.getFitness()); } JST jst = new JST(fittest.getW1(), fittest.getW2(), fittest.getB1(), fittest.getB2(), ds); double MAPE = jst.getMape(true); System.out.println(MAPE); //System.out.println("final MAPE = " + MAPE); for (int z = 0; z < 6; z++) { Cell c = r.createCell(z); switch (z) { case 0: c.setCellValue(input); break; case 1: c.setCellValue(neuron); break; case 2: c.setCellValue(numOfGen); break; case 3: c.setCellValue(numOfPop); break; case 4: c.setCellValue(fittest.getFitness()); break; case 5: c.setCellValue(MAPE); break; } } x++; progress++; System.out.println("completed: " + progress + "/" + totalCombination); } } } } output.write(fileOut); fileOut.close(); } catch (IOException ex) { Logger.getLogger(TubesSC.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:uk.ac.bbsrc.tgac.miso.core.util.FormUtils.java
License:Open Source License
public static void createSampleInputSpreadsheet(Collection<Sample> samples, File outpath) throws Exception { Collections.sort(new ArrayList<Sample>(samples), new AliasComparator(Sample.class)); InputStream in = null;/* w w w . j a v a 2 s .c om*/ if (outpath.getName().endsWith(".xlsx")) { in = FormUtils.class.getResourceAsStream("/forms/ods/bulk_input.xlsx"); if (in != null) { XSSFWorkbook oDoc = new XSSFWorkbook(in); FileOutputStream fileOut = new FileOutputStream(outpath); oDoc.write(fileOut); fileOut.close(); } else { throw new IOException("Could not read from resource."); } } else if (outpath.getName().endsWith(".ods")) { in = FormUtils.class.getResourceAsStream("/forms/ods/bulk_input.ods"); if (in != null) { OdfSpreadsheetDocument oDoc = OdfSpreadsheetDocument.loadDocument(in); oDoc.save(outpath); } else { throw new IOException("Could not read from resource."); } } else { throw new IllegalArgumentException("Can only produce bulk input forms in ods or xlsx formats."); } }
From source file:uk.ac.bbsrc.tgac.miso.core.util.FormUtils.java
License:Open Source License
public static void createPlateInputSpreadsheet(File outpath) throws Exception { InputStream in = null;/*w w w. j a va 2s.c o m*/ if (outpath.getName().endsWith(".xlsx")) { in = FormUtils.class.getResourceAsStream("/forms/ods/plate_input.xlsx"); if (in != null) { XSSFWorkbook oDoc = new XSSFWorkbook(in); FileOutputStream fileOut = new FileOutputStream(outpath); oDoc.write(fileOut); fileOut.close(); } else { throw new IOException("Could not read from resource."); } } else if (outpath.getName().endsWith(".ods")) { in = FormUtils.class.getResourceAsStream("/forms/ods/plate_input.ods"); if (in != null) { OdfSpreadsheetDocument oDoc = OdfSpreadsheetDocument.loadDocument(in); oDoc.save(outpath); } else { throw new IOException("Could not read from resource."); } } else { throw new IllegalArgumentException("Can only produce plate input forms in ods or xlsx formats."); } }
From source file:uk.ac.bbsrc.tgac.miso.core.util.FormUtils.java
License:Open Source License
public static void createPlateExportForm(File outpath, JSONArray jsonArray) throws Exception { InputStream in = null;// w ww . j a v a 2s . c o m in = FormUtils.class.getResourceAsStream("/forms/ods/plate_input.xlsx"); if (in != null) { XSSFWorkbook oDoc = new XSSFWorkbook(in); XSSFSheet sheet = oDoc.getSheet("Input"); FileOutputStream fileOut = new FileOutputStream(outpath); int i = 4; for (JSONObject jsonObject : (Iterable<JSONObject>) jsonArray) { String sampleinwell = jsonObject.getString("value"); //"sampleid:wellid:samplealias:projectname" String sampleId = sampleinwell.split(":")[0]; String wellId = sampleinwell.split(":")[1]; String sampleAlias = sampleinwell.split(":")[2]; String projectName = sampleinwell.split(":")[3]; XSSFRow row = sheet.createRow(i); XSSFCell cellA = row.createCell(0); cellA.setCellValue(wellId); XSSFCell cellB = row.createCell(1); cellB.setCellValue(projectName); XSSFCell cellC = row.createCell(2); cellC.setCellValue(sampleAlias); i++; } oDoc.write(fileOut); fileOut.close(); } else { throw new IOException("Could not read from resource."); } }
From source file:uk.ac.bbsrc.tgac.miso.spring.util.FormUtils.java
License:Open Source License
public static void createSampleInputSpreadsheet(Collection<Sample> samples, File outpath) throws Exception { Collections.sort(new ArrayList<>(samples), new AliasComparator<>()); InputStream in = null;//from ww w. jav a2 s . c om if (outpath.getName().endsWith(".xlsx")) { in = FormUtils.class.getResourceAsStream("/forms/ods/bulk_input.xlsx"); if (in != null) { XSSFWorkbook oDoc = new XSSFWorkbook(in); FileOutputStream fileOut = new FileOutputStream(outpath); oDoc.write(fileOut); fileOut.close(); } else { throw new IOException("Could not read from resource."); } } else if (outpath.getName().endsWith(".ods")) { in = FormUtils.class.getResourceAsStream("/forms/ods/bulk_input.ods"); if (in != null) { OdfSpreadsheetDocument oDoc = OdfSpreadsheetDocument.loadDocument(in); oDoc.save(outpath); } else { throw new IOException("Could not read from resource."); } } else { throw new IllegalArgumentException("Can only produce bulk input forms in ods or xlsx formats."); } }
From source file:uk.ac.bbsrc.tgac.miso.spring.util.FormUtils.java
License:Open Source License
public static void createSampleExportForm(File outpath, JSONArray jsonArray) throws Exception { InputStream in = null;//from w w w. j a v a 2 s.c om in = FormUtils.class.getResourceAsStream("/forms/ods/export_samples.xlsx"); if (in != null) { XSSFWorkbook oDoc = new XSSFWorkbook(in); XSSFSheet sheet = oDoc.getSheet("samples_export"); FileOutputStream fileOut = new FileOutputStream(outpath); int i = 5; for (JSONObject jsonObject : (Iterable<JSONObject>) jsonArray) { if ("sampleinwell".equals(jsonObject.getString("name"))) { String sampleinwell = jsonObject.getString("value"); // "sampleid:wellid:samplealias:projectname:projectalias:dnaOrRNA" String sampleId = sampleinwell.split(":")[0]; String wellId = sampleinwell.split(":")[1]; String sampleAlias = sampleinwell.split(":")[2]; String projectName = sampleinwell.split(":")[3]; String projectAlias = sampleinwell.split(":")[4]; String dnaOrRNA = sampleinwell.split(":")[5]; XSSFRow row = sheet.createRow(i); XSSFCell cellA = row.createCell(0); cellA.setCellValue(projectName); XSSFCell cellB = row.createCell(1); cellB.setCellValue(projectAlias); XSSFCell cellC = row.createCell(2); cellC.setCellValue(sampleId); XSSFCell cellD = row.createCell(3); cellD.setCellValue(sampleAlias); XSSFCell cellE = row.createCell(4); cellE.setCellValue(wellId); XSSFCell cellG = row.createCell(6); XSSFCell cellH = row.createCell(7); XSSFCell cellI = row.createCell(8); XSSFCell cellL = row.createCell(11); if ("R".equals(dnaOrRNA)) { cellG.setCellValue("NA"); cellL.setCellFormula("1000/H" + (i + 1)); } else if ("D".equals(dnaOrRNA)) { cellH.setCellValue("NA"); cellI.setCellValue("NA"); cellL.setCellFormula("1000/G" + (i + 1)); } XSSFCell cellM = row.createCell(12); cellM.setCellFormula("50-L" + (i + 1)); i++; } } oDoc.write(fileOut); fileOut.close(); } else { throw new IOException("Could not read from resource."); } }