Example usage for org.apache.poi.ss.usermodel Row createCell

List of usage examples for org.apache.poi.ss.usermodel Row createCell

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel Row createCell.

Prototype

Cell createCell(int column);

Source Link

Document

Use this to create new cells within the row and return it.

Usage

From source file:Account.java

public void writetoexcel() throws FileNotFoundException, IOException {
    refresh();//from  w w  w. j  a  v a 2 s.c om
    selection();
    DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
    DefaultTableModel dt = (DefaultTableModel) jTable2.getModel();
    DefaultTableModel d = (DefaultTableModel) jTable3.getModel();
    Workbook wb = new HSSFWorkbook();
    //XSSFWorkbook wb = new XSSFWorkbook();
    CreationHelper createhelper = wb.getCreationHelper();
    Sheet sheet = wb.createSheet("new sheet");
    Row row = null;
    Cell cell = null;
    row = sheet.createRow(0);
    cell = row.createCell(0);
    cell.setCellValue(jTextField1.getText());
    cell = row.createCell(6);
    cell.setCellValue("Replacement");

    row = sheet.createRow(1);
    cell = row.createCell(0);
    cell.setCellValue("Date");
    cell = row.createCell(6);
    cell.setCellValue("Date");

    cell = row.createCell(1);
    cell.setCellValue("Goods");
    cell = row.createCell(2);
    cell.setCellValue("Quantity");
    cell = row.createCell(3);
    cell.setCellValue("Rate");
    cell = row.createCell(4);
    cell.setCellValue("Total");

    cell = row.createCell(7);
    cell.setCellValue("Goods");
    cell = row.createCell(8);
    cell.setCellValue("Quantity");
    cell = row.createCell(9);
    cell.setCellValue("Rate");
    cell = row.createCell(10);
    cell.setCellValue("Total");

    int t = dtm.getRowCount();
    int m = dt.getRowCount();
    int y = d.getRowCount();
    int i, z;
    if (dtm.getValueAt(t - 1, 1) != null)
        t++;
    if (dt.getValueAt(m - 1, 1) != null)
        m++;
    if (d.getValueAt(y - 1, 0) != null)
        y++;
    if (t < m) {
        z = m;
        for (i = 0; i < t - 1; i++) {
            row = sheet.createRow(i + 2);
            for (int j = 0; j < dtm.getColumnCount(); j++) {

                cell = row.createCell(j);
                if (j == 4)
                    cell.setCellValue((Long) dtm.getValueAt(i, j));
                else if (j == 0 || j == 1)
                    cell.setCellValue((String) dtm.getValueAt(i, j));
                else
                    cell.setCellValue((Integer) dtm.getValueAt(i, j));

                cell = row.createCell(j + 6);
                if (j == 4)
                    cell.setCellValue((Long) dt.getValueAt(i, j));
                else if (j == 0 || j == 1)
                    cell.setCellValue((String) dt.getValueAt(i, j));
                else
                    cell.setCellValue(Integer.parseInt(dt.getValueAt(i, j).toString()));
            }
        }
        //i--;
        row = sheet.createRow(t + 2);
        cell = row.createCell(2);
        cell.setCellValue(jTextField3.getText());
        cell = row.createCell(4);
        cell.setCellValue(Long.parseLong(jTextField4.getText()));

        row = sheet.createRow(t + 3);
        cell = row.createCell(2);
        cell.setCellValue(jTextField5.getText());
        cell = row.createCell(4);
        cell.setCellValue(Long.parseLong(jTextField6.getText()));

        row = sheet.createRow(t + 4);
        cell = row.createCell(2);
        cell.setCellValue(jTextField7.getText());
        cell = row.createCell(4);
        cell.setCellValue(Long.parseLong(jTextField8.getText()));

        row = sheet.createRow(t + 5);
        cell = row.createCell(2);
        cell.setCellValue("Total Replacement");
        cell = row.createCell(4);
        cell.setCellValue(Long.parseLong(jTextField10.getText()));

        row = sheet.createRow(t + 6);
        cell = row.createCell(2);
        cell.setCellValue("Total");
        cell = row.createCell(4);
        cell.setCellValue(Long.parseLong(jTextField13.getText()));

        row = sheet.createRow(t + 7);
        cell = row.createCell(2);
        cell.setCellValue("Payment Total");
        cell = row.createCell(4);
        cell.setCellValue(Long.parseLong(jTextField16.getText()));

        row = sheet.createRow(t + 8);
        cell = row.createCell(2);
        cell.setCellValue("New Grand Total");
        cell = row.createCell(4);
        cell.setCellValue(Long.parseLong(jTextField20.getText()));

        int k = i;
        while (i <= m - 1) {
            row = sheet.createRow(i + 2);
            if (i == k + 1) {
                cell = row.createCell(2);
                cell.setCellValue(jTextField3.getText());
                cell = row.createCell(4);
                cell.setCellValue(Long.parseLong(jTextField4.getText()));
            }

            if (i == k + 2) {
                cell = row.createCell(2);
                cell.setCellValue(jTextField5.getText());
                cell = row.createCell(4);
                cell.setCellValue(Long.parseLong(jTextField6.getText()));

            }

            if (i == k + 3) {
                cell = row.createCell(2);
                cell.setCellValue(jTextField7.getText());
                cell = row.createCell(4);
                cell.setCellValue(Long.parseLong(jTextField8.getText()));
            }

            if (i == k + 4) {
                cell = row.createCell(2);
                cell.setCellValue("Total Replacement");
                cell = row.createCell(4);
                cell.setCellValue(Long.parseLong(jTextField10.getText()));
            }

            if (i == k + 5) {
                cell = row.createCell(2);
                cell.setCellValue("Total");
                cell = row.createCell(4);
                cell.setCellValue(Long.parseLong(jTextField13.getText()));
            }

            if (i == k + 6) {
                cell = row.createCell(2);
                cell.setCellValue("Payment Total");
                cell = row.createCell(4);
                cell.setCellValue(Long.parseLong(jTextField16.getText()));
            }
            if (i == k + 7) {
                cell = row.createCell(2);
                cell.setCellValue("New Grand Total");
                cell = row.createCell(4);
                cell.setCellValue(Long.parseLong(jTextField20.getText()));
            }
            if (i == m - 1) {
                cell = row.createCell(8);
                cell.setCellValue("Total Replacement");
                cell = row.createCell(10);
                cell.setCellValue(Long.parseLong(jTextField10.getText()));
            } else {
                for (int j = 0; j < dtm.getColumnCount(); j++) {

                    cell = row.createCell(j + 6);
                    if (j == 4)
                        cell.setCellValue((Long) dt.getValueAt(i, j));
                    else if (j == 0 || j == 1)
                        cell.setCellValue((String) dt.getValueAt(i, j));
                    else
                        cell.setCellValue(Integer.parseInt(dt.getValueAt(i, j).toString()));
                }
            }
            i++;
        }
        row = sheet.createRow(m + 9);
        cell = row.createCell(0);
        cell.setCellValue("Payment");
        row = sheet.createRow(m + 10);
        cell = row.createCell(0);
        cell.setCellValue("Date");
        cell = row.createCell(1);
        cell.setCellValue("Payments");
        for (int u = 0; u < y - 1; u++) {
            row = sheet.createRow(u + m + 11);
            for (int j = 0; j < d.getColumnCount(); j++) {

                cell = row.createCell(j);
                if (j == 0)
                    cell.setCellValue((String) d.getValueAt(u, j));
                else
                    cell.setCellValue(Integer.parseInt(d.getValueAt(u, j).toString()));
            }
        }
        row = sheet.createRow(m + 11 + y);
        cell = row.createCell(0);
        cell.setCellValue("Payment Total");
        cell = row.createCell(1);
        cell.setCellValue(Long.parseLong(jTextField16.getText()));
    } else {
        for (i = 0; i < m - 1; i++) {
            row = sheet.createRow(i + 2);
            for (int j = 0; j < dtm.getColumnCount(); j++) {

                cell = row.createCell(j);
                if (j == 4)
                    cell.setCellValue((Long) dtm.getValueAt(i, j));
                else if (j == 0 || j == 1)
                    cell.setCellValue((String) dtm.getValueAt(i, j));
                else
                    cell.setCellValue((Integer) dtm.getValueAt(i, j));

                cell = row.createCell(j + 6);
                if (j == 4)
                    cell.setCellValue((Long) dt.getValueAt(i, j));
                else if (j == 0 || j == 1)
                    cell.setCellValue((String) dt.getValueAt(i, j));
                else
                    cell.setCellValue(Integer.parseInt(dt.getValueAt(i, j).toString()));
            }
        }
        //i--;
        int k = i;
        while (i <= t - 1) {
            row = sheet.createRow(i + 2);
            if (i == k) {
                cell = row.createCell(8);
                cell.setCellValue("Total Replacement");
                cell = row.createCell(10);
                cell.setCellValue(Long.parseLong(jTextField10.getText()));
            }
            if (i != t - 1) {
                for (int j = 0; j < dtm.getColumnCount(); j++) {

                    cell = row.createCell(j);
                    if (j == 4)
                        cell.setCellValue((Long) dtm.getValueAt(i, j));
                    else if (j == 0 || j == 1)
                        cell.setCellValue((String) dtm.getValueAt(i, j));
                    else
                        cell.setCellValue((Integer) dtm.getValueAt(i, j));
                }
            }
            i++;
        }
        row = sheet.createRow(t + 2);
        cell = row.createCell(2);
        cell.setCellValue(jTextField3.getText());
        cell = row.createCell(4);
        cell.setCellValue(Long.parseLong(jTextField4.getText()));

        row = sheet.createRow(t + 3);
        cell = row.createCell(2);
        cell.setCellValue(jTextField5.getText());
        cell = row.createCell(4);
        cell.setCellValue(Long.parseLong(jTextField6.getText()));

        row = sheet.createRow(t + 4);
        cell = row.createCell(2);
        cell.setCellValue(jTextField7.getText());
        cell = row.createCell(4);
        cell.setCellValue(Long.parseLong(jTextField8.getText()));

        row = sheet.createRow(t + 5);
        cell = row.createCell(2);
        cell.setCellValue("Total Replacement");
        cell = row.createCell(4);
        cell.setCellValue(Long.parseLong(jTextField10.getText()));

        row = sheet.createRow(t + 6);
        cell = row.createCell(2);
        cell.setCellValue("Total");
        cell = row.createCell(4);
        cell.setCellValue(Long.parseLong(jTextField13.getText()));

        row = sheet.createRow(t + 7);
        cell = row.createCell(2);
        cell.setCellValue("Payment Total");
        cell = row.createCell(4);
        cell.setCellValue(Long.parseLong(jTextField16.getText()));

        row = sheet.createRow(t + 8);
        cell = row.createCell(2);
        cell.setCellValue("New Grand Total");
        cell = row.createCell(4);
        cell.setCellValue(Long.parseLong(jTextField20.getText()));

        row = sheet.createRow(t + 10);
        cell = row.createCell(0);
        cell.setCellValue("Payment");
        row = sheet.createRow(t + 11);
        cell = row.createCell(0);
        cell.setCellValue("Date");
        cell = row.createCell(1);
        cell.setCellValue("Payments");
        for (int u = 0; u < y - 1; u++) {
            row = sheet.createRow(u + t + 12);
            for (int j = 0; j < d.getColumnCount(); j++) {

                cell = row.createCell(j);
                if (j == 0)
                    cell.setCellValue((String) d.getValueAt(u, j));
                else
                    cell.setCellValue(Integer.parseInt(d.getValueAt(u, j).toString()));
            }
        }
        row = sheet.createRow(t + y + 12);
        cell = row.createCell(0);
        cell.setCellValue("Payment Total");
        cell = row.createCell(1);
        cell.setCellValue(Long.parseLong(jTextField16.getText()));
    }

    FileOutputStream out = new FileOutputStream(
            chooser.getSelectedFile() + "\\" + jTextField1.getText() + ".xls");
    wb.write(out);
    out.close();
}

From source file:Account.java

public void writereplacement() throws FileNotFoundException, IOException {
    DefaultTableModel dtm = (DefaultTableModel) jTable2.getModel();
    Workbook wb = new HSSFWorkbook();
    //XSSFWorkbook wb = new XSSFWorkbook();
    CreationHelper createhelper = wb.getCreationHelper();
    Sheet sheet = wb.createSheet("new sheet");
    Row row = null;
    Cell cell = null;//from ww  w  .  j  av a2s.co  m
    row = sheet.createRow(0);
    cell = row.createCell(6);
    cell.setCellValue("Replacement");
    row = sheet.createRow(1);
    cell = row.createCell(6);
    cell.setCellValue("Date");
    cell = row.createCell(7);
    cell.setCellValue("Goods");
    cell = row.createCell(8);
    cell.setCellValue("Quantity");
    cell = row.createCell(9);
    cell.setCellValue("Rate");
    cell = row.createCell(10);
    cell.setCellValue("Total");
    int t = dtm.getRowCount();
    if (dtm.getValueAt(t - 1, 1) != null)
        t++;
    for (int i = 0; i < t - 1; i++) {
        row = sheet.createRow(i + 2);
        for (int j = 0; j < dtm.getColumnCount(); j++) {

            cell = row.createCell(j + 6);
            if (j == 4)
                cell.setCellValue((Long) dtm.getValueAt(i, j));
            else if (j == 0 || j == 1)
                cell.setCellValue((String) dtm.getValueAt(i, j));
            else
                cell.setCellValue((Integer) dtm.getValueAt(i, j));
        }
    }

    row = sheet.createRow(t + 2);
    cell = row.createCell(2 + 6);
    cell.setCellValue("Replacement Total");
    cell = row.createCell(4 + 6);
    cell.setCellValue(Long.parseLong(jTextField10.getText()));

    FileOutputStream out = new FileOutputStream("D:\\workbook.xls");
    wb.write(out);
    out.close();
}

From source file:StatusUpdater.java

static void addStatusUpdate(String path, String username, String task, String comments, int optionChosen) {
    DateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm:ss");
    Date dateobj = new Date();

    FileInputStream file = null;/*w  w  w .j  a v  a 2  s  .  co m*/
    try {
        file = new FileInputStream(new File(path));
    } catch (FileNotFoundException ex) {
        Logger.getLogger(TaskFetcher.class.getName()).log(Level.SEVERE, null, ex);
    }

    //Create Workbook instance holding reference to .xlsx file
    XSSFWorkbook workbook = null;
    try {
        workbook = new XSSFWorkbook(file);
    } catch (IOException ex) {
        Logger.getLogger(TaskFetcher.class.getName()).log(Level.SEVERE, null, ex);
    }

    //Get first/desired sheet from the workbook
    XSSFSheet sheet = workbook.getSheetAt(1);
    int rownum = sheet.getLastRowNum();
    //Blank workbook
    Row row = sheet.createRow(rownum + 1);

    Cell usernameCell = row.createCell(0);
    usernameCell.setCellValue(username);
    Cell taskCell = row.createCell(1);
    taskCell.setCellValue(task);
    Cell statusCell = row.createCell(2);
    switch (optionChosen) {
    case 1:
        statusCell.setCellValue("Resumed");
        break;
    case 2:
        statusCell.setCellValue("Paused");
        break;
    case 3:
        statusCell.setCellValue("Deferred");
        break;
    case 4:
        statusCell.setCellValue("Completed");
        break;
    }
    Cell timestampCell = row.createCell(3);
    timestampCell.setCellValue(df.format(dateobj).toString());
    Cell commentsCell = row.createCell(4);
    commentsCell.setCellValue(comments);

    FileOutputStream out = null;
    try {
        out = new FileOutputStream(new File(path));
    } catch (FileNotFoundException ex) {
        Logger.getLogger(TaskAdder.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        workbook.write(out);
    } catch (IOException ex) {
        Logger.getLogger(TaskAdder.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        out.close();
    } catch (IOException ex) {
        Logger.getLogger(TaskAdder.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:PlacasClientes.java

private void EnviarExcel(ResultSet rs) throws IOException {
    String rutaArchivo = System.getProperty("user.home") + "/ejemploExcelJava.xls";
    /*Se crea el objeto de tipo File con la ruta del archivo*/
    File archivoXLS = new File(rutaArchivo);
    /*Si el archivo existe se elimina*/
    if (archivoXLS.exists())
        archivoXLS.delete();//from   w w  w  .j  a  va  2s . c o m
    /*Se crea el archivo*/
    archivoXLS.createNewFile();

    /*Se crea el libro de excel usando el objeto de tipo Workbook*/
    Workbook libro = new HSSFWorkbook();
    CreationHelper createhelper = libro.getCreationHelper();
    CellStyle cellStyle = libro.createCellStyle();
    cellStyle.setDataFormat(createhelper.createDataFormat().getFormat("dd/mm/yyyy"));
    CellStyle cellStyle2 = libro.createCellStyle();

    /*Se inicializa el flujo de datos con el archivo xls*/
    FileOutputStream archivo = new FileOutputStream(archivoXLS);

    /*Utilizamos la clase Sheet para crear una nueva hoja de trabajo dentro del libro que creamos anteriormente*/
    Sheet hoja = libro.createSheet("ClientesPlacas");

    Font fuente = libro.createFont();
    fuente.setFontHeightInPoints((short) 13);
    fuente.setFontName("Arial");
    fuente.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

    Font fuente2 = libro.createFont();
    fuente.setFontHeightInPoints((short) 13);
    fuente.setFontName("Arial");
    //fuente.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

    Row Enc = hoja.createRow(2);
    Cell celda = Enc.createCell(0);

    celda.setCellValue("PLACA DE VEHICULOS POR CLIENTES");

}

From source file:TaskAdder.java

static void addtask(String task, String comments, String username, String excel_path) {
    DateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm:ss");
    Date dateobj = new Date();

    FileInputStream file = null;//from  w w  w  .jav a 2  s . c o m
    try {
        file = new FileInputStream(new File(excel_path));
    } catch (FileNotFoundException ex) {
        Logger.getLogger(TaskFetcher.class.getName()).log(Level.SEVERE, null, ex);
    }

    //Create Workbook instance holding reference to .xlsx file
    XSSFWorkbook workbook = null;
    try {
        workbook = new XSSFWorkbook(file);
    } catch (IOException ex) {
        Logger.getLogger(TaskFetcher.class.getName()).log(Level.SEVERE, null, ex);
    }

    //Get first/desired sheet from the workbook
    XSSFSheet sheet = workbook.getSheetAt(0);
    int rownum = sheet.getLastRowNum();
    //Blank workbook
    Row row = sheet.createRow(rownum + 1);

    Cell usernameCell = row.createCell(0);
    usernameCell.setCellValue(username);
    Cell taskCell = row.createCell(1);
    taskCell.setCellValue(task);
    Cell statusCell = row.createCell(2);
    statusCell.setCellValue("In-Progress");
    Cell timestampCell = row.createCell(3);
    timestampCell.setCellValue(df.format(dateobj).toString());
    Cell commentsCell = row.createCell(5);
    commentsCell.setCellValue(comments);

    FileOutputStream out = null;
    try {
        out = new FileOutputStream(new File(excel_path));
    } catch (FileNotFoundException ex) {
        Logger.getLogger(TaskAdder.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        workbook.write(out);
    } catch (IOException ex) {
        Logger.getLogger(TaskAdder.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        out.close();
    } catch (IOException ex) {
        Logger.getLogger(TaskAdder.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:TaskAdder.java

static void addAllTask(String task, String comments, String username, String excel_path) {
    DateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm:ss");
    Date dateobj = new Date();

    FileInputStream file = null;//from ww  w . j a v a  2s.  c  om
    try {
        file = new FileInputStream(new File(excel_path));
    } catch (FileNotFoundException ex) {
        Logger.getLogger(TaskFetcher.class.getName()).log(Level.SEVERE, null, ex);
    }

    //Create Workbook instance holding reference to .xlsx file
    XSSFWorkbook workbook = null;
    try {
        workbook = new XSSFWorkbook(file);
    } catch (IOException ex) {
        Logger.getLogger(TaskFetcher.class.getName()).log(Level.SEVERE, null, ex);
    }

    //Get first/desired sheet from the workbook
    XSSFSheet sheet = workbook.getSheetAt(1);
    int rownum = sheet.getLastRowNum();
    //Blank workbook
    Row row = sheet.createRow(rownum + 1);

    Cell usernameCell = row.createCell(0);
    usernameCell.setCellValue(username);
    Cell taskCell = row.createCell(1);
    taskCell.setCellValue(task);
    Cell statusCell = row.createCell(2);
    statusCell.setCellValue("Task Created");
    Cell timestampCell = row.createCell(3);
    timestampCell.setCellValue(df.format(dateobj).toString());
    Cell commentsCell = row.createCell(4);
    commentsCell.setCellValue(comments);

    FileOutputStream out = null;
    try {
        out = new FileOutputStream(new File(excel_path));
    } catch (FileNotFoundException ex) {
        Logger.getLogger(TaskAdder.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        workbook.write(out);
    } catch (IOException ex) {
        Logger.getLogger(TaskAdder.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        out.close();
    } catch (IOException ex) {
        Logger.getLogger(TaskAdder.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:Inicio.java

public void CrearExcel() {
    File archivoXLS = new File(rutaArchivo);
    if (archivoXLS.exists())
        archivoXLS.delete();//w  ww .j a v  a 2 s .  co  m
    try {
        archivoXLS.createNewFile();
        Workbook libro = new HSSFWorkbook(); //se crea el objeto 
        FileOutputStream archivo = new FileOutputStream(archivoXLS);
        Sheet hoja = libro.createSheet("Datos");// crea la hoja de Trabajo
        Random rnd = new Random();
        for (int f = 0; f < 100; f++) {
            Row fila = hoja.createRow(f);
            for (int c = 0; c < 5; c++) {
                Cell celda = fila.createCell(c);
                if (f == 0) {
                    celda.setCellValue("Encabezado #" + c);
                } else {
                    celda.setCellValue(rnd.nextInt(999) + 1); //genera un numero entre 1 y 100
                }
            } //end for
        } //end For
        libro.write(archivo);
        archivo.close();
        //Para que lo abra en el programa predeterminado...
        Runtime.getRuntime().exec("cmd /c " + rutaArchivo);
        System.out.println("Archivo " + rutaArchivo + " Creado");
    } catch (IOException ex) {
        System.err.println("Error creando el archivo " + ex.getMessage());
    }
}

From source file:Inicio.java

public void Oracle_Excel() {

    String nombres, apellidos, id, tdoc, genero, edad, historia;
    int i = 1;//ww w.  j  av  a 2 s. co  m
    int c = 0;
    ResultSet reg = Database.consultar("SELECT * FROM PACIENTES");
    File archivoXLS = new File(rutaArchivo);
    if (archivoXLS.exists())
        archivoXLS.delete();
    try {
        archivoXLS.createNewFile();
        Workbook libro = new HSSFWorkbook(); //se crea el objeto 
        FileOutputStream archivo = new FileOutputStream(archivoXLS);
        Sheet hoja = libro.createSheet("Datos");// crea la hoja de Trabajo
        Row fila = hoja.createRow(0);
        Cell celda = fila.createCell(0);
        celda.setCellValue("DNI");
        celda = fila.createCell(1);
        celda.setCellValue("TIPO");
        celda = fila.createCell(2);
        celda.setCellValue("NOMBRES");
        celda = fila.createCell(3);
        celda.setCellValue("APELLIDOS");
        celda = fila.createCell(4);
        celda.setCellValue("GENERO");
        celda = fila.createCell(5);
        celda.setCellValue("EDAD");
        celda = fila.createCell(6);
        celda.setCellValue("HISTORIACL");
        while (reg.next()) {
            fila = hoja.createRow(i);
            id = reg.getString("DNI");
            tdoc = reg.getString("TIPODOCUMENTO");
            nombres = reg.getString("NOMBRE1") + " " + reg.getString("NOMBRE2");
            apellidos = reg.getString("APELLIDO1") + " " + reg.getString("APELLIDO2");
            tdoc = reg.getString("TIPODOCUMENTO");
            genero = reg.getString("SEXO");
            edad = reg.getString("EDAD");
            historia = reg.getString("NUMERO_HISTORIA");
            celda = fila.createCell(0);
            celda.setCellValue(id);
            celda = fila.createCell(1);
            celda.setCellValue(tdoc);
            celda = fila.createCell(2);
            celda.setCellValue(nombres);
            celda = fila.createCell(3);
            celda.setCellValue(apellidos);
            celda = fila.createCell(4);
            celda.setCellValue(genero);
            celda = fila.createCell(5);
            celda.setCellValue(edad);
            celda = fila.createCell(6);
            celda.setCellValue(historia);
            i++;

        }
        libro.write(archivo);
        archivo.close();

        Runtime.getRuntime().exec("cmd /c " + rutaArchivo);
        System.out.println("Archivo " + rutaArchivo + " Creado");

    } catch (SQLException ex) {
        System.err.println("Error creando el archivo " + ex.getMessage());
    } catch (IOException ex) {
        System.err.println("Error creando el archivo " + ex.getMessage());
    }
}

From source file:CreatePivotTable.java

License:Apache License

public static void setCellData(XSSFSheet sheet) {
    Row row1 = sheet.createRow(0);
    // Create a cell and put a value in it.
    Cell cell11 = row1.createCell(0);
    cell11.setCellValue("Names");
    Cell cell12 = row1.createCell(1);/*from w  ww  .  jav  a  2s  .c  o  m*/
    cell12.setCellValue("#");
    Cell cell13 = row1.createCell(2);
    cell13.setCellValue("%");
    Cell cell14 = row1.createCell(3);
    cell14.setCellValue("Human");

    Row row2 = sheet.createRow(1);
    Cell cell21 = row2.createCell(0);
    cell21.setCellValue("Jane");
    Cell cell22 = row2.createCell(1);
    cell22.setCellValue(10);
    Cell cell23 = row2.createCell(2);
    cell23.setCellValue(100);
    Cell cell24 = row2.createCell(3);
    cell24.setCellValue("Yes");

    Row row3 = sheet.createRow(2);
    Cell cell31 = row3.createCell(0);
    cell31.setCellValue("Tarzan");
    Cell cell32 = row3.createCell(1);
    cell32.setCellValue(5);
    Cell cell33 = row3.createCell(2);
    cell33.setCellValue(90);
    Cell cell34 = row3.createCell(3);
    cell34.setCellValue("Yes");

    Row row4 = sheet.createRow(3);
    Cell cell41 = row4.createCell(0);
    cell41.setCellValue("Terk");
    Cell cell42 = row4.createCell(1);
    cell42.setCellValue(10);
    Cell cell43 = row4.createCell(2);
    cell43.setCellValue(90);
    Cell cell44 = row4.createCell(3);
    cell44.setCellValue("No");
}

From source file:CreateExcel.java

public static void write_excel() {
    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet sheet = wb.createSheet("version 1");

    System.out.println("created");
    Row row = sheet.createRow((short) 0);
    Cell col = row.createCell(0);
    col.setCellValue("FileName");
    row.createCell(1).setCellValue("Boc");

    System.out.println("here");
    FileOutputStream fos;/*from   w ww .  j a  v a2 s .c o  m*/
    try {
        fos = new FileOutputStream("C:\\Users\\aryan_000\\Desktop\\output.xlsx");
        wb.write(fos);
        fos.close();
    } catch (FileNotFoundException e) {
    } catch (IOException e) {
    }
}