List of usage examples for org.apache.poi.xssf.streaming SXSSFWorkbook SXSSFWorkbook
public SXSSFWorkbook()
From source file:br.com.tecsinapse.dataio.Table.java
License:LGPL
public Workbook toSXSSFWorkBook() { return toWorkBook(new SXSSFWorkbook()); }
From source file:br.com.tecsinapse.dataio.test.TableTest.java
License:LGPL
@Test public void testAutoSizeColumn_ComprovaErroMetodoAutoSizeColumn_de_Sheet_QuandoUltimasLinhasSaoVazias() { final int tamanhoIncorretoColuna = 236; final int tamanhoCorretoColuna = 2048; Table t = new Table(); //aps escrever certo nmero de linhas com o contedo vazio, //a coluna no ajustada para o tamanho equivalente a linha //com maior nmero de caracteres for (int i = 1; i < 130; i++) { t.addNewRow();//from w ww. ja va 2 s .c o m if (i < 20) { t.add("Teste erro " + i); } else { t.add(" "); } } Workbook wb = t.toWorkBook(new SXSSFWorkbook()); Sheet sheet = wb.getSheetAt(0); // alterado o modo de validao devido a difernea de plataformas(Windows, Linux, Mac) esses valores podem mudar, porm devem respeitar o mnimo. Por isso usado assertTrue e no assertEquals Assert.assertTrue(sheet.getColumnWidth(0) >= tamanhoIncorretoColuna); Assert.assertTrue(sheet.getColumnWidth(1) >= tamanhoCorretoColuna); }
From source file:br.com.tecsinapse.dataio.test.TableTest.java
License:LGPL
@Test public void testAutoSizeColumn_GeraTamanhoConformeMaiorQuantidadeCaracteresColuna() { final int tamanhoUmCaracter = 256; final int tamanhoDefaultColuna = 2048; final int maiorNumeroCaracteresColuna = 13; Table t = new Table() { @Override/* w w w . j a v a2 s . c o m*/ public boolean isAutoSizeColumnSheet() { return false; } }; for (int i = 1; i < 130; i++) { t.addNewRow(); if (i < 20) { t.add("Teste erro " + i); } else { t.add(" "); } } Workbook wb = t.toWorkBook(new SXSSFWorkbook()); Sheet sheet = wb.getSheetAt(0); Assert.assertEquals(sheet.getColumnWidth(0), maiorNumeroCaracteresColuna * tamanhoUmCaracter); Assert.assertEquals(sheet.getColumnWidth(1), tamanhoDefaultColuna); }
From source file:br.com.tecsinapse.files.test.ExporterFileTest.java
License:LGPL
@DataProvider(name = "beans") public Object[][] beans() { final List<FileBean> beans = FileBean.getBeans(); //melhorar e unificar api de exportao final Function<Table, File> csvExport = new Function<Table, File>() { @Override//from w ww .jav a 2 s . c om public File apply(Table table) { try { final File csv = File.createTempFile("csv", ".csv"); csv.deleteOnExit(); ExporterUtil.writeCsvToOutput(table, Charsets.ISO_8859_1.displayName(), new FileOutputStream(csv)); return csv; } catch (IOException e) { throw Throwables.propagate(e); } } }; final Function<File, List<List<String>>> csvLines = new Function<File, List<List<String>>>() { @Override public List<List<String>> apply(File input) { try { final List<String> strings = CsvUtil.processCSV(new FileInputStream(input), Charsets.ISO_8859_1); return FluentIterable.from(strings).transform(new Function<String, List<String>>() { @Override public List<String> apply(String input) { return Arrays.asList(input.split(";")); } }).toList(); } catch (IOException e) { throw Throwables.propagate(e); } } }; final Function<File, List<List<String>>> excelLines = new Function<File, List<List<String>>>() { @Override public List<List<String>> apply(File file) { try (final SpreadsheetParser<?> parser = new SpreadsheetParser<>(null, file)) { parser.setExporterFormatter(exporterFormatter); parser.setHeadersRows(0); return parser.getLines(); } catch (Exception e) { throw Throwables.propagate(e); } } }; final Function<Table, File> xlsExport = toWorkbookFunction(new Supplier<Workbook>() { @Override public Workbook get() { return new HSSFWorkbook(); } }); final Function<Table, File> xlsxExport = toWorkbookFunction(new Supplier<Workbook>() { @Override public Workbook get() { return new XSSFWorkbook(); } }); final Function<Table, File> sxlsxExport = toWorkbookFunction(new Supplier<Workbook>() { @Override public Workbook get() { return new SXSSFWorkbook(); } }); return new Object[][] { { beans, csvExport, csvLines, "#.#", "" }, { beans, xlsExport, excelLines, "#.#", "" }, { beans, xlsxExport, excelLines, ".#", "" }, { beans, sxlsxExport, excelLines, ".#", "" } }; }
From source file:ch.bfh.lca._15h.library.export.ExportToExcel.java
/*** * Generate an Excel file based on a list of results. * Use the name of the fields described in the GenericResultRow to label the columns. * @param language Language of the label in the Excel file * @param sheetTitle Title of the sheet in the Excel file * @param tableTitle Title of the table in the Excel file * @param rows Arrays of rows to include in the listing * @param excelFilePath Path of the outputed file * @throws FileNotFoundException/* w w w. j a v a 2 s .c o m*/ * @throws IOException */ public static void exportToExcel(Translation.TRANSLATION_LANGUAGE language, String sheetTitle, String tableTitle, GenericResultRow[] rows, String excelFilePath) throws FileNotFoundException, IOException { //Workbook wb = new HSSFWorkbook(); //xls Workbook wb = new SXSSFWorkbook(); //xlsx //create new sheet Sheet sheet1 = wb.createSheet(sheetTitle); Row row; Cell cell; String translation; int rowIndex = 0; //add title row = sheet1.createRow((short) rowIndex); cell = row.createCell(0); cell.setCellValue(tableTitle); CellStyle style = wb.createCellStyle(); Font font = wb.createFont(); font.setFontHeightInPoints((short) 24); //font.setFontName("Courier New"); style.setFont(font); cell.setCellStyle(style); //add rows for (int i = 0; i < rows.length; i++) { //if first line, write col names if (i == 0) { row = sheet1.createRow((short) rowIndex + 2); for (int j = 0; j < rows[i].getColNames().length; j++) { cell = row.createCell(j); //look for translation translation = Translation.getForKey(language, rows[i].getColNames()[j]); if (translation == null) { translation = rows[i].getColNames()[j]; //if doesn't found a translation for the column take name of col } cell.setCellValue(translation); } } row = sheet1.createRow((short) (rowIndex + i + 3)); for (int j = 0; j < rows[i].getColNames().length; j++) { cell = row.createCell(j); cell.setCellValue(rows[i].getValueAt(j).toString()); } } //write to the file FileOutputStream fileOut = new FileOutputStream(excelFilePath); wb.write(fileOut); fileOut.close(); wb.close(); }
From source file:cn.afterturn.easypoi.excel.ExcelExportUtil.java
License:Apache License
private static Workbook getWorkbook(ExcelType type, int size) { if (ExcelType.HSSF.equals(type)) { return new HSSFWorkbook(); } else if (size < USE_SXSSF_LIMIT) { return new XSSFWorkbook(); } else {// w ww . jav a2 s . c o m return new SXSSFWorkbook(); } }
From source file:cn.com.zhbook.component.poi.PoiPerformanceTest.java
License:Apache License
static Workbook createWorkbook(String type) { if ("HSSF".equals(type)) return new HSSFWorkbook(); else if ("XSSF".equals(type)) return new XSSFWorkbook(); else if ("SXSSF".equals(type)) return new SXSSFWorkbook(); else/*from w ww . j a va2 s. c o m*/ usage("Unknown type \"" + type + "\""); return null; }
From source file:com.dua3.meja.model.poi.PoiWorkbookFactory.java
License:Apache License
/** * Create a workbook using the SXSSF backend (write only). * @param locale the {@link Locale} to use * @return the new workbook/*from w w w . ja v a2s. co m*/ */ public Workbook createXlsxStreaming(Locale locale) { return new PoiXssfWorkbook(new SXSSFWorkbook(), locale, null); }
From source file:com.fjn.helper.common.io.file.office.excel.ExcelMgr.java
License:Apache License
/** * ?WorkBook//from w w w . j a v a 2 s . c o m * * @param type * @return */ public static Workbook createWorkBook(Excel.ExcelType type) { Workbook wb = null; switch (type) { case XLSX: wb = new XSSFWorkbook(); break; case XLS: wb = new HSSFWorkbook(); break; default: wb = new SXSSFWorkbook(); break; } return wb; }
From source file:com.fjn.helper.common.io.file.office.excel.ExcelUtil.java
License:Apache License
/** * @param excelFormat//w ww . ja v a2 s . co m * ???<br> * XLS 97-2003?Excel<br> * XLSX 2007?2010?Excel<br> * SXLSX Excel * @return */ public static Workbook newWorkbook(String excelFormat) { Workbook wb = null; if (XLSX.equals(excelFormat)) { wb = new XSSFWorkbook(); } else if (XLS.equals(excelFormat)) { wb = new HSSFWorkbook(); } else { wb = new SXSSFWorkbook(); } return wb; }