protected void nextRow() { currentRowNumber++; currentRow = currentSheet.createRow(currentRowNumber); currentColumnNumber = -1; }
XSSFRow row = getRow(i); if (row == null) { row = createRow(i);
/** * this method return row on given index if row is null then create new row * * @param sheet * current sheet object * @param index * index of current row * @return this method return sheet row on given index * @since POI 4.0.0 */ private XSSFRow getRow(XSSFSheet sheet, int index) { if (sheet.getRow(index) != null) { return sheet.getRow(index); } else { return sheet.createRow(index); } }
/** * Tie a range of cell together so that they can be collapsed or expanded * * @param fromRow start row (0-based) * @param toRow end row (0-based) */ @Override public void groupRow(int fromRow, int toRow) { for (int i = fromRow; i <= toRow; i++) { XSSFRow xrow = getRow(i); if (xrow == null) { xrow = createRow(i); } CTRow ctrow = xrow.getCTRow(); short outlineLevel = ctrow.getOutlineLevel(); ctrow.setOutlineLevel((short) (outlineLevel + 1)); } setSheetFormatPrOutlineLevelRow(); }
/** * Also creates cells if they don't exist */ private CellRange<XSSFCell> getCellRange(CellRangeAddress range) { int firstRow = range.getFirstRow(); int firstColumn = range.getFirstColumn(); int lastRow = range.getLastRow(); int lastColumn = range.getLastColumn(); int height = lastRow - firstRow + 1; int width = lastColumn - firstColumn + 1; List<XSSFCell> temp = new ArrayList<>(height * width); for (int rowIn = firstRow; rowIn <= lastRow; rowIn++) { for (int colIn = firstColumn; colIn <= lastColumn; colIn++) { XSSFRow row = getRow(rowIn); if (row == null) { row = createRow(rowIn); } XSSFCell cell = row.getCell(colIn); if (cell == null) { cell = row.createCell(colIn); } temp.add(cell); } } return SSCellRange.create(firstRow, firstColumn, height, width, temp, XSSFCell.class); }
XSSFRow row = table.getXSSFSheet().getRow(rowId); if (row == null) { row = table.getXSSFSheet().createRow(rowId);
/** * @param rowIndex the zero based row index to collapse */ private void collapseRow(int rowIndex) { XSSFRow row = getRow(rowIndex); if (row != null) { int startRow = findStartOfRowOutlineGroup(rowIndex); // Hide all the columns until the end of the group int lastRow = writeHidden(row, startRow, true); if (getRow(lastRow) != null) { getRow(lastRow).getCTRow().setCollapsed(true); } else { XSSFRow newRow = createRow(lastRow); newRow.getCTRow().setCollapsed(true); } } }
final XSSFRow destRow = createRow(destRowNum); destRow.copyRowFrom(srcRow, options);
/** * Gets the XSSFCell referenced by the R attribute or creates a new one if cell doesn't exists * @return the referenced XSSFCell, null if the cell reference is invalid */ public XSSFCell getReferencedCell(){ XSSFCell cell = null; CellReference cellReference = new CellReference(singleXmlCell.getR()); XSSFRow row = parent.getXSSFSheet().getRow(cellReference.getRow()); if(row==null){ row = parent.getXSSFSheet().createRow(cellReference.getRow()); } cell = row.getCell(cellReference.getCol()); if(cell==null){ cell = row.createCell(cellReference.getCol()); } return cell; }
Row row = sheet.createRow(rownum++);
import org.apache.poi.xssf.usermodel.*; //import needed XSSFWorkbook wb = new XSSFWorkbook (); // Create workbook XSSFSheet sheet = wb.createSheet(); // Create spreadsheet in workbook XSSFRow row = sheet.createRow(rowIndex); // Create the row in the spreadsheet //1. Create the date cell style XSSFCreationHelper createHelper = wb.getCreationHelper(); XSSFCellStyle cellStyle = wb.createCellStyle(); cellStyle.setDataFormat( createHelper.createDataFormat().getFormat("MMMM dd, yyyy")); //2. Apply the Date cell style to a cell //This example sets the first cell in the row using the date cell style cell = row.createCell(0); cell.setCellValue(new Date()); cell.setCellStyle(cellStyle);
XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet = wb.createSheet(); XSSFRow row = sheet.createRow(0); XSSFCell cell = row.createCell( 0); cell.setCellValue("custom XSSF colors"); XSSFCellStyle style1 = wb.createCellStyle(); style1.setFillForegroundColor(new XSSFColor(new java.awt.Color(128, 0, 128))); style1.setFillPattern(CellStyle.SOLID_FOREGROUND);
protected void nextRow() { currentRowNumber++; currentRow = currentSheet.createRow(currentRowNumber); currentColumnNumber = -1; }
XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet("Sample.xlsx"); //Create a new row in current sheet Row row = sheet.createRow(0); //Create a new cell in current row Cell cell = row.createCell(0); //Set value to new value cell.setCellValue("Blahblah"); //finally write data to excel file FileOutputStream out = new FileOutputStream(new File("C:\\test.xls")); workbook.write(out); out.close();
fis = new FileInputStream(new File(fileName)); XSSFWorkbook workbook = new XSSFWorkbook (fis); XSSFSheet sheet = workbook.getSheetAt(0); XSSFRow row1 = sheet.createRow(0); XSSFCell r1c1 = row1.createCell(0); r1c1.setCellValue("Demo"); fis.close(); FileOutputStream fos = new FileOutputStream(new File(outputFile)); workbook.write(fos); fos.close();
private static XSSFRow createDataRow(XSSFSheet sheet, Set columnSet, Map dataMap, int rowIndex){ XSSFRow dataRow = sheet.createRow(rowIndex); dataRow.setHeight((short) 300); // Row Height int dataCellIndex = 0; for(Object columnName : columnSet){ // Column XSSFCell cell = dataRow.createCell((short) dataCellIndex); cell.setCellValue(dataMap.get(columnName).toString()); dataCellIndex++; } return dataRow; }
private void newRow() { incrementRow(); row = viewOutputExcel.getOutput().createRow(rowIndex); columnIndex = -1; }
XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet = wb.createSheet("test"); Row row = sheet.createRow(0); Cell inCell = row.createCell(0); inCell.setCellValue("01.0234500"); Cell outCell = row.createCell(1); FormulaEvaluator fev = wb.getCreationHelper().createFormulaEvaluator(); String value = inCell.getStringCellValue(); outCell.setCellFormula("VALUE(" + value + ")"); fev.evaluateInCell(outCell);
XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet(); XSSFFormulaEvaluator evaluator = new XSSFFormulaEvaluator(workbook); XSSFCell cellvalue = sheet.createRow(0).createCell(0); sheet.getRow(0).createCell(1).setCellValue(2); sheet.getRow(0).createCell(2).setCellValue(5); cellvalue.setCellFormula("B1+C1"); if (cellvalue.getCellType() == XSSFCell.CELL_TYPE_FORMULA) { evaluator.evaluateFormulaCell(cellvalue); } System.out.println(cellvalue.getNumericCellValue());
XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet = wb.createSheet(); XSSFRow row = sheet.createRow(0); XSSFCell cell = row.createCell( 0); cell.setCellValue("custom XSSF colors"); XSSFCellStyle style1 = wb.createCellStyle(); style1.setFillForegroundColor(new XSSFColor(new java.awt.Color(128, 0, 128))); style1.setFillPattern(CellStyle.SOLID_FOREGROUND);