List of usage examples for org.apache.poi.ss.usermodel Row getCell
Cell getCell(int cellnum);
From source file:com.github.s4ke.worktimegen.Main.java
License:BEER-WARE LICENSE
public static void generateExcelSheet(int year, int month, List<Work> workObjs) throws IOException { try (InputStream is = Main.class.getResourceAsStream("/template_urlaub.xls")) { HSSFWorkbook workbook = new HSSFWorkbook(is); HSSFSheet sheet = workbook.getSheetAt(0); GregorianCalendar calendar = new GregorianCalendar(); calendar.set(year, month - 1, 1); sheet.getRow(7).getCell(2).setCellValue(DATE_FORMAT.format(calendar.getTime())); calendar.set(year, month - 1, calendar.getActualMaximum(Calendar.DAY_OF_MONTH)); sheet.getRow(7).getCell(4).setCellValue(DATE_FORMAT.format(calendar.getTime())); int startRow = 11; int endRow = 33; if (workObjs.size() > (endRow - startRow)) { throw new AssertionError("template has too few rows"); }//from w w w. ja v a2s. c om int curRow = startRow; for (Work work : workObjs) { Row row = sheet.getRow(curRow); row.getCell(0).setCellValue(work.date); row.getCell(1).setCellValue(pad(work.startHours) + ":" + pad(work.startMinutes)); row.getCell(2).setCellValue(pad(work.endHours) + ":" + pad(work.endMinutes)); ++curRow; } try (FileOutputStream fos = new FileOutputStream( new File("zeiterfassung_braun_" + year + "_" + month + ".xls"))) { workbook.write(fos); } } }
From source file:com.github.svrtm.xlreport.Cell.java
License:Apache License
Cell(final TR row, final int i, final CellOperation cellOperation) { super(row);/*from ww w.j av a 2 s. c o m*/ creationHelper = builder.sheet.getWorkbook().getCreationHelper(); final org.apache.poi.ss.usermodel.Row poiRow = row.poiRow; if (CREATE == cellOperation) poiCell = poiRow.createCell(i); else poiCell = CREATE_and_GET == cellOperation && poiRow.getCell(i) == null ? poiRow.createCell(i) : poiRow.getCell(i); }
From source file:com.github.svrtm.xlreport.Cells.java
License:Apache License
/** * Finalization of the implementation <code>Cells</code>. * * @return an instance of the implementation <code>Row</code> * @see com.github.svrtm.xlreport.Row#addCells(int) * @see com.github.svrtm.xlreport.Row#addCells(int...) *///from w w w . j a v a2 s. co m @SuppressWarnings("unchecked") public TR configureCells() { if (columnWidth == -1 && incrementValue == -1 && cellStyle == null) return (TR) row; int increment = incrementValue; for (final int i : indexesCells) { if (row.cells.get(i) == null) row.prepareNewCell(i).createCell(); final org.apache.poi.ss.usermodel.Row poiRow = row.poiRow; final Cell poiCell = poiRow.getCell(i); if (poiCell == null) throw new ReportBuilderException( format("A cell of number %d [row:%d] can't be found. Please, create a cell before using it", i, poiRow.getRowNum())); if (columnWidth != -1) poiCell.getSheet().setColumnWidth(i, columnWidth); if (incrementValue != -1) poiCell.setCellValue(increment++); if (enableAutoSize) setAutoSizeColumn(poiCell); if (cellStyle != null) if (row.cells.get(i).cellStyle == null) { // Apply a style to the cell final CellStyle poiStyle = cellStyle.getStyle(); poiCell.setCellStyle(poiStyle); final List<Cell> mergedCells = findMergedCells(poiCell); if (mergedCells != null) for (final Cell mergedCell : mergedCells) mergedCell.setCellStyle(poiStyle); } } return (TR) row; }
From source file:com.github.wnameless.workbookaccessor.WorkbookReader.java
License:Apache License
private RubyArray<String> rowToRubyArray(final Row row, boolean isCSV) { int colNum;//from w ww . j av a2 s . c om if (hasHeader) colNum = sheet.rowIterator().next().getLastCellNum(); else colNum = row.getLastCellNum(); return range(0, colNum - 1).map(new TransformBlock<Integer, Cell>() { @Override public Cell yield(Integer item) { return row.getCell(item); } }).map(cell2Str(isCSV)); }
From source file:com.github.xiilei.ecdiff.Processor.java
License:Apache License
public void diff() { try {//w ww. j a va 2 s .c o m logger.info("start ,src:" + job.getSrc() + ",dist:" + job.getDist()); Store store = this.getStoreFromSrc(); Workbook wb = readExcelFileByext(job.getDist()); this.font = wb.createFont(); this.font.setColor((short) 0xa); int rows_len = 0, i = 0, max_cells_len = 0; Sheet sheet = wb.getSheetAt(job.getDistSheet()); rows_len = sheet.getPhysicalNumberOfRows(); logger.info("Dist,open " + sheet.getSheetName() + " with " + rows_len + " rows"); for (i = 0; i < rows_len; i++) { Row row = sheet.getRow(i); max_cells_len = row.getPhysicalNumberOfCells(); if (!job.checkDistIndex(max_cells_len)) { logger.warn("Dist,The length of columns is too small at row " + i + ",length:" + max_cells_len); continue; } if (job.isByrow()) { cellComparer(store.get(i), row.getCell(job.getDistColumnIndex())); } else { cellComparer(store.get(getStringCellValue(row.getCell(job.getDistColumnIdIndex()))), row.getCell(job.getDistColumnIndex())); } } try (FileOutputStream out = new FileOutputStream(job.getOutFileName())) { wb.write(out); } logger.info("output file:" + job.getOutFileName()); } catch (Exception e) { logger.fatal(e.getMessage(), e); // e.printStackTrace(); } }
From source file:com.github.xiilei.ecdiff.Processor.java
License:Apache License
public Store getStoreFromSrc() throws IOException { Workbook wb = readExcelFileByext(job.getSrc()); Row row = null; int max_cells_len = 0; int rows_len = 0; Sheet sheet = wb.getSheetAt(job.getSrcSheet()); rows_len = sheet.getPhysicalNumberOfRows(); Store store = new Store(rows_len); logger.info("Src,open " + sheet.getSheetName() + " with " + rows_len + " rows"); for (int i = 0; i < rows_len; i++) { row = sheet.getRow(i);//from www . jav a 2 s. c o m max_cells_len = row.getPhysicalNumberOfCells(); if (!job.checkSrcIndex(max_cells_len)) { logger.warn("Src,The length of columns is too small at row " + i + ",length:" + max_cells_len); continue; } if (job.isByrow()) { store.put(i, row.getCell(job.getSrcColumnIndex())); } else { store.put(getStringCellValue(row.getCell(job.getSrcColumnIdIndex())), row.getCell(job.getSrcColumnIndex())); } } return store; }
From source file:com.globalsight.everest.qachecks.DITAQAChecker.java
License:Apache License
private Cell getCell(Row p_row, int index) { Cell cell = p_row.getCell(index); if (cell == null) cell = p_row.createCell(index);//from w ww.ja v a2s . c om return cell; }
From source file:com.globalsight.everest.qachecks.QAChecker.java
License:Apache License
private Cell getCell(Row p_row, int columnIndex) { Cell cell = p_row.getCell(columnIndex); if (cell == null) { cell = p_row.createCell(columnIndex); }/*w w w .j av a 2s . c o m*/ return cell; }
From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.generator.CommentsAnalysisReportGenerator.java
License:Apache License
/** * Create Report File.//from w w w. j av a2 s. c o m */ protected File getFile(String p_reportType, Job p_job, Workbook p_workBook) { String langInfo = null; // If the Workbook has only one sheet, the report name should contain language pair info, such as en_US_de_DE. if (p_workBook != null && p_workBook.getNumberOfSheets() == 1) { Sheet sheet = p_workBook.getSheetAt(0); String srcLang = null, trgLang = null; if (p_job != null) { srcLang = p_job.getSourceLocale().toString(); } if (srcLang == null) { Row languageInfoRow = sheet.getRow(LANGUAGE_INFO_ROW); if (languageInfoRow != null) { srcLang = languageInfoRow.getCell(0).getStringCellValue(); srcLang = srcLang.substring(srcLang.indexOf("[") + 1, srcLang.indexOf("]")); trgLang = languageInfoRow.getCell(1).getStringCellValue(); trgLang = trgLang.substring(trgLang.indexOf("[") + 1, trgLang.indexOf("]")); } else { Row dataRow = sheet.getRow(sheet.getLastRowNum()); if (dataRow != null) { try { long jobId = (long) dataRow.getCell(0).getNumericCellValue(); Job job = ServerProxy.getJobHandler().getJobById(jobId); srcLang = job.getSourceLocale().toString(); } catch (Exception e) { } } } } if (trgLang == null) { trgLang = sheet.getSheetName(); } if (srcLang != null && trgLang != null) { langInfo = srcLang + "_" + trgLang; } } return ReportHelper.getReportFile(p_reportType, p_job, ReportConstants.EXTENSION_XLSX, langInfo); }
From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.generator.ScorecardReportGenerator.java
License:Apache License
/** * Create Report File.//from www . jav a 2 s. c o m */ protected File getFile(String p_reportType, Job p_job, Workbook p_workBook) { String langInfo = null; // If the Workbook has only one sheet, the report name should contain language pair info, such as en_US_de_DE. if (p_workBook != null && p_workBook.getNumberOfSheets() == 1) { Sheet sheet = p_workBook.getSheetAt(0); String srcLang = null, trgLang = null; if (p_job != null) { srcLang = p_job.getSourceLocale().toString(); } if (srcLang == null) { Row languageInfoRow = sheet.getRow(1); if (languageInfoRow != null) { srcLang = languageInfoRow.getCell(0).getStringCellValue(); srcLang = srcLang.substring(srcLang.indexOf("[") + 1, srcLang.indexOf("]")); trgLang = languageInfoRow.getCell(1).getStringCellValue(); trgLang = trgLang.substring(trgLang.indexOf("[") + 1, trgLang.indexOf("]")); } else { Row dataRow = sheet.getRow(sheet.getLastRowNum()); if (dataRow != null) { try { long jobId = (long) dataRow.getCell(0).getNumericCellValue(); Job job = ServerProxy.getJobHandler().getJobById(jobId); srcLang = job.getSourceLocale().toString(); } catch (Exception e) { } } } } if (trgLang == null) { trgLang = sheet.getSheetName(); } if (srcLang != null && trgLang != null) { langInfo = srcLang + "_" + trgLang; } } return ReportHelper.getReportFile(p_reportType, p_job, ReportConstants.EXTENSION_XLSX, langInfo); }