use of org.apache.poi.ss.usermodel.Row in project poi by apache.
the class TestSXSSFWorkbook method testTemplateFile.
@Ignore("Just a local test for http://stackoverflow.com/questions/33627329/apache-poi-streaming-api-using-xssf-template")
@Test
public void testTemplateFile() throws IOException {
XSSFWorkbook workBook = XSSFTestDataSamples.openSampleWorkbook("sample.xlsx");
SXSSFWorkbook streamingWorkBook = new SXSSFWorkbook(workBook, 10);
Sheet sheet = streamingWorkBook.getSheet("Sheet1");
for (int rowNum = 10; rowNum < 1000000; rowNum++) {
Row row = sheet.createRow(rowNum);
for (int cellNum = 0; cellNum < 700; cellNum++) {
Cell cell = row.createCell(cellNum);
cell.setCellValue("somevalue");
}
if (rowNum % 100 == 0) {
System.out.print(".");
if (rowNum % 10000 == 0) {
System.out.println(rowNum);
}
}
}
FileOutputStream fos = new FileOutputStream("C:\\temp\\streaming.xlsx");
streamingWorkBook.write(fos);
fos.close();
streamingWorkBook.close();
workBook.close();
}
use of org.apache.poi.ss.usermodel.Row in project poi by apache.
the class TestSXSSFWorkbook method assertWorkbookDispose.
protected static void assertWorkbookDispose(SXSSFWorkbook wb) {
int rowNum = 1000;
int sheetNum = 5;
for (int i = 0; i < sheetNum; i++) {
Sheet sh = wb.createSheet("sheet" + i);
for (int j = 0; j < rowNum; j++) {
Row row = sh.createRow(j);
Cell cell1 = row.createCell(0);
cell1.setCellValue(new CellReference(cell1).formatAsString());
Cell cell2 = row.createCell(1);
cell2.setCellValue(i);
Cell cell3 = row.createCell(2);
cell3.setCellValue(j);
}
}
for (Sheet sheet : wb) {
SXSSFSheet sxSheet = (SXSSFSheet) sheet;
assertTrue(sxSheet.getSheetDataWriter().getTempFile().exists());
}
assertTrue(wb.dispose());
for (Sheet sheet : wb) {
SXSSFSheet sxSheet = (SXSSFSheet) sheet;
assertFalse(sxSheet.getSheetDataWriter().getTempFile().exists());
}
}
use of org.apache.poi.ss.usermodel.Row in project poi by apache.
the class TestUnfixedBugs method test54071.
@Test
public void test54071() throws Exception {
Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("54071.xlsx");
Sheet sheet = workbook.getSheetAt(0);
int rows = sheet.getPhysicalNumberOfRows();
System.out.println(">> file rows is:" + (rows - 1) + " <<");
Row title = sheet.getRow(0);
Date prev = null;
for (int row = 1; row < rows; row++) {
Row rowObj = sheet.getRow(row);
for (int col = 0; col < 1; col++) {
String titleName = title.getCell(col).toString();
Cell cell = rowObj.getCell(col);
if (titleName.startsWith("time")) {
// here the output will produce ...59 or ...58 for the rows, probably POI is
// doing some different rounding or some other small difference...
System.out.println("==Time:" + cell.getDateCellValue());
if (prev != null) {
assertEquals(prev, cell.getDateCellValue());
}
prev = cell.getDateCellValue();
}
}
}
workbook.close();
}
use of org.apache.poi.ss.usermodel.Row in project poi by apache.
the class TestUnfixedBugs method testBug55752.
@Test
public void testBug55752() throws IOException {
Workbook wb = new XSSFWorkbook();
try {
Sheet sheet = wb.createSheet("test");
for (int i = 0; i < 4; i++) {
Row row = sheet.createRow(i);
for (int j = 0; j < 2; j++) {
Cell cell = row.createCell(j);
cell.setCellStyle(wb.createCellStyle());
}
}
// set content
Row row1 = sheet.getRow(0);
row1.getCell(0).setCellValue("AAA");
Row row2 = sheet.getRow(1);
row2.getCell(0).setCellValue("BBB");
Row row3 = sheet.getRow(2);
row3.getCell(0).setCellValue("CCC");
Row row4 = sheet.getRow(3);
row4.getCell(0).setCellValue("DDD");
// merge cells
CellRangeAddress range1 = new CellRangeAddress(0, 0, 0, 1);
sheet.addMergedRegion(range1);
CellRangeAddress range2 = new CellRangeAddress(1, 1, 0, 1);
sheet.addMergedRegion(range2);
CellRangeAddress range3 = new CellRangeAddress(2, 2, 0, 1);
sheet.addMergedRegion(range3);
assertEquals(0, range3.getFirstColumn());
assertEquals(1, range3.getLastColumn());
assertEquals(2, range3.getLastRow());
CellRangeAddress range4 = new CellRangeAddress(3, 3, 0, 1);
sheet.addMergedRegion(range4);
// set border
RegionUtil.setBorderBottom(CellStyle.BORDER_THIN, range1, sheet, wb);
row2.getCell(0).getCellStyle().setBorderBottom(CellStyle.BORDER_THIN);
row2.getCell(1).getCellStyle().setBorderBottom(CellStyle.BORDER_THIN);
Cell cell0 = CellUtil.getCell(row3, 0);
CellUtil.setCellStyleProperty(cell0, CellUtil.BORDER_BOTTOM, CellStyle.BORDER_THIN);
Cell cell1 = CellUtil.getCell(row3, 1);
CellUtil.setCellStyleProperty(cell1, CellUtil.BORDER_BOTTOM, CellStyle.BORDER_THIN);
RegionUtil.setBorderBottom(CellStyle.BORDER_THIN, range4, sheet, wb);
// write to file
OutputStream stream = new FileOutputStream(new File("C:/temp/55752.xlsx"));
try {
wb.write(stream);
} finally {
stream.close();
}
} finally {
wb.close();
}
}
use of org.apache.poi.ss.usermodel.Row in project poi by apache.
the class TestSXSSFSheetAutoSizeColumn method createRowWithCellValues.
private static Cell createRowWithCellValues(final Sheet sheet, final int rowNumber, final String... cellValues) {
Row row = sheet.createRow(rowNumber);
int cellIndex = 0;
Cell firstCell = null;
for (final String cellValue : cellValues) {
Cell cell = row.createCell(cellIndex++);
if (firstCell == null) {
firstCell = cell;
}
cell.setCellValue(cellValue);
}
return firstCell;
}
Aggregations