List of usage examples for org.apache.poi.ss.usermodel Row createCell
Cell createCell(int column);
From source file:cherry.goods.excel.ExcelReaderTest.java
License:Apache License
@Test public void testRead_FORMULA_STRING() throws IOException { try (Workbook workbook = new XSSFWorkbook()) { // /*from w ww.ja v a 2 s . c o m*/ Sheet sheet = workbook.createSheet(); Row row0 = sheet.createRow(0); row0.createCell(0).setCellFormula("\"CELL\"&\"00\""); row0.createCell(1).setCellFormula("\"CELL\"&\"01\""); FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator(); evaluator.evaluateAll(); // try (ExcelReader reader = new ExcelReader(workbook)) { String[] r0 = reader.read(); assertNotNull(r0); assertEquals(2, r0.length); assertEquals("CELL00", r0[0]); assertEquals("CELL01", r0[1]); assertNull(reader.read()); } } }
From source file:cherry.goods.excel.ExcelReaderTest.java
License:Apache License
@Test public void testRead_FORMULA_BOOLEAN() throws IOException { try (Workbook workbook = new XSSFWorkbook()) { // // w ww .jav a2 s . com Sheet sheet = workbook.createSheet(); Row row0 = sheet.createRow(0); row0.createCell(0).setCellFormula("1=1"); row0.createCell(1).setCellFormula("1=0"); FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator(); evaluator.evaluateAll(); // try (ExcelReader reader = new ExcelReader(workbook)) { String[] r0 = reader.read(); assertNotNull(r0); assertEquals(2, r0.length); assertEquals("true", r0[0]); assertEquals("false", r0[1]); assertNull(reader.read()); } } }
From source file:cherry.goods.excel.ExcelReaderTest.java
License:Apache License
@Test public void testRead_FORMULA_ERROR() throws IOException { try (Workbook workbook = new XSSFWorkbook()) { // //from w ww . jav a2 s. c o m Sheet sheet = workbook.createSheet(); Row row0 = sheet.createRow(0); row0.createCell(0).setCellErrorValue((byte) 0); row0.createCell(1).setCellFormula("A1"); FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator(); evaluator.evaluateAll(); // try (ExcelReader reader = new ExcelReader(workbook)) { String[] r0 = reader.read(); assertNotNull(r0); assertEquals(2, r0.length); assertNull(r0[0]); assertNull(r0[1]); assertNull(reader.read()); } } }
From source file:cherry.goods.excel.ExcelWriter.java
License:Apache License
/** * ?<br />//from ww w .java 2 s . c om * ???1(1) * * @param offsetCols ????? (???) * @param record 1(1) */ public void write(int offsetCols, String... record) { Row row = currentSheet.getRow(rownum); if (row == null) { row = currentSheet.createRow(rownum); } rownum += 1; for (int i = 0; i < record.length; i++) { int colnum = i + offsetCols; Cell cell = row.getCell(colnum); if (record[i] == null) { if (cell != null) { row.removeCell(cell); } } else { if (cell == null) { cell = row.createCell(colnum); } cell.setCellValue(record[i]); } } }
From source file:cherry.goods.excel.ExcelWriterTest.java
License:Apache License
@Test public void testWrite_2_COLS_2_ROWS_WITH_NULL() throws IOException { try (Workbook workbook = new XSSFWorkbook()) { // /*from w w w . j ava 2s . co m*/ Sheet sheet = workbook.createSheet("CREATED 0"); Row row0 = sheet.createRow(0); row0.createCell(0); row0.createCell(1); // try (ExcelWriter writer = new ExcelWriter(workbook)) { writer.write("CELL 00", null); writer.write(null, "CELL 11"); assertEquals("CELL 00", sheet.getRow(0).getCell(0).getStringCellValue()); assertNull(sheet.getRow(0).getCell(1)); assertNull(sheet.getRow(1).getCell(0)); assertEquals("CELL 11", sheet.getRow(1).getCell(1).getStringCellValue()); } } }
From source file:chronostone.parser.ChronoStoneParser.java
private static void inicializar_celdas(Sheet hoja) { Row fila = hoja.createRow(xls_index); xls_index++;/*from w w w. j a v a2 s .c om*/ Cell celda = fila.createCell(0); celda.setCellValue("Name"); celda = fila.createCell(1); celda.setCellValue("Position"); celda = fila.createCell(2); celda.setCellValue(gp); celda = fila.createCell(3); celda.setCellValue(TP); celda = fila.createCell(4); celda.setCellValue(KICK); celda = fila.createCell(5); celda.setCellValue(DRIBBLING); celda = fila.createCell(6); celda.setCellValue(BLOCK); celda = fila.createCell(7); celda.setCellValue(A_CATCH); celda = fila.createCell(8); celda.setCellValue(TECHNIQUE); celda = fila.createCell(9); celda.setCellValue(SPEED); celda = fila.createCell(10); celda.setCellValue(STAMINA); celda = fila.createCell(11); celda.setCellValue(LUCKY); }
From source file:chronostone.parser.ChronoStoneParser.java
private static void add_character_sheet(Sheet hoja) { Row fila = hoja.createRow(xls_index); xls_index++;/*from w w w . ja v a2 s . co m*/ Cell celda = fila.createCell(0); celda.setCellValue(tenmakun.getName()); celda = fila.createCell(1); celda.setCellValue(tenmakun.getPosition()); celda = fila.createCell(2); celda.setCellValue(tenmakun.getGp()); celda = fila.createCell(3); celda.setCellValue(tenmakun.getTp()); celda = fila.createCell(4); celda.setCellValue(tenmakun.getKick()); celda = fila.createCell(5); celda.setCellValue(tenmakun.getDribbling()); celda = fila.createCell(6); celda.setCellValue(tenmakun.getBlock()); celda = fila.createCell(7); celda.setCellValue(tenmakun.getCatch_keeper()); celda = fila.createCell(8); celda.setCellValue(tenmakun.getTechnique()); celda = fila.createCell(9); celda.setCellValue(tenmakun.getSpeed()); celda = fila.createCell(10); celda.setCellValue(tenmakun.getStamina()); celda = fila.createCell(11); celda.setCellValue(tenmakun.getLucky()); }
From source file:cl.a2r.wsmicampov2.common.utils.Excel.java
public static void GenerateExcel(String fileUrl, String sheetName, List<Integer> dataList) { File archivo = new File(fileUrl); Workbook workbook = new XSSFWorkbook(); Sheet sheet = workbook.createSheet(sheetName); int rowNum = 1; for (Integer data : dataList) { Row row = sheet.createRow(rowNum++); row.createCell(0).setCellValue(data); }// w w w . j a v a 2 s. c o m try { FileOutputStream salida = new FileOutputStream(archivo); workbook.write(salida); workbook.close(); } catch (FileNotFoundException ex) { AppLog.logInfo(ex.getMessage(), ex); } catch (IOException ex) { AppLog.logInfo(ex.getMessage(), ex); } catch (Exception ex) { AppLog.logInfo(ex.getMessage(), ex); } }
From source file:clases.Funciones.java
private String GenerateReporte_xls(JTable t, int open) { String rutaArchivo = ""; try {//from w ww. j a v a2 s . com char rt = p.ReturnPropiedad(p.Ruta_SaveReports) .charAt(p.ReturnPropiedad(p.Ruta_SaveReports).length() - 1); if ("/".equalsIgnoreCase(String.valueOf(rt))) { rutaArchivo = p.ReturnPropiedad(p.Ruta_SaveReports) + ReturnNombreUsuario().replace(" ", "_") + rutaArchivo + "_" + GetFechaAndHourActual().replace(":", "_").replace(" ", "_").replace("-", "_") + ".xls"; } else { rutaArchivo = p.ReturnPropiedad(p.Ruta_SaveReports) + "/" + ReturnNombreUsuario().replace(" ", "_") + rutaArchivo + "_" + GetFechaAndHourActual().replace(":", "_").replace(" ", "_").replace("-", "_") + ".xls"; } File archivoXLS = new File(rutaArchivo); if (archivoXLS.exists()) archivoXLS.delete(); archivoXLS.createNewFile(); Workbook libro = new HSSFWorkbook(); FileOutputStream archivo = new FileOutputStream(archivoXLS); Sheet hoja = libro.createSheet(ReturnDatosFisicos(this.Datos_Nombre)); for (int f = 0; f < t.getRowCount() + 1; f++) { Row fila = hoja.createRow(f); for (int c = 0; c < t.getColumnCount(); c++) { Cell celda = fila.createCell(c); if (f == 0) { celda.setCellValue(String.valueOf(t.getColumnName(c))); } else { celda.setCellValue(String.valueOf(t.getValueAt(f - 1, c))); } hoja.autoSizeColumn(c); } } libro.write(archivo); archivo.close(); if (open > 0) { Desktop.getDesktop().open(archivoXLS); } } catch (IOException ex) { Alert(ex.getMessage()); } return rutaArchivo; }
From source file:Clientes.editaCliente.java
private void bt_actualiza2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_actualiza2ActionPerformed // TODO add your handling code here: javax.swing.JFileChooser jF1 = new javax.swing.JFileChooser(); jF1.setFileFilter(new ExtensionFileFilter("Excel document (*.xls)", new String[] { "xls" })); String ruta = null;/*from w w w .ja v a 2 s .co m*/ if (jF1.showSaveDialog(null) == jF1.APPROVE_OPTION) { ruta = jF1.getSelectedFile().getAbsolutePath(); if (ruta != null) { File archivoXLS = new File(ruta + ".xls"); try { if (archivoXLS.exists()) archivoXLS.delete(); archivoXLS.createNewFile(); Workbook libro = new HSSFWorkbook(); FileOutputStream archivo = new FileOutputStream(archivoXLS); Sheet hoja = libro.createSheet("Clientes"); for (int ren = 0; ren < (t_datos.getRowCount() + 1); ren++) { Row fila = hoja.createRow(ren); for (int col = 0; col < t_datos.getColumnCount(); col++) { Cell celda = fila.createCell(col); if (ren == 0) { celda.setCellValue(columnas[col]); } else { try { celda.setCellValue(t_datos.getValueAt(ren - 1, col).toString()); } catch (Exception e) { celda.setCellValue(""); } } } } libro.write(archivo); archivo.close(); Desktop.getDesktop().open(archivoXLS); } catch (Exception e) { System.out.println(e); JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte"); } } } }