List of usage examples for org.apache.poi.ss.util CellRangeAddress CellRangeAddress
public CellRangeAddress(int firstRow, int lastRow, int firstCol, int lastCol)
From source file:co.turnus.analysis.data.bottlenecks.io.XlsAlgoBottlenecksDataWriter.java
License:Open Source License
private void writeActorsTable(HSSFWorkbook workbook, HotspotsDataAnalyser analyzer) { HSSFSheet sheet = workbook.createSheet("Actors"); // Actors Results Cell cell = sheet.createRow(0).createCell(0); HSSFRichTextString title = new HSSFRichTextString("Actors Results"); title.applyFont(titleFont);// w ww . j a v a 2 s .c o m cell.setCellValue(title); Row row = sheet.createRow(1); sheet.addMergedRegion(new CellRangeAddress(1, 3, 0, 0)); row.createCell(0).setCellValue("Actor"); sheet.addMergedRegion(new CellRangeAddress(1, 3, 1, 1)); row.createCell(1).setCellValue("Class"); sheet.addMergedRegion(new CellRangeAddress(1, 1, 2, 6)); row.createCell(2).setCellValue("Total Executions"); sheet.addMergedRegion(new CellRangeAddress(1, 1, 7, 11)); row.createCell(7).setCellValue("Non Deferrable Executions"); sheet.addMergedRegion(new CellRangeAddress(1, 1, 12, 16)); row.createCell(12).setCellValue("Critical Executions"); row = sheet.createRow(2); sheet.addMergedRegion(new CellRangeAddress(2, 2, 2, 3)); row.createCell(2).setCellValue("Executions"); sheet.addMergedRegion(new CellRangeAddress(2, 2, 4, 6)); row.createCell(4).setCellValue("Clock Cycles"); sheet.addMergedRegion(new CellRangeAddress(2, 2, 7, 8)); row.createCell(7).setCellValue("Executions"); sheet.addMergedRegion(new CellRangeAddress(2, 2, 9, 11)); row.createCell(9).setCellValue("Clock Cycles"); sheet.addMergedRegion(new CellRangeAddress(2, 2, 12, 13)); row.createCell(12).setCellValue("Executions"); sheet.addMergedRegion(new CellRangeAddress(2, 2, 14, 16)); row.createCell(14).setCellValue("Clock Cycles"); row = sheet.createRow(3); row.createCell(2).setCellValue("%"); row.createCell(3).setCellValue("abs"); row.createCell(4).setCellValue("%"); row.createCell(5).setCellValue("mean"); row.createCell(6).setCellValue("variance"); row.createCell(7).setCellValue("%"); row.createCell(8).setCellValue("abs"); row.createCell(9).setCellValue("%"); row.createCell(10).setCellValue("mean"); row.createCell(11).setCellValue("variance"); row.createCell(12).setCellValue("%"); row.createCell(13).setCellValue("abs"); row.createCell(14).setCellValue("%"); row.createCell(15).setCellValue("mean"); row.createCell(16).setCellValue("variance"); Map<Actor, ExtendExecData> aMap = analyzer.getSumDataMap(Actor.class, Key.CRITICAL_CLOCKCYCLES, Order.DECREASING); // row index int rowi = 4; for (Entry<Actor, ExtendExecData> entry : aMap.entrySet()) { Actor actor = entry.getKey(); ExtendExecData exec = entry.getValue(); row = sheet.createRow(rowi); rowi++; row.createCell(0).setCellValue(actor.getId()); row.createCell(1).setCellValue(actor.getActorClass().getName()); cell = row.createCell(2); cell.setCellFormula("D" + rowi + "/Summary!A14*100"); row.createCell(3).setCellValue(exec.getTotalExec().getExecutions()); cell = row.createCell(4); cell.setCellFormula("F" + rowi + "/Summary!B14*100"); row.createCell(5).setCellValue(exec.getTotalExec().getClockCyclesMean()); row.createCell(6).setCellValue(exec.getTotalExec().getClockCyclesVariance()); cell = row.createCell(7); cell.setCellFormula("I" + rowi + "/Summary!E14*100"); row.createCell(8).setCellValue(exec.getNotDeferrableExec().getExecutions()); cell = row.createCell(9); cell.setCellFormula("K" + rowi + "/Summary!G14*100"); row.createCell(10).setCellValue(exec.getNotDeferrableExec().getClockCyclesMean()); row.createCell(11).setCellValue(exec.getNotDeferrableExec().getClockCyclesVariance()); cell = row.createCell(12); cell.setCellFormula("N" + rowi + "/Summary!J14*100"); row.createCell(13).setCellValue(exec.getCriticalExec().getExecutions()); cell = row.createCell(14); cell.setCellFormula("P" + rowi + "/Summary!L14*100"); row.createCell(15).setCellValue(exec.getCriticalExec().getClockCyclesMean()); row.createCell(16).setCellValue(exec.getCriticalExec().getClockCyclesVariance()); } }
From source file:co.turnus.analysis.data.bottlenecks.io.XlsAlgoBottlenecksDataWriter.java
License:Open Source License
private void writeSummary(HSSFWorkbook workbook, Network network, HotspotsDataAnalyser analyzer) { HSSFSheet sheet = workbook.createSheet("Summary"); // Network Results Cell cell = sheet.createRow(0).createCell(0); HSSFRichTextString title = new HSSFRichTextString("Hotspots and Algorithmic Bottlenecks Report Summary"); title.applyFont(titleFont);/*from w ww . j a v a 2s .c om*/ cell.setCellValue(title); // network name Row row = sheet.createRow(2); row.createCell(0).setCellValue("Network"); row.createCell(1).setCellValue(network.getName()); // network cal project row = sheet.createRow(3); row.createCell(0).setCellValue("CAL Project"); row.createCell(1).setCellValue(network.getCalProject()); // network source file row = sheet.createRow(4); row.createCell(0).setCellValue("Source File"); row.createCell(1).setCellValue(network.getSourceFile()); // network version sheet.addMergedRegion(new CellRangeAddress(5, 7, 0, 0)); row = sheet.createRow(5); row.createCell(0).setCellValue("Version"); row.createCell(1).setCellValue("Id"); row.createCell(2).setCellValue(network.getVersion().getId()); row = sheet.createRow(6); row.createCell(1).setCellValue("Last Modification Date"); cell = row.createCell(2); cell.setCellValue(network.getVersion().getLastModificationDate()); cell.setCellStyle(cellStyle); row = sheet.createRow(7); row.createCell(1).setCellValue("Versioning Date"); cell = row.createCell(2); cell.setCellValue(network.getVersion().getVersioningDate()); cell.setCellStyle(cellStyle); // [total | non deferrable | critical] row = sheet.createRow(10); sheet.addMergedRegion(new CellRangeAddress(10, 10, 0, 2)); cell = row.createCell(0); cell.setCellValue("Total Executions"); sheet.addMergedRegion(new CellRangeAddress(10, 10, 3, 7)); cell = row.createCell(3); cell.setCellValue("Non Deferrable Executions"); sheet.addMergedRegion(new CellRangeAddress(10, 10, 8, 12)); cell = row.createCell(8); cell.setCellValue("Critical Executions"); // [Executions | Workload | slack || Executions | workload || Executions // | workload ] row = sheet.createRow(11); sheet.addMergedRegion(new CellRangeAddress(11, 12, 0, 0)); cell = row.createCell(0); cell.setCellValue("Executions"); sheet.addMergedRegion(new CellRangeAddress(11, 11, 1, 2)); cell = row.createCell(1); cell.setCellValue("Clock Cycles"); sheet.addMergedRegion(new CellRangeAddress(11, 11, 3, 4)); cell = row.createCell(3); cell.setCellValue("Executions"); sheet.addMergedRegion(new CellRangeAddress(11, 11, 5, 7)); cell = row.createCell(5); cell.setCellValue("Clock Cycles"); sheet.addMergedRegion(new CellRangeAddress(11, 11, 8, 9)); cell = row.createCell(8); cell.setCellValue("Executions"); sheet.addMergedRegion(new CellRangeAddress(11, 11, 10, 12)); cell = row.createCell(10); cell.setCellValue("Clock Cycles"); // [* | mean , variance, % ... ] row = sheet.createRow(12); row.createCell(1).setCellValue("mean"); row.createCell(2).setCellValue("variance"); row.createCell(3).setCellValue("%"); row.createCell(4).setCellValue("abs"); row.createCell(5).setCellValue("%"); row.createCell(6).setCellValue("mean"); row.createCell(7).setCellValue("variance"); row.createCell(8).setCellValue("%"); row.createCell(9).setCellValue("abs"); row.createCell(10).setCellValue("%"); row.createCell(11).setCellValue("mean"); row.createCell(12).setCellValue("variance"); // write down data ExtendExecData sumData = analyzer.getSumData(); row = sheet.createRow(13); row.createCell(0).setCellValue(sumData.getTotalExec().getExecutions()); row.createCell(1).setCellValue(sumData.getTotalExec().getClockCyclesMean()); row.createCell(2).setCellValue(sumData.getTotalExec().getClockCyclesVariance()); cell = row.createCell(3); cell.setCellFormula("E14/A14*100"); row.createCell(4).setCellValue(sumData.getNotDeferrableExec().getExecutions()); cell = row.createCell(5); cell.setCellFormula("G14/B14*100"); row.createCell(6).setCellValue(sumData.getNotDeferrableExec().getClockCyclesMean()); row.createCell(7).setCellValue(sumData.getNotDeferrableExec().getClockCyclesVariance()); cell = row.createCell(8); cell.setCellFormula("J14/A14*100"); row.createCell(9).setCellValue(sumData.getCriticalExec().getExecutions()); cell = row.createCell(10); cell.setCellFormula("L14/B14*100"); row.createCell(11).setCellValue(sumData.getCriticalExec().getClockCyclesMean()); row.createCell(12).setCellValue(sumData.getCriticalExec().getClockCyclesVariance()); }
From source file:co.turnus.analysis.data.buffers.io.XlsBufferMinimizationDataWriter.java
License:Open Source License
private void writeData(HSSFWorkbook workbook, BuffersData data, Network netork, String algorithm, int solutionId) { HSSFSheet sheet = workbook.createSheet("Solution " + solutionId); Cell cell = sheet.createRow(0).createCell(0); HSSFRichTextString title = new HSSFRichTextString(algorithm + " Results"); title.applyFont(titleFont);// w w w . jav a 2s . c om cell.setCellValue(title); Row row = sheet.createRow(3); sheet.addMergedRegion(new CellRangeAddress(3, 3, 0, 3)); row.createCell(0).setCellValue("Algorithm specific Parameters"); row = sheet.createRow(4); int cellNum = 0; for (String attrName : data.getKeyAttributes()) { row.createCell(cellNum++).setCellValue(attrName); Object val = data.getAttribute(attrName); row.createCell(cellNum++).setCellValue(val.toString()); } row = sheet.createRow(1); sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 5)); row.createCell(0).setCellValue("Generic Parameters"); row = sheet.createRow(2); row.createCell(0).setCellValue("Total bits"); row.createCell(1).setCellValue(data.getTotalBitSize()); row.createCell(2).setCellValue("Total Tokens"); row.createCell(3).setCellValue(data.getTotalTokenSize()); row.createCell(4).setCellValue("Solution Time (ms)"); row.createCell(5).setCellValue(data.getExecutionTime()); row.createCell(6).setCellValue("number of Actors"); row.createCell(7).setCellValue(netork.getActors().size()); row.createCell(8).setCellValue("number of Fifos"); row.createCell(9).setCellValue(netork.getFifos().size()); row.createCell(10).setCellValue("bit accurate"); row.createCell(11).setCellValue(data.isBitAccurate()); row.createCell(12).setCellValue("deadlock free"); row.createCell(13).setCellValue(data.isDeadlockFree()); row = sheet.createRow(5); sheet.addMergedRegion(new CellRangeAddress(5, 5, 0, 6)); row.createCell(0).setCellValue("Buffers Size Configuration"); row = sheet.createRow(6); sheet.addMergedRegion(new CellRangeAddress(6, 7, 0, 0)); row.createCell(0).setCellValue("Source Actor"); sheet.addMergedRegion(new CellRangeAddress(6, 7, 1, 1)); row.createCell(1).setCellValue("Source Port"); sheet.addMergedRegion(new CellRangeAddress(6, 7, 2, 2)); row.createCell(2).setCellValue("Traget Actor"); sheet.addMergedRegion(new CellRangeAddress(6, 7, 3, 4)); row.createCell(3).setCellValue("Traget Port"); sheet.addMergedRegion(new CellRangeAddress(6, 7, 4, 4)); row.createCell(4).setCellValue("Type"); sheet.addMergedRegion(new CellRangeAddress(6, 6, 5, 6)); row.createCell(5).setCellValue("Size"); sheet.addMergedRegion(new CellRangeAddress(6, 6, 8, 9)); row.createCell(8).setCellValue("Algorithm Starting Point"); row = sheet.createRow(7); row.createCell(5).setCellValue("bit"); row.createCell(6).setCellValue("tokens"); row.createCell(8).setCellValue("bit"); row.createCell(9).setCellValue("tokens"); int rowi = 8; for (Entry<Fifo, Integer> entry : data.getFifosSize().getFifosSizeMap().entrySet()) { Fifo fifo = entry.getKey(); int tokens = entry.getValue(); row = sheet.createRow(rowi++); row.createCell(0).setCellValue(fifo.getSourceActor().getId()); row.createCell(1).setCellValue(fifo.getSourcePort().getName()); row.createCell(2).setCellValue(fifo.getTargetActor().getId()); row.createCell(3).setCellValue(fifo.getTargetPort().getName()); row.createCell(4).setCellValue(fifo.getType().toString()); row.createCell(5).setCellValue(tokens * fifo.getType().getBits()); row.createCell(6).setCellValue(tokens); // do the same for the starting point (if it exists) tokens = data.getStartingPoint().containsKey(fifo) ? data.getStartingPoint().get(fifo) : 0; row.createCell(8).setCellValue(tokens * fifo.getType().getBits()); row.createCell(9).setCellValue(tokens); } }
From source file:co.turnus.analysis.data.partitioning.io.XlsPartitioningDataWriter.java
License:Open Source License
private void writeData(HSSFWorkbook workbook, PartitionsData data, Network network, String algorithm, int solutionId) { HSSFSheet sheet = workbook.createSheet("Partition " + solutionId); Cell cell = sheet.createRow(0).createCell(0); HSSFRichTextString title = new HSSFRichTextString(algorithm + " Results"); title.applyFont(titleFont);//from www . j av a2s. co m cell.setCellValue(title); Row row = sheet.createRow(3); sheet.addMergedRegion(new CellRangeAddress(3, 3, 0, 3)); row.createCell(0).setCellValue("Algorithm specific Parameters"); row = sheet.createRow(4); int cellNum = 0; for (String attrName : data.getKeyAttributes()) { row.createCell(cellNum++).setCellValue(attrName); Object val = data.getAttribute(attrName); row.createCell(cellNum++).setCellValue(val.toString()); } row = sheet.createRow(5); sheet.addMergedRegion(new CellRangeAddress(5, 5, 0, 1)); row.createCell(0).setCellValue("Partitions"); row = sheet.createRow(6); row.createCell(0).setCellValue("id"); row.createCell(1).setCellValue("Actors"); int rown = 7; row = sheet.createRow(rown); for (ActorsMapping p : data.getMapping().getActorsMappings()) { row.createCell(0).setCellValue(p.getId()); for (Actor a : p.getActors()) { row.createCell(1).setCellValue(a.getId()); row = sheet.createRow(++rown); } } }
From source file:co.turnus.analysis.data.pipelining.io.XlsSimplePipeliningDataWriter.java
License:Open Source License
public void write(SimplePipelingData report, File file) { try {//from w ww . jav a 2 s . co m HSSFWorkbook workbook = new HSSFWorkbook(); titleFont = workbook.createFont(); titleFont.setFontName("Arial"); titleFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); cellStyle = workbook.createCellStyle(); cellStyle.setDataFormat(workbook.getCreationHelper().createDataFormat().getFormat("m/d/yy h:mm")); HSSFSheet sheet = workbook.createSheet("Pipelinable <Actor, Action>"); // Action Actor Class Results Cell cell = sheet.createRow(0).createCell(0); HSSFRichTextString title = new HSSFRichTextString("Action and Actor Pipelining Results"); title.applyFont(titleFont); cell.setCellValue(title); Row row = sheet.createRow(1); sheet.addMergedRegion(new CellRangeAddress(1, 3, 0, 0)); row.createCell(0).setCellValue("Actor"); sheet.addMergedRegion(new CellRangeAddress(1, 3, 1, 1)); row.createCell(1).setCellValue("Action"); sheet.addMergedRegion(new CellRangeAddress(1, 3, 2, 2)); row.createCell(2).setCellValue("pipelinable"); sheet.addMergedRegion(new CellRangeAddress(1, 1, 3, 10)); row.createCell(3).setCellValue("Consecutive Executions"); sheet.addMergedRegion(new CellRangeAddress(1, 3, 11, 11)); row.createCell(11).setCellValue("Splittable Actions"); row = sheet.createRow(2); sheet.addMergedRegion(new CellRangeAddress(2, 2, 3, 6)); row.createCell(3).setCellValue("Pipelinable"); sheet.addMergedRegion(new CellRangeAddress(2, 2, 7, 10)); row.createCell(7).setCellValue("Unconstrained"); row = sheet.createRow(3); row.createCell(3).setCellValue("min"); row.createCell(4).setCellValue("mean"); row.createCell(5).setCellValue("max"); row.createCell(6).setCellValue("var"); row.createCell(7).setCellValue("min"); row.createCell(8).setCellValue("mean"); row.createCell(9).setCellValue("max"); row.createCell(10).setCellValue("var"); int rowId = 4; Map<Actor, Map<Action, SimpleActionPipeliningData>> table = report.asTable().rowMap(); for (Map<Action, SimpleActionPipeliningData> ac : table.values()) { for (SimpleActionPipeliningData data : ac.values()) { row = sheet.createRow(rowId); row.createCell(0).setCellValue(data.getActor().getId()); row.createCell(1).setCellValue(data.getAction().getId()); row.createCell(2).setCellValue(data.isPipelinable()); StatisticalData stat = data.getPipelinableRepetitions(); if (stat.getSamples() > 0) { row.createCell(3).setCellValue(stat.getMin()); row.createCell(4).setCellValue(stat.getMean()); row.createCell(5).setCellValue(stat.getMax()); row.createCell(6).setCellValue(stat.getVariance()); } else { row.createCell(3).setCellValue("-"); row.createCell(4).setCellValue("-"); row.createCell(5).setCellValue("-"); row.createCell(6).setCellValue("-"); } stat = data.getUnconstrainedRepetitions(); if (stat.getSamples() > 0) { row.createCell(7).setCellValue(stat.getMin()); row.createCell(8).setCellValue(stat.getMean()); row.createCell(9).setCellValue(stat.getMax()); row.createCell(10).setCellValue(stat.getVariance()); } else { row.createCell(7).setCellValue("-"); row.createCell(8).setCellValue("-"); row.createCell(9).setCellValue("-"); row.createCell(10).setCellValue("-"); } StringBuffer b = new StringBuffer(); for (Action action : data.getSplittableActions()) { b.append(action.getId()).append(" "); } row.createCell(11).setCellValue(b.toString()); rowId++; } } OutputStream out = new FileOutputStream(file); out = new BufferedOutputStream(out); workbook.write(out); out.close(); } catch (Exception e) { throw new TurnusRuntimeException("Error writing the excel file " + file, e.getCause()); } }
From source file:co.turnus.profiling.io.XlsProfilingDataWriter.java
License:Open Source License
private void writeFifosData(HSSFWorkbook workbook, ProfilingData data) { HSSFSheet sheet = workbook.createSheet("Fifos Data"); // Action Actor Class Results Cell cell = sheet.createRow(0).createCell(0); HSSFRichTextString title = new HSSFRichTextString("Communication data summary"); title.applyFont(titleFont);//from w ww. jav a 2 s. c o m cell.setCellValue(title); int rowIdx = 2; Row row = sheet.createRow(rowIdx++); sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, 1)); row.createCell(0).setCellValue("Source"); sheet.addMergedRegion(new CellRangeAddress(2, 2, 2, 3)); row.createCell(2).setCellValue("Target"); sheet.addMergedRegion(new CellRangeAddress(2, 2, 4, 5)); row.createCell(4).setCellValue("Type"); sheet.addMergedRegion(new CellRangeAddress(2, 2, 6, 12)); row.createCell(6).setCellValue("Writing (tokens)"); sheet.addMergedRegion(new CellRangeAddress(2, 2, 13, 20)); row.createCell(13).setCellValue("Reading (tokens)"); // header row = sheet.createRow(rowIdx++); row.createCell(0).setCellValue("Actor"); row.createCell(1).setCellValue("Out Port"); row.createCell(2).setCellValue("Actor"); row.createCell(3).setCellValue("In Port"); // type row.createCell(4).setCellValue("Name"); row.createCell(5).setCellValue("Bit:Token"); // writing row.createCell(6).setCellValue("hits"); row.createCell(7).setCellValue("misses"); row.createCell(8).setCellValue("total"); row.createCell(9).setCellValue("average"); row.createCell(10).setCellValue("min"); row.createCell(11).setCellValue("max"); row.createCell(12).setCellValue("variance"); // reading row.createCell(13).setCellValue("peeks"); row.createCell(14).setCellValue("hits"); row.createCell(15).setCellValue("misses"); row.createCell(16).setCellValue("total"); row.createCell(17).setCellValue("average"); row.createCell(18).setCellValue("min"); row.createCell(19).setCellValue("max"); row.createCell(20).setCellValue("variance"); for (FifoProfilingData fData : data.getFifosData()) { row = sheet.createRow(rowIdx++); Fifo fifo = fData.getFifo(); // header row.createCell(0).setCellValue(fifo.getSourceActor().getId()); row.createCell(1).setCellValue(fifo.getSourcePort().getName()); row.createCell(2).setCellValue(fifo.getTargetActor().getId()); row.createCell(3).setCellValue(fifo.getTargetPort().getName()); // type row.createCell(4).setCellValue(fifo.getType().toString()); row.createCell(5).setCellValue(fifo.getType().getBits()); // writes row.createCell(6).setCellValue(fData.getWriteHit()); row.createCell(7).setCellValue(fData.getWriteMiss()); row.createCell(8).setCellValue(fData.getWriteTokens().getSum()); row.createCell(9).setCellValue(fData.getWriteTokens().getMean()); row.createCell(10).setCellValue(fData.getWriteTokens().getMin()); row.createCell(11).setCellValue(fData.getWriteTokens().getMax()); row.createCell(12).setCellValue(fData.getWriteTokens().getVariance()); // reads row.createCell(13).setCellValue(fData.getPeeks()); row.createCell(14).setCellValue(fData.getReadHit()); row.createCell(15).setCellValue(fData.getWriteMiss()); row.createCell(16).setCellValue(fData.getReadTokens().getSum()); row.createCell(17).setCellValue(fData.getWriteTokens().getMean()); row.createCell(18).setCellValue(fData.getWriteTokens().getMin()); row.createCell(19).setCellValue(fData.getWriteTokens().getMax()); row.createCell(20).setCellValue(fData.getWriteTokens().getVariance()); } }
From source file:com.aan.girsang.client.ui.master.barang.BarangPanel.java
private void exportExcel(List<Barang> dataList) throws IOException { if (dataList != null && !dataList.isEmpty()) { HSSFWorkbook workBook = new HSSFWorkbook(); HSSFSheet sheet = workBook.createSheet(); HSSFSheet worksheet = workBook.createSheet("Sheet 0"); // Nama Field Row judul = sheet.createRow((short) 0); Cell cell = judul.createCell((short) 0); cell.setCellValue("This is a test of merging"); HSSFRow headingRow = sheet.createRow((short) 2); headingRow.createCell((short) 0).setCellValue("ID"); headingRow.createCell((short) 1).setCellValue("BARCODE 1"); headingRow.createCell((short) 2).setCellValue("BARCODE 2"); headingRow.createCell((short) 3).setCellValue("NAMA BARANG"); headingRow.createCell((short) 4).setCellValue("GOLONGAN"); headingRow.createCell((short) 5).setCellValue("SAT. JUAL"); headingRow.createCell((short) 6).setCellValue("ST. TOKO"); headingRow.createCell((short) 7).setCellValue("ST. GUDANG"); headingRow.createCell((short) 8).setCellValue("SAT. BELI"); headingRow.createCell((short) 9).setCellValue("ISI PEM."); headingRow.createCell((short) 10).setCellValue("HRG PEM."); headingRow.createCell((short) 11).setCellValue("HRG NORMAL"); headingRow.createCell((short) 12).setCellValue("HRG MEMBER"); headingRow.createCell((short) 13).setCellValue("JUAL"); int panjang = headingRow.getLastCellNum() - 1; short rowNo = 3; sheet.addMergedRegion(new CellRangeAddress(0, //first row (0-based) 0, //last row (0-based) 0, //first column (0-based) panjang //last column (0-based) ));//from www .j a va2s .c o m CellStyle styleData = workBook.createCellStyle(); styleData.setBorderBottom(CellStyle.BORDER_THIN); styleData.setBorderRight(CellStyle.BORDER_THIN); styleData.setBorderLeft(CellStyle.BORDER_THIN); for (Barang b : dataList) { HSSFRow row = sheet.createRow(rowNo); String jual; if (b.getJual() == true) { jual = "Jual"; } else { jual = "Tidak"; } row.createCell((short) 0).setCellValue(b.getPlu()); row.createCell((short) 1).setCellValue(b.getBarcode1()); row.createCell((short) 2).setCellValue(b.getBarcode2()); row.createCell((short) 3).setCellValue(b.getNamaBarang()); row.createCell((short) 4).setCellValue(b.getGolonganBarang().getGolonganBarang()); row.createCell((short) 5).setCellValue(b.getSatuan()); row.createCell((short) 6).setCellValue(b.getStokToko()); row.createCell((short) 7).setCellValue(b.getStokGudang()); row.createCell((short) 8).setCellValue(b.getSatuanPembelian()); row.createCell((short) 9).setCellValue(b.getIsiPembelian()); row.createCell((short) 10).setCellValue(TextComponentUtils.formatNumber(b.getHargaBeli())); row.createCell((short) 11).setCellValue(TextComponentUtils.formatNumber(b.getHargaNormal())); row.createCell((short) 12).setCellValue(TextComponentUtils.formatNumber(b.getHargaMember())); row.createCell((short) 13).setCellValue(jual); for (int i = 0; i <= 13; i++) { row.getCell((short) i).setCellStyle(styleData); } rowNo++; } for (int i = 0; i <= 13; i++) { sheet.autoSizeColumn(i); } Font font = workBook.createFont(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); //style judul CellStyle styleTitle = workBook.createCellStyle(); styleTitle.setAlignment(CellStyle.ALIGN_CENTER_SELECTION); styleTitle.setFont(font); judul.getCell(0).setCellStyle(styleTitle); //judul field CellStyle styleHeading = workBook.createCellStyle(); styleHeading.setFont(font); styleHeading.setAlignment(CellStyle.ALIGN_CENTER_SELECTION); styleHeading.setBorderBottom(CellStyle.BORDER_THIN); styleHeading.setBorderTop(CellStyle.BORDER_THIN); styleHeading.setBorderRight(CellStyle.BORDER_THIN); styleHeading.setBorderLeft(CellStyle.BORDER_THIN); for (int i = 0; i < headingRow.getLastCellNum(); i++) {//For each cell in the row headingRow.getCell(i).setCellStyle(styleHeading);//Set the style } String file = "D:/Student_detais.xls"; try { try (FileOutputStream fos = new FileOutputStream(file)) { workBook.write(fos); } JOptionPane.showMessageDialog(null, "Sukses"); } catch (FileNotFoundException e) { System.out.println("Invalid directory or file not found"); } catch (IOException e) { System.out.println("Error occurred while writting excel file to directory"); } } }
From source file:com.accounting.accountMBean.DifferentAccReports.java
public void postProcessXLS(Object document) { String startDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate1"); ndc = new NepaliDateConverter(); HSSFWorkbook wb = (HSSFWorkbook) document; HSSFCellStyle headerCellStyle = wb.createCellStyle(); HSSFCellStyle headerCellStyle1 = wb.createCellStyle(); HSSFCellStyle headerCellStyle2 = wb.createCellStyle(); Font headerFont = wb.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); headerFont.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle.setFont(headerFont); headerCellStyle.setAlignment(CellStyle.ALIGN_CENTER); Font headerFont1 = wb.createFont(); headerFont1.setBoldweight(Font.U_SINGLE_ACCOUNTING); headerFont1.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle1.setFont(headerFont); headerCellStyle1.setAlignment(CellStyle.ALIGN_RIGHT); HSSFSheet sheet = wb.getSheetAt(0);//ww w . j a v a2s . c o m int noOfColumns = sheet.getRow(0).getLastCellNum(); Font headerFont3 = wb.createFont(); headerFont3.setBoldweight(Font.U_SINGLE); headerFont3.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle2.setFont(headerFont1); headerCellStyle2.setAlignment(CellStyle.ALIGN_RIGHT); for (int i = 0; i < noOfColumns; i++) { sheet.autoSizeColumn(i); } sheet.shiftRows(0, sheet.getLastRowNum(), 4); HSSFRow firstRow = sheet.createRow(1); firstRow.createCell(0).setCellValue(PageName); firstRow.getCell(0).setCellStyle(headerCellStyle); HSSFRow secondRow = sheet.createRow(0); secondRow.createCell(0).setCellValue(getLoggedInOffice().getName()); secondRow.getCell(0).setCellStyle(headerCellStyle); HSSFRow thirdRow = sheet.createRow(3); String generatedDate = ndc.convertToNepaliDate(new Date()); SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss a"); String time = sdf.format(new Date()); thirdRow.createCell(0) .setCellValue("Generated on:" + generatedDate + " " + time + " by:" + getLoggedInUser().getName()); thirdRow.getCell(0).setCellStyle(headerCellStyle2); HSSFRow fourthRow = sheet.createRow(2); fourthRow.createCell(0).setCellValue("To Date: " + startDateString); fourthRow.getCell(0).setCellStyle(headerCellStyle); sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 4)); sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 4)); sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, 4)); sheet.addMergedRegion(new CellRangeAddress(3, 3, 0, 4)); // HSSFRow lastRow; // double totalDr = 0; // for (Row row : sheet) { // if (row.getRowNum() > 4) { // String cost = row.getCell(3).getStringCellValue(); // if (cost != null && !cost.isEmpty()) { // row.getCell(3).setCellType(HSSFCell.CELL_TYPE_BLANK); // row.getCell(3).setCellType(HSSFCell.CELL_TYPE_NUMERIC); // row.getCell(3).setCellValue(Double.parseDouble(cost.replace(",", ""))); // totalDr += Double.parseDouble(cost.replace(",", "")); // } // } // } }
From source file:com.accounting.accountMBean.DifferentAccReports.java
public void postProcessXLSAgeingReport(Object document) { ndc = new NepaliDateConverter(); String startDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate4"); String endDateReading = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate5"); HSSFWorkbook wb = (HSSFWorkbook) document; HSSFCellStyle headerCellStyle = wb.createCellStyle(); HSSFCellStyle headerCellStyle1 = wb.createCellStyle(); HSSFCellStyle headerCellStyle2 = wb.createCellStyle(); Font headerFont = wb.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); headerFont.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle.setFont(headerFont); headerCellStyle.setAlignment(CellStyle.ALIGN_CENTER); Font headerFont1 = wb.createFont(); headerFont1.setBoldweight(Font.U_SINGLE_ACCOUNTING); headerFont1.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle1.setFont(headerFont); headerCellStyle1.setAlignment(CellStyle.ALIGN_RIGHT); HSSFSheet sheet = wb.getSheetAt(0);//from w ww . j a v a 2 s . com int noOfColumns = sheet.getRow(0).getLastCellNum(); Font headerFont3 = wb.createFont(); headerFont3.setBoldweight(Font.U_SINGLE); headerFont3.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle2.setFont(headerFont1); headerCellStyle2.setAlignment(CellStyle.ALIGN_RIGHT); for (int i = 0; i < noOfColumns; i++) { sheet.autoSizeColumn(i); } sheet.shiftRows(0, sheet.getLastRowNum(), 4); HSSFRow firstRow = sheet.createRow(1); firstRow.createCell(0).setCellValue(PageName); firstRow.getCell(0).setCellStyle(headerCellStyle); HSSFRow secondRow = sheet.createRow(0); secondRow.createCell(0).setCellValue(getLoggedInOffice().getName()); secondRow.getCell(0).setCellStyle(headerCellStyle); HSSFRow thirdRow = sheet.createRow(3); String generatedDate = ndc.convertToNepaliDate(new Date()); SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss a"); String time = sdf.format(new Date()); thirdRow.createCell(0) .setCellValue("Generated on:" + generatedDate + " " + time + " by:" + getLoggedInUser().getName()); thirdRow.getCell(0).setCellStyle(headerCellStyle2); HSSFRow fourthRow = sheet.createRow(2); fourthRow.createCell(0).setCellValue("From: " + startDateString + " To: " + endDateReading); fourthRow.getCell(0).setCellStyle(headerCellStyle); sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6)); sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 6)); sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, 6)); sheet.addMergedRegion(new CellRangeAddress(3, 3, 0, 6)); for (Row row : sheet) { if (row.getRowNum() > 4) { String cost = row.getCell(4).getStringCellValue(); if (cost != null && !cost.isEmpty()) { row.getCell(4).setCellType(HSSFCell.CELL_TYPE_BLANK); row.getCell(4).setCellType(HSSFCell.CELL_TYPE_NUMERIC); row.getCell(4).setCellValue(Double.parseDouble(cost.replace(",", ""))); } } } }
From source file:com.accounting.accountMBean.DifferentAccReports.java
public void simplePostProcessXLSX(Object document) { String startDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate4"); String endDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("nepaliDate5"); XSSFWorkbook wb = (XSSFWorkbook) document; XSSFCellStyle headerCellStyle = wb.createCellStyle(); XSSFCellStyle headerCellStyle1 = wb.createCellStyle(); XSSFCellStyle headerCellStyle2 = wb.createCellStyle(); Font headerFont = wb.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); headerFont.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle.setFont(headerFont); headerCellStyle.setAlignment(CellStyle.ALIGN_CENTER); Font headerFont1 = wb.createFont(); headerFont1.setBoldweight(Font.U_SINGLE_ACCOUNTING); headerFont1.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle1.setFont(headerFont); headerCellStyle1.setAlignment(CellStyle.ALIGN_RIGHT); Font headerFont3 = wb.createFont(); headerFont3.setBoldweight(Font.U_SINGLE); headerFont3.setFontName(HSSFFont.FONT_ARIAL); headerCellStyle2.setFont(headerFont1); headerCellStyle2.setAlignment(CellStyle.ALIGN_RIGHT); XSSFSheet sheet = wb.getSheetAt(0);//w w w . j a v a2 s .co m int noOfColumns = sheet.getRow(2).getLastCellNum(); for (int i = 0; i < noOfColumns; i++) { sheet.autoSizeColumn(i); } sheet.shiftRows(0, sheet.getLastRowNum(), 4); XSSFRow firstRow = sheet.createRow(1); firstRow.createCell(0).setCellValue("SALES AGEING REPORT"); firstRow.getCell(0).setCellStyle(headerCellStyle); XSSFRow secondRow = sheet.createRow(0); secondRow.createCell(0).setCellValue(getLoggedInOffice().getName()); secondRow.getCell(0).setCellStyle(headerCellStyle); // XSSFRow thirdRow = sheet.createRow(3); String date = ndc.convertToNepaliDate(new Date()); SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss a"); String time = sdf.format(new Date()); thirdRow.createCell(0) .setCellValue("Generated on:" + date + " " + time + " by:" + getLoggedInUser().getName()); thirdRow.getCell(0).setCellStyle(headerCellStyle2); XSSFRow fourthRow = sheet.createRow(2); fourthRow.createCell(0).setCellValue("FROM: " + startDateString + " TO: " + endDateString); fourthRow.getCell(0).setCellStyle(headerCellStyle); sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 7)); sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 7)); sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, 7)); sheet.addMergedRegion(new CellRangeAddress(3, 3, 0, 7)); }