List of usage examples for org.apache.poi.xssf.usermodel XSSFSheet createRow
@Override public XSSFRow createRow(int rownum)
From source file:VentanaJava.ConsultarIngresoCortoExportar.java
private void ExportarPlanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ExportarPlanActionPerformed DefaultTableModel model = (DefaultTableModel) TablaPlanesIngresoCortoPlazo.getModel(); int filas = TablaPlanesIngresoCortoPlazo.getRowCount(); JFileChooser GuardarArchivo = new JFileChooser(); int opcion = GuardarArchivo.showSaveDialog(this); if (opcion == JFileChooser.APPROVE_OPTION) { String direccion = GuardarArchivo.getSelectedFile().toString(); XSSFWorkbook libro = new XSSFWorkbook(); XSSFSheet hoja = libro.createSheet(); XSSFRow fila = hoja.createRow(0); fila.createCell(0).setCellValue("Granja"); fila.createCell(1).setCellValue("Galera"); fila.createCell(2).setCellValue("Fecha de Ingreso"); fila.createCell(3).setCellValue("Cantidad a Ingresar"); XSSFRow hileras;/*from ww w . j a v a 2s. com*/ for (int i = 0; i < filas; i++) { hileras = hoja.createRow((i + 1)); for (int e = 0; e < 4; e++) { hileras.createCell(e).setCellValue(model.getValueAt(i, e).toString()); } } try { libro.write(new FileOutputStream(new File(direccion + ".xlsx"))); Desktop.getDesktop().open(new File(direccion + ".xlsx")); this.dispose(); } catch (Exception e) { JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } }
From source file:VentanaJava.ConsultarIngresoMedianoExportar.java
private void ExportarPlanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ExportarPlanActionPerformed DefaultTableModel model = (DefaultTableModel) TablaConsultaIngresoLargo.getModel(); int filas = TablaConsultaIngresoLargo.getRowCount(); JFileChooser GuardarArchivo = new JFileChooser(); int opcion = GuardarArchivo.showSaveDialog(this); if (opcion == JFileChooser.APPROVE_OPTION) { String direccion = GuardarArchivo.getSelectedFile().toString(); XSSFWorkbook libro = new XSSFWorkbook(); XSSFSheet hoja = libro.createSheet(); XSSFRow fila = hoja.createRow(0); fila.createCell(0).setCellValue("Granja"); fila.createCell(1).setCellValue("Galera"); fila.createCell(2).setCellValue("Fecha de Ingreso"); fila.createCell(3).setCellValue("Cantidad a Ingresar"); fila.createCell(4).setCellValue("Rol"); XSSFRow hileras;// w w w. j a va2s . c o m for (int i = 0; i < filas; i++) { hileras = hoja.createRow((i + 1)); for (int e = 0; e < 5; e++) { hileras.createCell(e).setCellValue(model.getValueAt(i, e).toString()); } } try { libro.write(new FileOutputStream(new File(direccion + ".xlsx"))); Desktop.getDesktop().open(new File(direccion + ".xlsx")); this.dispose(); } catch (Exception e) { JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } }
From source file:vistas.MantenedorReportes.java
private void btnExportarGastosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExportarGastosActionPerformed Thread t;//ww w. ja v a2s . c o m t = new Thread() { @Override public void run() { XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet hoja = workbook.createSheet(); XSSFRow fila = hoja.createRow(0); fila.createCell(0).setCellValue("N"); fila.createCell(1).setCellValue("Vendedor"); fila.createCell(2).setCellValue("Fecha (Ao-Mes-Da)"); fila.createCell(3).setCellValue("Descripcin"); fila.createCell(4).setCellValue("Valor"); pbGastosExtras.setMaximum(tbGastosExtras.getRowCount()); XSSFRow filas; Rectangle rect; for (int i = 0; i < tbGastosExtras.getRowCount(); i++) { rect = tbGastosExtras.getCellRect(i, 0, true); tbGastosExtras.scrollRectToVisible(rect); tbGastosExtras.setRowSelectionInterval(i, i); pbGastosExtras.setValue((i + 1)); filas = hoja.createRow((i + 1)); filas.createCell(0).setCellValue(tbGastosExtras.getValueAt(i, 0).toString()); filas.createCell(1).setCellValue(tbGastosExtras.getValueAt(i, 1).toString()); filas.createCell(2).setCellValue(tbGastosExtras.getValueAt(i, 2).toString()); filas.createCell(3).setCellValue(tbGastosExtras.getValueAt(i, 3).toString()); filas.createCell(4).setCellValue(tbGastosExtras.getValueAt(i, 4).toString()); } pbGastosExtras.setValue(0); try { workbook.write(new FileOutputStream(new File("Excel.xlsx"))); Desktop.getDesktop().open(new File("Excel.xlsx")); } catch (Exception e) { } } }; t.start(); }
From source file:vistas.MantenedorReportes.java
private void btnExportarProductosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExportarProductosActionPerformed // TODO add your handling code here: Thread t;/*from w w w . j a va 2s.c o m*/ t = new Thread() { @Override public void run() { XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet hoja = workbook.createSheet(); XSSFRow fila = hoja.createRow(0); fila.createCell(0).setCellValue("N"); fila.createCell(1).setCellValue("Codigo"); fila.createCell(2).setCellValue("Nombre"); fila.createCell(3).setCellValue("Marca"); fila.createCell(4).setCellValue("Precio Compra"); fila.createCell(5).setCellValue("Precio Venta"); fila.createCell(6).setCellValue("Utilidad Unitaria"); fila.createCell(7).setCellValue("Cantidad vendida"); fila.createCell(8).setCellValue("Utilidad Final"); fila.createCell(9).setCellValue("Periodo anterior"); pbProductos.setMaximum(tbGastosExtras.getRowCount()); XSSFRow filas; Rectangle rect; for (int i = 0; i < tbProductos.getRowCount(); i++) { rect = tbProductos.getCellRect(i, 0, true); tbProductos.scrollRectToVisible(rect); tbProductos.setRowSelectionInterval(i, i); pbProductos.setValue((i + 1)); filas = hoja.createRow((i + 1)); filas.createCell(0).setCellValue(tbProductos.getValueAt(i, 0).toString()); filas.createCell(1).setCellValue(tbProductos.getValueAt(i, 1).toString()); filas.createCell(2).setCellValue(tbProductos.getValueAt(i, 2).toString()); filas.createCell(3).setCellValue(tbProductos.getValueAt(i, 3).toString()); filas.createCell(4).setCellValue(tbProductos.getValueAt(i, 4).toString()); filas.createCell(5).setCellValue(tbProductos.getValueAt(i, 5).toString()); filas.createCell(6).setCellValue(tbProductos.getValueAt(i, 6).toString()); filas.createCell(7).setCellValue(tbProductos.getValueAt(i, 7).toString()); filas.createCell(8).setCellValue(tbProductos.getValueAt(i, 8).toString()); filas.createCell(9).setCellValue(tbProductos.getValueAt(i, 9).toString()); } pbProductos.setValue(0); try { workbook.write(new FileOutputStream(new File("Excel.xlsx"))); Desktop.getDesktop().open(new File("Excel.xlsx")); } catch (Exception e) { } } }; t.start(); }
From source file:vistas.MantenedorReportes.java
private void btnExportarVendedoresActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExportarVendedoresActionPerformed // TODO add your handling code here: Thread t;/* w w w . j a v a2 s . c o m*/ t = new Thread() { @Override public void run() { XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet hoja = workbook.createSheet(); XSSFRow fila = hoja.createRow(0); fila.createCell(0).setCellValue("N"); fila.createCell(1).setCellValue("Vendedor"); fila.createCell(2).setCellValue("Ventas totales"); fila.createCell(3).setCellValue("Utilidades"); fila.createCell(4).setCellValue("Das trabajados"); fila.createCell(5).setCellValue("Horas trabajadas"); pbVendedores.setMaximum(tbVendedores.getRowCount()); XSSFRow filas; Rectangle rect; for (int i = 0; i < tbVendedores.getRowCount(); i++) { rect = tbVendedores.getCellRect(i, 0, true); tbVendedores.scrollRectToVisible(rect); tbVendedores.setRowSelectionInterval(i, i); pbVendedores.setValue((i + 1)); filas = hoja.createRow((i + 1)); filas.createCell(0).setCellValue(tbVendedores.getValueAt(i, 0).toString()); filas.createCell(1).setCellValue(tbVendedores.getValueAt(i, 1).toString()); filas.createCell(2).setCellValue(tbVendedores.getValueAt(i, 2).toString()); filas.createCell(3).setCellValue(tbVendedores.getValueAt(i, 3).toString()); filas.createCell(4).setCellValue(tbVendedores.getValueAt(i, 4).toString()); filas.createCell(5).setCellValue(tbVendedores.getValueAt(i, 5).toString()); } pbVendedores.setValue(0); try { workbook.write(new FileOutputStream(new File("Excel.xlsx"))); Desktop.getDesktop().open(new File("Excel.xlsx")); } catch (Exception e) { } } }; t.start(); }
From source file:vistas.MantenedorReportes.java
private void btnExportarInventarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExportarInventarioActionPerformed // TODO add your handling code here: Thread t;// w ww .ja v a 2 s . c om t = new Thread() { @Override public void run() { XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet hoja = workbook.createSheet(); XSSFRow fila = hoja.createRow(0); fila.createCell(0).setCellValue("N"); fila.createCell(1).setCellValue("Codigo"); fila.createCell(2).setCellValue("Nombre"); fila.createCell(3).setCellValue("Marca"); fila.createCell(4).setCellValue("Stock"); pbInventario.setMaximum(tbInventario.getRowCount()); XSSFRow filas; Rectangle rect; for (int i = 0; i < tbInventario.getRowCount(); i++) { rect = tbInventario.getCellRect(i, 0, true); tbInventario.scrollRectToVisible(rect); tbInventario.setRowSelectionInterval(i, i); pbInventario.setValue((i + 1)); filas = hoja.createRow((i + 1)); filas.createCell(0).setCellValue(tbInventario.getValueAt(i, 0).toString()); filas.createCell(1).setCellValue(tbInventario.getValueAt(i, 1).toString()); filas.createCell(2).setCellValue(tbInventario.getValueAt(i, 2).toString()); filas.createCell(3).setCellValue(tbInventario.getValueAt(i, 3).toString()); filas.createCell(4).setCellValue(tbInventario.getValueAt(i, 4).toString()); } pbInventario.setValue(0); try { workbook.write(new FileOutputStream(new File("Excel.xlsx"))); Desktop.getDesktop().open(new File("Excel.xlsx")); } catch (Exception e) { } } }; t.start(); }
From source file:WeeklyOPD.SplitOldDepartmentwise.java
License:Open Source License
private static void createDepartmentwiseSheets() { HashMap<String, Integer> depttMap = new HashMap<>(); depttMap.put("Medicine", 1); depttMap.put("Surgery", 2); depttMap.put("Obs & Gynae", 3); depttMap.put("Paediatrics", 4); depttMap.put("Orthopaedics", 5); depttMap.put("Ophthalmology", 6); depttMap.put("ENT", 7); depttMap.put("Dental", 8); depttMap.put("Casualty", 9); int depttSheetCreateFlag = 0; System.out.println("In createDepartmentwiseSheets"); Iterator<Row> rowIterator = sheetAllOld.rowIterator(); //Store the first row to be printed as it is. ArrayList<String> heading = new ArrayList<>(); Row row = rowIterator.next();// w w w .j av a 2 s. c o m Iterator<Cell> cellIterator = row.cellIterator(); while (cellIterator.hasNext()) heading.add(cellIterator.next().getStringCellValue()); int rowNums[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 }; while (rowIterator.hasNext()) { row = rowIterator.next(); XSSFSheet sheetToWrite = null; System.out.println("Row: " + row.getRowNum()); Cell cell = row.getCell(0); if ((depttSheetCreateFlag & 1 << (depttMap.get(cell.getStringCellValue()))) == 0) { //that means this deptt came in this sheet for the first time in this row. XSSFSheet sheet = sheets[depttMap.get(cell.getStringCellValue()) - 1] = workbookOld .createSheet(cell.getStringCellValue()); //create heading row in this sheet Row headingRow = sheet.createRow(0); for (int i = 0; i < heading.size(); i++) { String cellString = heading.get(i); Cell headingCell = headingRow.createCell(i); headingCell.setCellValue(cellString);//sets cell type to string too } //mark this deptt. as seen depttSheetCreateFlag |= (1 << (depttMap.get(cell.getStringCellValue()))); } int sheetNum = depttMap.get(cell.getStringCellValue()) - 1; sheetToWrite = sheets[sheetNum]; assert (sheetToWrite != null); //write row to sheetToWrite Row rowNew = sheetToWrite.createRow(rowNums[sheetNum]++); cellIterator = row.cellIterator(); int cellNum = 0; while (cellIterator.hasNext()) { cell = cellIterator.next(); //write cell Cell cellNew = rowNew.createCell(cellNum++); String cellValue; if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) cellValue = (int) (cell.getNumericCellValue()) + ""; else cellValue = cell.getStringCellValue(); cellNew.setCellValue(cellValue); } } }