use of org.apache.poi.ss.usermodel.Row in project poi by apache.
the class CreateUserDefinedDataFormats method main.
public static void main(String[] args) throws IOException {
//or new HSSFWorkbook();
Workbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet("format sheet");
CellStyle style;
DataFormat format = wb.createDataFormat();
Row row;
Cell cell;
short rowNum = 0;
short colNum = 0;
row = sheet.createRow(rowNum);
cell = row.createCell(colNum);
cell.setCellValue(11111.25);
style = wb.createCellStyle();
style.setDataFormat(format.getFormat("0.0"));
cell.setCellStyle(style);
row = sheet.createRow(++rowNum);
cell = row.createCell(colNum);
cell.setCellValue(11111.25);
style = wb.createCellStyle();
style.setDataFormat(format.getFormat("#,##0.0000"));
cell.setCellStyle(style);
FileOutputStream fileOut = new FileOutputStream("ooxml_dataFormat.xlsx");
wb.write(fileOut);
fileOut.close();
wb.close();
}
use of org.apache.poi.ss.usermodel.Row in project poi by apache.
the class WorkingWithBorders method main.
public static void main(String[] args) throws IOException {
//or new HSSFWorkbook();
Workbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet("borders");
// Create a row and put some cells in it. Rows are 0 based.
Row row = sheet.createRow((short) 1);
// Create a cell and put a value in it.
Cell cell = row.createCell((short) 1);
cell.setCellValue(4);
// Style the cell with borders all around.
CellStyle style = wb.createCellStyle();
style.setBorderBottom(BorderStyle.THIN);
style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
style.setBorderLeft(BorderStyle.THIN);
style.setLeftBorderColor(IndexedColors.GREEN.getIndex());
style.setBorderRight(BorderStyle.THIN);
style.setRightBorderColor(IndexedColors.BLUE.getIndex());
style.setBorderTop(BorderStyle.MEDIUM_DASHED);
style.setTopBorderColor(IndexedColors.BLACK.getIndex());
cell.setCellStyle(style);
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("xssf-borders.xlsx");
wb.write(fileOut);
fileOut.close();
wb.close();
}
use of org.apache.poi.ss.usermodel.Row in project poi by apache.
the class IterateCells method main.
public static void main(String[] args) throws IOException {
Workbook wb = new XSSFWorkbook(new FileInputStream(args[0]));
for (int i = 0; i < wb.getNumberOfSheets(); i++) {
Sheet sheet = wb.getSheetAt(i);
System.out.println(wb.getSheetName(i));
for (Row row : sheet) {
System.out.println("rownum: " + row.getRowNum());
for (Cell cell : row) {
System.out.println(cell);
}
}
}
wb.close();
}
use of org.apache.poi.ss.usermodel.Row in project poi by apache.
the class XSSFEvaluationSheet method getCell.
@Override
public EvaluationCell getCell(int rowIndex, int columnIndex) {
// cache for performance: ~30% speedup due to caching
if (_cellCache == null) {
_cellCache = new HashMap<CellKey, EvaluationCell>(_xs.getLastRowNum() * 3);
for (final Row row : _xs) {
final int rowNum = row.getRowNum();
for (final Cell cell : row) {
// cast is safe, the iterator is just defined using the interface
final CellKey key = new CellKey(rowNum, cell.getColumnIndex());
final EvaluationCell evalcell = new XSSFEvaluationCell((XSSFCell) cell, this);
_cellCache.put(key, evalcell);
}
}
}
final CellKey key = new CellKey(rowIndex, columnIndex);
EvaluationCell evalcell = _cellCache.get(key);
// See bug 59958: Add cells on the fly to the evaluation sheet cache on cache miss
if (evalcell == null) {
XSSFRow row = _xs.getRow(rowIndex);
if (row == null) {
return null;
}
XSSFCell cell = row.getCell(columnIndex);
if (cell == null) {
return null;
}
evalcell = new XSSFEvaluationCell(cell, this);
_cellCache.put(key, evalcell);
}
return evalcell;
}
use of org.apache.poi.ss.usermodel.Row in project poi by apache.
the class CountifsTests method testCallFunction.
/**
* Basic call
*/
@Test
public void testCallFunction() {
Sheet sheet = workbook.createSheet("test");
Row row1 = sheet.createRow(0);
Cell cellA1 = row1.createCell(0, CellType.FORMULA);
Cell cellB1 = row1.createCell(1, CellType.NUMERIC);
Cell cellC1 = row1.createCell(2, CellType.NUMERIC);
Cell cellD1 = row1.createCell(3, CellType.NUMERIC);
Cell cellE1 = row1.createCell(4, CellType.NUMERIC);
cellB1.setCellValue(1);
cellC1.setCellValue(1);
cellD1.setCellValue(2);
cellE1.setCellValue(4);
cellA1.setCellFormula("COUNTIFS(B1:C1,1, D1:E1,2)");
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
CellValue evaluate = evaluator.evaluate(cellA1);
assertEquals(1.0d, evaluate.getNumberValue(), 0.000000000000001);
}
Aggregations