Example usage for org.apache.poi.ss.usermodel Sheet createRow

List of usage examples for org.apache.poi.ss.usermodel Sheet createRow

Introduction

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

Prototype

Row createRow(int rownum);

Source Link

Document

Create a new row within the sheet and return the high level representation

Usage

From source file:com.siberhus.tdfl.DflBaseTest.java

License:Apache License

@Before
public void createXLSFile() throws Exception {
    if (new File(XLS_FILE_IN_NAME).exists()) {
        return;/*  w  ww. java  2  s .  c  om*/
    }
    Workbook workbook = new HSSFWorkbook();
    Sheet sheet = workbook.createSheet("Untitled");
    String dataArray[][] = getTestData();
    for (int i = 0; i < dataArray.length; i++) {
        String data[] = dataArray[i];
        Row row = sheet.createRow(i);
        for (int j = 0; j < data.length; j++) {
            row.createCell(j).setCellValue(data[j]);
        }
    }
    OutputStream out = new FileOutputStream(XLS_FILE_IN_NAME);
    workbook.write(out);
    IOUtils.closeQuietly(out);
}

From source file:com.siemens.sw360.exporter.ExcelExporter.java

License:Open Source License

public InputStream makeExcelExport(List<T> documents) throws IOException {
    final Workbook workbook = new XSSFWorkbook();

    Sheet sheet = workbook.createSheet("Component Data");

    /** Adding styles to cells */
    CellStyle cellStyte = createCellStyte(workbook);
    CellStyle headerStyle = createHeaderStyle(workbook);

    /** Create header row */
    Row headerRow = sheet.createRow(0);
    List<String> headerNames = helper.getHeaders();
    fillRow(headerRow, headerNames, headerStyle);

    /** Create data rows */
    fillValues(sheet, documents, cellStyte);

    /** Resize the columns */
    for (int iColumns = 0; iColumns < nColumns; iColumns++) {
        sheet.autoSizeColumn(iColumns);/*  w w w  .ja v a  2s .c o  m*/
    }

    /** Copy the streams */
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    workbook.write(out);

    return new ByteArrayInputStream(out.toByteArray());
}

From source file:com.siemens.sw360.exporter.ExcelExporter.java

License:Open Source License

/**
 * Convert all documents to//from   w w w . j av a 2  s .  co m
 */
private void fillValues(Sheet sheet, List<T> documents, CellStyle style) {
    int nRow = documents.size();
    for (int iRow = 0; iRow < nRow; iRow++) {
        T document = documents.get(iRow);
        List<String> values = helper.makeRow(document);
        Row row = sheet.createRow(iRow + 1); // Since 0 is used for headers
        fillRow(row, values, style);
    }
}

From source file:com.simopuve.helper.FlowDataCreator.java

public static void FillDetailBaseSheet(List<PDVSurvey> surveyList, Sheet detailBaseSheet) {
    int rowIndex = 1;
    for (PDVSurvey survey : surveyList) {
        Row row = null;//  w  w w  .jav  a 2s .  c  o  m
        Cell cell = null;
        PDVHeader header = survey.getHeader();

        for (PDVRow encRow : survey.getRows()) {
            row = detailBaseSheet.createRow(rowIndex);
            cell = row.createCell(0);
            cell.setCellValue(header.getPointOfSaleName());

            cell = row.createCell(1);
            cell.setCellValue(header.getAddress());

            //TODO obtener info necesaria
            cell = row.createCell(2);
            cell.setCellValue("Comuna");

            //TODO obtener info
            cell = row.createCell(3);
            cell.setCellValue("Zona");

            cell = row.createCell(4);
            cell.setCellValue(getFlowBaseFormatDate(header.getSurveyDate()));

            cell = row.createCell(5);
            cell.setCellValue(header.getCompleteName());

            cell = row.createCell(6);
            cell.setCellValue(encRow.getPersonNumber());

            cell = row.createCell(7);
            cell.setCellValue(encRow.getDeviceBrand());

            cell = row.createCell(8);
            cell.setCellValue(encRow.getDeviceModel());

            cell = row.createCell(9);
            cell.setCellValue(encRow.getContractType());

            cell = row.createCell(10);
            cell.setCellValue(encRow.getDeviceMode());

            cell = row.createCell(11);
            cell.setCellValue(espBoolean(encRow.isBoughtCard()));

            cell = row.createCell(12);
            cell.setCellValue(espBoolean(encRow.isBoughtChip()));

            cell = row.createCell(13);
            cell.setCellValue(espBoolean(encRow.isBoughtAccessory()));

            cell = row.createCell(14);
            cell.setCellValue(encRow.getPlanRating());

            //TODO
            cell = row.createCell(15);
            cell.setCellValue(getWeekNumber(header.getSurveyDate()));

            //TODO
            cell = row.createCell(16);
            cell.setCellValue(getMonthNumber(header.getSurveyDate()));

            cell = row.createCell(17);
            cell.setCellValue((header.isMall()) ? "MALL" : "OFICINA");

            //TODO
            cell = row.createCell(18);
            cell.setCellValue("operador");

            cell = row.createCell(19);
            cell.setCellValue(encRow.getDeviceRating());

            cell = row.createCell(20);
            cell.setCellValue(encRow.getExpressRefillValue());

            cell = row.createCell(21);
            cell.setCellValue(encRow.getAdditionalCharacteristics());

            //TODO
            cell = row.createCell(22);
            cell.setCellValue("Total ventas");

            cell = row.createCell(23);
            cell.setCellValue(encRow.getPortabilityChange());

            cell = row.createCell(24);
            cell.setCellValue(encRow.getPortabilityChangeReason());
            rowIndex++;
        }
    }
}

From source file:com.simopuve.helper.FlowDataCreator.java

public static void FillFlowBaseSheet(List<PDVSurvey> surveyList, Sheet flowBaseSheet) {
    int rowIndex = 1;
    for (PDVSurvey survey : surveyList) {
        Row row = null;/*from w  w w. j  a  v  a 2s.c  o  m*/
        Cell cell = null;
        row = flowBaseSheet.createRow(rowIndex);
        PDVHeader header = survey.getHeader();

        cell = row.createCell(0);
        cell.setCellValue(header.getPointOfSaleName());

        cell = row.createCell(1);
        cell.setCellValue(header.getAddress());

        cell = row.createCell(2);
        cell.setCellValue(header.getComuna());

        //Campo zona en base flujo
        cell = row.createCell(3);
        cell.setCellValue("Por definir");

        cell = row.createCell(4);
        cell.setCellValue(getFlowBaseFormatDate(header.getSurveyDate()));

        cell = row.createCell(5);
        cell.setCellValue(header.getCompleteName());

        cell = row.createCell(6);
        cell.setCellValue(header.getNumberOfPeopleAM());

        cell = row.createCell(7);
        cell.setCellValue(header.getNumberOfPeoplePM());

        cell = row.createCell(8);
        cell.setCellValue(header.getPeopleWithBags());

        //Campo Compaia de punto de venta
        cell = row.createCell(9);
        cell.setCellValue("Por definir");

        cell = row.createCell(10);
        cell.setCellValue(header.getNumberOfPeopleAM() + header.getNumberOfPeoplePM());

        //TODO Semana
        cell = row.createCell(11);
        cell.setCellValue("SEMANA " + getWeekNumber(header.getSurveyDate()));

        //TODO Mes
        cell = row.createCell(12);
        cell.setCellValue("MES " + getMonthNumber(header.getSurveyDate()));

        cell = row.createCell(13);
        cell.setCellValue((header.isMall()) ? "MALL" : "OFICINA");

        rowIndex++;
    }
}

From source file:com.sirelab.controller.reportes.ControllerGeneradorReportes.java

public void reporteUsuariosSistema() throws Exception {
    String rutaArchivo = "";
    if (validarNombreReporte()) {
        rutaArchivo = System.getProperty("user.home") + "/" + nombreReporte + ".xls";
    } else {/*from ww  w.ja  va 2 s  . c  o  m*/
        rutaArchivo = System.getProperty("user.home") + "/" + "USUARIOS_REGISTRADOS_SIRELAB" + ".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("USUARIOS REGISTRADOS");
    List<Persona> personas = administradorGeneradorReportesBO.obtenerPersonasDelSistema();
    int tamtotal = personas.size();
    for (int f = 0; f < tamtotal; f++) {
        Row fila = hoja.createRow(f);
        Persona persona = personas.get(f);
        for (int c = 0; c < 10; c++) {
            Cell celda = fila.createCell(c);
            if (f == 0) {
                if (c == 0) {
                    celda.setCellValue("NOMBRES_USUARIO");
                } else if (c == 1) {
                    celda.setCellValue("APELLIDOS_USUARIO");
                } else if (c == 2) {
                    celda.setCellValue("IDENTIFICACION");
                } else if (c == 3) {
                    celda.setCellValue("CORREO");
                } else if (c == 4) {
                    celda.setCellValue("TELEFONO_1");
                } else if (c == 5) {
                    celda.setCellValue("TELEFONO_2");
                } else if (c == 6) {
                    celda.setCellValue("DIRECCION");
                } else if (c == 7) {
                    celda.setCellValue("USUARIO");
                } else if (c == 8) {
                    celda.setCellValue("TIPO_USUARIO");
                } else if (c == 9) {
                    celda.setCellValue("ESTADO");
                }
            } else {
                if (c == 0) {
                    celda.setCellValue(persona.getNombrespersona());
                } else if (c == 1) {
                    celda.setCellValue(persona.getApellidospersona());
                } else if (c == 2) {
                    celda.setCellValue(persona.getIdentificacionpersona());
                } else if (c == 3) {
                    celda.setCellValue(persona.getEmailpersona());
                } else if (c == 4) {
                    celda.setCellValue(persona.getTelefono1persona());
                } else if (c == 5) {
                    celda.setCellValue(persona.getTelefono2persona());
                } else if (c == 6) {
                    celda.setCellValue(persona.getDireccionpersona());
                } else if (c == 7) {
                    celda.setCellValue(persona.getUsuario().getNombreusuario());
                } else if (c == 8) {
                    celda.setCellValue(persona.getUsuario().getTipousuario().getNombretipousuario());
                } else if (c == 9) {
                    celda.setCellValue(persona.getUsuario().getStrEstado());
                }
            }
        }
    }
    libro.write(archivo);
    archivo.close();
    descargarArchivo(rutaArchivo);
}

From source file:com.sirelab.controller.reportes.ControllerGeneradorReportes.java

public void reporteProveedoresSistema() throws Exception {
    String rutaArchivo = "";
    if (validarNombreReporte()) {
        rutaArchivo = System.getProperty("user.home") + "/" + nombreReporte + ".xls";
    } else {/*  w  w w. ja  v  a2  s .c o  m*/
        rutaArchivo = System.getProperty("user.home") + "/" + "PROVEEDORES" + ".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("PROVEEDORES");
    List<Proveedor> proveedores = administradorGeneradorReportesBO.consultarProveedoresRegistrados();
    int tamtotal = 0;
    if (null != proveedores) {
        tamtotal = proveedores.size();
    }
    for (int f = 0; f < tamtotal; f++) {
        Row fila = hoja.createRow(f);
        Proveedor proveedor = proveedores.get(f);
        for (int c = 0; c < 4; c++) {
            Cell celda = fila.createCell(c);
            if (f == 0) {
                if (c == 0) {
                    celda.setCellValue("NIT_PROVEEDOR");
                } else if (c == 1) {
                    celda.setCellValue("NOMBRE_PROVEEDOR");
                } else if (c == 2) {
                    celda.setCellValue("DIRECCION");
                } else if (c == 3) {
                    celda.setCellValue("TELEFONO");
                }
            } else {
                if (c == 0) {
                    celda.setCellValue(proveedor.getNitproveedor());
                } else if (c == 1) {
                    celda.setCellValue(proveedor.getNombreproveedor());
                } else if (c == 2) {
                    celda.setCellValue(proveedor.getDireccionproveedor());
                } else if (c == 3) {
                    celda.setCellValue(proveedor.getTelefonoproveedor());
                }
            }
        }
    }
    libro.write(archivo);
    archivo.close();
    descargarArchivo(rutaArchivo);
}

From source file:com.sirelab.controller.reportes.ControllerGeneradorReportes.java

public void reporteSalasLaboratorio() throws Exception {
    String rutaArchivo = "";
    if (validarNombreReporte()) {
        rutaArchivo = System.getProperty("user.home") + "/" + nombreReporte + ".xls";
    } else {/*from   w  ww  .  j  a  va  2s. c o m*/
        rutaArchivo = System.getProperty("user.home") + "/" + "SALAS_LABORATORIO" + ".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("SALAS_LABORATORIO");
    List<SalaLaboratorio> salas = administradorGeneradorReportesBO.obtenerSalasLaboratorio();
    int tamtotal = 0;
    if (null != salas) {
        tamtotal = salas.size();
    }
    for (int f = 0; f < tamtotal; f++) {
        Row fila = hoja.createRow(f);
        SalaLaboratorio sala = salas.get(f);
        for (int c = 0; c < 8; c++) {
            Cell celda = fila.createCell(c);
            if (f == 0) {
                if (c == 0) {
                    celda.setCellValue("DEPARTAMENTO");
                } else if (c == 1) {
                    celda.setCellValue("LABORATORIO");
                } else if (c == 2) {
                    celda.setCellValue("NOMBRE");
                } else if (c == 3) {
                    celda.setCellValue("CODIGO");
                } else if (c == 4) {
                    celda.setCellValue("ESTADO");
                } else if (c == 5) {
                    celda.setCellValue("SEDE");
                } else if (c == 6) {
                    celda.setCellValue("EDIFICIO");
                } else if (c == 7) {
                    celda.setCellValue("UBICACION");
                }
            } else {
                if (c == 0) {
                    celda.setCellValue(sala.getLaboratorio().getDepartamento().getNombredepartamento());
                } else if (c == 1) {
                    celda.setCellValue(sala.getLaboratorio().getNombrelaboratorio());
                } else if (c == 2) {
                    celda.setCellValue(sala.getNombresala());
                } else if (c == 3) {
                    celda.setCellValue(sala.getCodigosala());
                } else if (c == 4) {
                    celda.setCellValue(sala.getStrEstado());
                } else if (c == 5) {
                    celda.setCellValue(sala.getEdificio().getSede().getNombresede());
                } else if (c == 6) {
                    celda.setCellValue(sala.getEdificio().getDescripcionedificio());
                } else if (c == 7) {
                    celda.setCellValue(sala.getPisoubicacion());
                }
            }
        }
    }
    libro.write(archivo);
    archivo.close();
    descargarArchivo(rutaArchivo);
}

From source file:com.sirelab.controller.reportes.ControllerGeneradorReportes.java

public void reporteReservasPorPeriodo() throws Exception {
    listaReservasGenerador = null;/*from ww  w. j a  v  a 2 s .c o  m*/
    String rutaArchivo = "";
    if (validarNombreReporte()) {
        rutaArchivo = System.getProperty("user.home") + "/" + nombreReporte + ".xls";
    } else {
        rutaArchivo = System.getProperty("user.home") + "/" + "RESERVAS_POR_PERIODO" + ".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("RESERVAS");
    BigInteger idPeriodo = null;
    if (null != periodo) {
        idPeriodo = periodo.getIdperiodoacademico();
    }
    List<ReservaModuloLaboratorio> reservamodulo = administradorGeneradorReportesBO
            .obtenerReservasModuloLaboratorioPorPeriodoAcademico(idPeriodo);
    convertirReservasModulo(reservamodulo);
    List<ReservaSala> reservasala = administradorGeneradorReportesBO
            .obtenerReservasSalaPorPeriodoAcademico(idPeriodo);
    convertirReservasSala(reservasala);
    int tamtotal = listaReservasGenerador.size();
    for (int f = 0; f < tamtotal; f++) {
        Row fila = hoja.createRow(f);
        ReservasGenerador reserva = listaReservasGenerador.get(f);
        for (int c = 0; c < 13; c++) {
            Cell celda = fila.createCell(c);
            if (f == 0) {
                if (c == 0) {
                    celda.setCellValue("ID_RESERVA");
                } else if (c == 1) {
                    celda.setCellValue("RESERVA");
                } else if (c == 2) {
                    celda.setCellValue("FECHA_RESERVA");
                } else if (c == 3) {
                    celda.setCellValue("HORA_RESERVA");
                } else if (c == 4) {
                    celda.setCellValue("HORA_REAL");
                } else if (c == 5) {
                    celda.setCellValue("TIPO_RESERVA");
                } else if (c == 6) {
                    celda.setCellValue("SERVICIO");
                } else if (c == 7) {
                    celda.setCellValue("LABORATORIO");
                } else if (c == 8) {
                    celda.setCellValue("SALA_LABORATORIO");
                } else if (c == 9) {
                    celda.setCellValue("ESTADO");
                } else if (c == 10) {
                    celda.setCellValue("TIPO_USUARIO");
                } else if (c == 11) {
                    celda.setCellValue("USUARIO");
                } else if (c == 12) {
                    celda.setCellValue("ID_USUARIO");
                }
            } else {
                if (c == 0) {
                    celda.setCellValue(reserva.getID_RESERVA());
                } else if (c == 1) {
                    celda.setCellValue(reserva.getRESERVA());
                } else if (c == 2) {
                    celda.setCellValue(reserva.getFECHA_RESERVA());
                } else if (c == 3) {
                    celda.setCellValue(reserva.getHORA_RESERVA());
                } else if (c == 4) {
                    celda.setCellValue(reserva.getHORA_REAL());
                } else if (c == 5) {
                    celda.setCellValue(reserva.getTIPO_RESERVA());
                } else if (c == 6) {
                    celda.setCellValue(reserva.getSERVICIO());
                } else if (c == 7) {
                    celda.setCellValue(reserva.getLABORATORIO());
                } else if (c == 8) {
                    celda.setCellValue(reserva.getSALA_LABORATORIO());
                } else if (c == 9) {
                    celda.setCellValue(reserva.getESTADO());
                } else if (c == 10) {
                    celda.setCellValue(reserva.getTIPO_USUARIO());
                } else if (c == 11) {
                    celda.setCellValue(reserva.getUSUARIO());
                } else if (c == 12) {
                    celda.setCellValue(reserva.getID_USUARIO());
                }
            }
        }
    }
    libro.write(archivo);
    archivo.close();
    descargarArchivo(rutaArchivo);
}

From source file:com.sirelab.controller.reportes.ControllerGeneradorReportes.java

public void reporteReservasPorTipoUsuario() throws Exception {
    listaReservasGenerador = null;//from  w  ww. j  a va2s .  c  o  m
    String rutaArchivo = "";
    if (validarNombreReporte()) {
        rutaArchivo = System.getProperty("user.home") + "/" + nombreReporte + ".xls";
    } else {
        rutaArchivo = System.getProperty("user.home") + "/" + "RESERVAS_POR_TIPO_USUARIO" + ".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("RESERVAS");
    List<ReservaModuloLaboratorio> reservamodulo = administradorGeneradorReportesBO
            .obtenerReservasModuloLaboratorioPorTipoUsuario(tipoUsuario);
    convertirReservasModulo(reservamodulo);
    List<ReservaSala> reservasala = administradorGeneradorReportesBO
            .obtenerReservasSalaPorTipoUsuario(tipoUsuario);
    convertirReservasSala(reservasala);
    int tamtotal = listaReservasGenerador.size();
    for (int f = 0; f < tamtotal; f++) {
        Row fila = hoja.createRow(f);
        ReservasGenerador reserva = listaReservasGenerador.get(f);
        for (int c = 0; c < 13; c++) {
            Cell celda = fila.createCell(c);
            if (f == 0) {
                if (c == 0) {
                    celda.setCellValue("ID_RESERVA");
                } else if (c == 1) {
                    celda.setCellValue("RESERVA");
                } else if (c == 2) {
                    celda.setCellValue("FECHA_RESERVA");
                } else if (c == 3) {
                    celda.setCellValue("HORA_RESERVA");
                } else if (c == 4) {
                    celda.setCellValue("HORA_REAL");
                } else if (c == 5) {
                    celda.setCellValue("TIPO_RESERVA");
                } else if (c == 6) {
                    celda.setCellValue("SERVICIO");
                } else if (c == 7) {
                    celda.setCellValue("LABORATORIO");
                } else if (c == 8) {
                    celda.setCellValue("SALA_LABORATORIO");
                } else if (c == 9) {
                    celda.setCellValue("ESTADO");
                } else if (c == 10) {
                    celda.setCellValue("TIPO_USUARIO");
                } else if (c == 11) {
                    celda.setCellValue("USUARIO");
                } else if (c == 12) {
                    celda.setCellValue("ID_USUARIO");
                }
            } else {
                if (c == 0) {
                    celda.setCellValue(reserva.getID_RESERVA());
                } else if (c == 1) {
                    celda.setCellValue(reserva.getRESERVA());
                } else if (c == 2) {
                    celda.setCellValue(reserva.getFECHA_RESERVA());
                } else if (c == 3) {
                    celda.setCellValue(reserva.getHORA_RESERVA());
                } else if (c == 4) {
                    celda.setCellValue(reserva.getHORA_REAL());
                } else if (c == 5) {
                    celda.setCellValue(reserva.getTIPO_RESERVA());
                } else if (c == 6) {
                    celda.setCellValue(reserva.getSERVICIO());
                } else if (c == 7) {
                    celda.setCellValue(reserva.getLABORATORIO());
                } else if (c == 8) {
                    celda.setCellValue(reserva.getSALA_LABORATORIO());
                } else if (c == 9) {
                    celda.setCellValue(reserva.getESTADO());
                } else if (c == 10) {
                    celda.setCellValue(reserva.getTIPO_USUARIO());
                } else if (c == 11) {
                    celda.setCellValue(reserva.getUSUARIO());
                } else if (c == 12) {
                    celda.setCellValue(reserva.getID_USUARIO());
                }
            }
        }
    }
    libro.write(archivo);
    archivo.close();
    descargarArchivo(rutaArchivo);
}