Example usage for org.apache.poi.xssf.usermodel XSSFWorkbook getCreationHelper

List of usage examples for org.apache.poi.xssf.usermodel XSSFWorkbook getCreationHelper

Introduction

In this page you can find the example usage for org.apache.poi.xssf.usermodel XSSFWorkbook getCreationHelper.

Prototype

@Override
public XSSFCreationHelper getCreationHelper() 

Source Link

Document

Returns an object that handles instantiating concrete classes of the various instances for XSSF.

Usage

From source file:com.pe.nisira.movil.view.action.RegistroPaleta.java

public StreamedContent downFormatExcel() throws Exception {
    InputStream stream = null;/*  w w  w.ja  v  a2  s  .  co m*/
    StreamedContent arch = null;
    try {
        String folder = "C:\\SOLUTION\\WEB\\FORMATOS_IMPORTACION";
        File ruta = new File(folder);
        if (!ruta.isDirectory()) {
            ruta.mkdirs();
        }
        String rutaArchivo = folder + "\\FI_REGISTROPALE.xlsx";
        File fileXls = new File(rutaArchivo);
        if (fileXls.exists()) {
            fileXls.delete();
        }
        fileXls.createNewFile();
        XSSFWorkbook libro = new XSSFWorkbook();
        FileOutputStream file2 = new FileOutputStream(fileXls);
        XSSFSheet hoja = libro.createSheet("IMPORTAR_PALETA");
        CreationHelper factory = libro.getCreationHelper();
        hoja = libro.getSheetAt(0);
        XSSFCellStyle style = libro.createCellStyle();
        Font font = libro.createFont();
        Font font1 = libro.createFont();
        Drawing drawing = hoja.createDrawingPatriarch();
        ClientAnchor anchor1 = factory.createClientAnchor();
        font.setBoldweight(Font.BOLDWEIGHT_BOLD);
        font.setFontHeightInPoints((short) 8);
        font1.setFontHeightInPoints((short) 8);
        font1.setFontName("Arial");
        font.setFontName("Arial");
        style.setFillForegroundColor(new XSSFColor(new java.awt.Color(247, 150, 70)));
        style.setFillPattern(CellStyle.SOLID_FOREGROUND);
        style.setAlignment(CellStyle.VERTICAL_CENTER);
        style.setAlignment(CellStyle.ALIGN_CENTER);
        style.setFont(font);

        XSSFSheet hoja2 = libro.createSheet("IMPORTAR_DET_PALETA");
        CreationHelper factory2 = libro.getCreationHelper();
        hoja2 = libro.getSheetAt(1);
        XSSFCellStyle style2 = libro.createCellStyle();
        Font font2 = libro.createFont();
        Font font12 = libro.createFont();
        Drawing drawing2 = hoja2.createDrawingPatriarch();
        ClientAnchor anchor12 = factory2.createClientAnchor();
        font2.setBoldweight(Font.BOLDWEIGHT_BOLD);
        font2.setFontHeightInPoints((short) 8);
        font12.setFontHeightInPoints((short) 8);
        font12.setFontName("Arial");
        font2.setFontName("Arial");
        style2.setFillForegroundColor(new XSSFColor(new java.awt.Color(247, 150, 70)));
        style2.setFillPattern(CellStyle.SOLID_FOREGROUND);
        style2.setAlignment(CellStyle.VERTICAL_CENTER);
        style2.setAlignment(CellStyle.ALIGN_CENTER);
        style2.setFont(font);
        for (int f = 0; f < 1; f++) {
            XSSFRow fila = hoja.createRow(f);
            for (int c = 0; c < 29; c++) {
                XSSFCell celda = fila.createCell(c);
                celda.setCellStyle(style);
                anchor1.setCol1(celda.getColumnIndex());
                anchor1.setCol2(celda.getColumnIndex() + 5);
                anchor1.setRow1(fila.getRowNum());
                anchor1.setRow2(fila.getRowNum() + 3);
                Comment comment = drawing.createCellComment(anchor1);
                if (f == 0 && c == 0) {
                    RichTextString str = factory.createRichTextString("ADM:\nCampo Obligatorio \n - IDEMPRESA");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("IDEMPRESA");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 1) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - IDREGISTROPALETA. \n Debe de tener (15) caracteres");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("IDREGISTROPALETA");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 2) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Id del emisor. \n -Debe tener 3 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("IDEMISOR");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 3) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - id de la operacion.\n -Debe tener 4 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("IDOPERACION");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 4) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Numero de Operacion.\n -Debe tener 10 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("NUMOPERACION");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 5) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Id del motivo de Paleta.\n -Debe tener 3 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("IDMOTIVOPALETA");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 6) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Id documento. \n -Debe tener 3 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("IDDOCUMENTO");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 7) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Serie del Documento. \n -Debe tener 4 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("SERIE");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 8) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Numero de Documento.\n -Debe tener 7 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("NUMERO");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 9) {
                    RichTextString str = factory
                            .createRichTextString("ADM:\nCampo Obligatorio \n - Formato YYYY/MM/DD.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("FECHA");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 10) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Perido del ao \n - fromato YYYYMM.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("PERIODO");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 11) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Id del estado \n -Debe tener 2 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("IDESTADO");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 12) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Id del cliente o proveedor \n -Debe tener 11 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("IDCLIEPROV");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 13) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Numero de Paleta \n -Debe tener 20 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("NROPALETA");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 14) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Id de envase \n -Debe tener 3 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("IDENVASE");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 15) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Id la sucursal \n -Debe tener 3 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("IDSUCURSAL");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 16) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Id del almacen. \n -Debe tener 3 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("IDALMACEN");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 17) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Id del embalaje. \n -Debe tener 10 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("IDEMBALAJE");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 18) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Id de cultivo. \n -Debe tener 4 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("IDCULTIVO");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 19) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - id de Variadd. \n -Debe tener 3 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("IDVARIEDAD");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 20) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Observaciones sobre la paleta \n -como maximo 240 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("OBSERVACIONES");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 21) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n -Nombre de la venta \n como maximo 50 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("VENTANA");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 22) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Cantidad. \n - 15 numeros y 2 decimales como maximo.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("CANTIDAD");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 23) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Estado de la paleta \n- 1 = cerrado, 0 = Abierto.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("CERRADO");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 24) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Sincroniza \n - N = no , S = si.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("SINCRONIZA");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 25) {
                    RichTextString str = factory
                            .createRichTextString("ADM:\nCampo Obligatorio \n - Formato YYYY/MM/DD.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("FECHACREACION");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 26) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Numero de Manural\n Debe tener 10 caracteres.");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("NROMANUAL");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 27) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - idcliepro-destino\n debe tener 11 caracteres");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("IDCLIEPROV_DESTINO");
                    celda.setCellComment(comment);
                } else if (f == 0 && c == 28) {
                    RichTextString str = factory.createRichTextString(
                            "ADM:\nCampo Obligatorio \n - Tipo de paleta\n debe tener 1 caraccter..");
                    str.applyFont(font1);
                    str.applyFont(0, 19, font);
                    comment.setString(str);
                    comment.setAuthor("ADM");
                    celda.setCellValue("TIPO");
                    celda.setCellComment(comment);
                }
            }
        }
        hoja.autoSizeColumn((short) 0);
        hoja.autoSizeColumn((short) 1);
        hoja.autoSizeColumn((short) 2);
        hoja.autoSizeColumn((short) 3);
        hoja.autoSizeColumn((short) 4);
        hoja.autoSizeColumn((short) 5);
        hoja.autoSizeColumn((short) 6);
        hoja.autoSizeColumn((short) 7);
        hoja.autoSizeColumn((short) 8);
        hoja.autoSizeColumn((short) 9);
        hoja.autoSizeColumn((short) 10);
        hoja.autoSizeColumn((short) 11);
        hoja.autoSizeColumn((short) 12);
        hoja.autoSizeColumn((short) 13);
        hoja.autoSizeColumn((short) 14);
        hoja.autoSizeColumn((short) 15);
        hoja.autoSizeColumn((short) 16);
        hoja.autoSizeColumn((short) 17);
        hoja.autoSizeColumn((short) 18);
        hoja.autoSizeColumn((short) 19);
        hoja.autoSizeColumn((short) 20);
        hoja.autoSizeColumn((short) 21);
        hoja.autoSizeColumn((short) 22);
        hoja.autoSizeColumn((short) 23);
        hoja.autoSizeColumn((short) 24);
        hoja.autoSizeColumn((short) 25);
        hoja.autoSizeColumn((short) 26);
        hoja.autoSizeColumn((short) 27);
        hoja.autoSizeColumn((short) 28);
        for (int f = 0; f < 2; f++) {
            XSSFRow fila2 = hoja2.createRow(f);
            if (f == 0) {
                for (int c = 0; c < 15; c++) {
                    XSSFCell celda2 = fila2.createCell(c);
                    anchor12.setCol1(celda2.getColumnIndex());
                    anchor12.setCol2(celda2.getColumnIndex() + 8);
                    anchor12.setRow1(fila2.getRowNum());
                    anchor12.setRow2(fila2.getRowNum() + 8);
                    Comment comment2 = drawing2.createCellComment(anchor12);
                    RichTextString str;
                    switch (c) {
                    case 0:
                        celda2.setCellStyle(style2);
                        str = factory2.createRichTextString(
                                "ADM:\nCampo Obligatorio \n - El Cdigo debe de ser nico.");
                        str.applyFont(font12);
                        str.applyFont(0, 19, font2);
                        comment2.setString(str);
                        comment2.setAuthor("ADM");
                        celda2.setCellValue("IDEMPRESA");
                        celda2.setCellComment(comment2);
                        break;
                    case 1:
                        celda2.setCellStyle(style2);
                        str = factory.createRichTextString("ADM:\nCampo Obligatorio ");
                        str.applyFont(font12);
                        str.applyFont(0, 19, font2);
                        comment2.setString(str);
                        comment2.setAuthor("ADM");
                        celda2.setCellValue("IDREGISTROPALETA");
                        celda2.setCellComment(comment2);
                        break;
                    case 2:
                        celda2.setCellStyle(style2);
                        str = factory.createRichTextString("ADM:\nCampo Obligatorio ");
                        str.applyFont(font12);
                        str.applyFont(0, 19, font2);
                        comment2.setString(str);
                        comment2.setAuthor("ADM");
                        celda2.setCellValue("ITEM");
                        celda2.setCellComment(comment2);
                        break;
                    case 3:
                        celda2.setCellStyle(style2);
                        str = factory.createRichTextString("ADM:\nCampo Obligatorio ");
                        str.applyFont(font12);
                        str.applyFont(0, 19, font2);
                        comment2.setString(str);
                        comment2.setAuthor("ADM");
                        celda2.setCellValue("IDCLIEPROV");
                        celda2.setCellComment(comment2);
                        break;
                    case 4:
                        celda2.setCellStyle(style2);
                        str = factory.createRichTextString("ADM:\nCampo Obligatorio");
                        str.applyFont(font12);
                        str.applyFont(0, 19, font2);
                        comment2.setString(str);
                        comment2.setAuthor("ADM");
                        celda2.setCellValue("IDLOTE");
                        celda2.setCellComment(comment2);
                        break;
                    case 5:
                        celda2.setCellStyle(style2);
                        str = factory.createRichTextString("ADM:\nCampo Obligatorio");
                        str.applyFont(font12);
                        str.applyFont(0, 19, font2);
                        comment2.setString(str);
                        comment2.setAuthor("ADM");
                        celda2.setCellValue("IDCONDICION");
                        celda2.setCellComment(comment2);
                        break;
                    case 6:
                        celda2.setCellStyle(style2);
                        str = factory.createRichTextString("ADM:\nCampo Obligatorio");
                        str.applyFont(font12);
                        str.applyFont(0, 19, font2);
                        comment2.setString(str);
                        comment2.setAuthor("ADM");
                        celda2.setCellValue("IDTALLA");
                        celda2.setCellComment(comment2);
                        break;
                    case 7:
                        celda2.setCellStyle(style2);
                        str = factory.createRichTextString("ADM:\nCampo Obligatorio");
                        str.applyFont(font12);
                        str.applyFont(0, 19, font2);
                        comment2.setString(str);
                        comment2.setAuthor("ADM");
                        celda2.setCellValue("IDCOLOR");
                        celda2.setCellComment(comment2);
                        break;
                    case 8:
                        celda2.setCellStyle(style2);
                        str = factory.createRichTextString("ADM:\nCampo Obligatorio");
                        str.applyFont(font12);
                        str.applyFont(0, 19, font2);
                        comment2.setString(str);
                        comment2.setAuthor("ADM");
                        celda2.setCellValue("CANTIDAD");
                        celda2.setCellComment(comment2);
                        break;
                    case 9:
                        celda2.setCellStyle(style2);
                        str = factory.createRichTextString("ADM:\nCampo Obligatorio");
                        str.applyFont(font12);
                        str.applyFont(0, 19, font2);
                        comment2.setString(str);
                        comment2.setAuthor("ADM");
                        celda2.setCellValue("IDEMBALAJE");
                        celda2.setCellComment(comment2);
                        break;
                    case 10:
                        celda2.setCellStyle(style2);
                        str = factory.createRichTextString("ADM:\nCampo Obligatorio");
                        str.applyFont(font12);
                        str.applyFont(0, 19, font2);
                        comment2.setString(str);
                        comment2.setAuthor("ADM");
                        celda2.setCellValue("IDPRODUCTO");
                        celda2.setCellComment(comment2);
                        break;
                    case 11:
                        celda2.setCellStyle(style2);
                        str = factory.createRichTextString("ADM:\nCampo Obligatorio");
                        str.applyFont(font12);
                        str.applyFont(0, 19, font2);
                        comment2.setString(str);
                        comment2.setAuthor("ADM");
                        celda2.setCellValue("IDLOTEP");
                        celda2.setCellComment(comment2);
                        break;
                    case 12:
                        celda2.setCellStyle(style2);
                        str = factory.createRichTextString("ADM:\nCampo Obligatorio");
                        str.applyFont(font12);
                        str.applyFont(0, 19, font2);
                        comment2.setString(str);
                        comment2.setAuthor("ADM");
                        celda2.setCellValue("IDCONSUMIDOR");
                        celda2.setCellComment(comment2);
                        break;
                    case 13:
                        celda2.setCellStyle(style2);
                        str = factory.createRichTextString("ADM:\nCampo Obligatorio");
                        str.applyFont(font12);
                        str.applyFont(0, 19, font2);
                        comment2.setString(str);
                        comment2.setAuthor("ADM");
                        celda2.setCellValue("IDLOTECAMPO");
                        celda2.setCellComment(comment2);
                        break;
                    case 14:
                        celda2.setCellStyle(style2);
                        str = factory.createRichTextString("ADM:\nCampo Obligatorio");
                        str.applyFont(font12);
                        str.applyFont(0, 19, font2);
                        comment2.setString(str);
                        comment2.setAuthor("ADM");
                        celda2.setCellValue("IDPRESENTACION");
                        celda2.setCellComment(comment2);
                        break;
                    }
                }
            }
        }
        hoja2.autoSizeColumn((short) 0);
        hoja2.autoSizeColumn((short) 1);
        hoja2.autoSizeColumn((short) 2);
        hoja2.autoSizeColumn((short) 3);
        hoja2.autoSizeColumn((short) 4);
        hoja2.autoSizeColumn((short) 5);
        hoja2.autoSizeColumn((short) 6);
        hoja2.autoSizeColumn((short) 7);
        hoja2.autoSizeColumn((short) 8);
        hoja2.autoSizeColumn((short) 9);
        hoja2.autoSizeColumn((short) 10);
        hoja2.autoSizeColumn((short) 11);
        hoja2.autoSizeColumn((short) 12);
        hoja2.autoSizeColumn((short) 13);
        hoja2.autoSizeColumn((short) 14);
        hoja2.autoSizeColumn((short) 15);
        libro.write(file2);
        file2.close();
        stream = new FileInputStream(new File(rutaArchivo));
        arch = new DefaultStreamedContent(stream, "application/xlsx", "FI_REGISTROPALE.xlsx");
    } catch (FileNotFoundException ex) {
        System.out.println("Error al Descargar : " + ex.getMessage());
    }
    return arch;
}

From source file:com.phucdk.emailsender.utils.ExcelUtils.java

public static String getCellValueAsString(int row, int column, XSSFWorkbook myWorkBook) {
    XSSFSheet mySheet = myWorkBook.getSheetAt(1);
    Cell cell = getCell(row, column, mySheet);
    String strCellValue = "";
    FormulaEvaluator evaluator = myWorkBook.getCreationHelper().createFormulaEvaluator();
    if (cell != null) {
        CellValue cellValue = null;/*from  ww  w . java  2s .c  om*/
        try {
            cellValue = evaluator.evaluate(cell);
        } catch (Exception ex) {
            log.error("Error when evaluate cell value", ex);
        }

        if (cellValue != null) {
            switch (cellValue.getCellType()) {
            case Cell.CELL_TYPE_NUMERIC:
                strCellValue = String.valueOf(cellValue.getNumberValue());
                break;
            case Cell.CELL_TYPE_BOOLEAN:
                strCellValue = String.valueOf(cellValue.getBooleanValue());
                break;
            case Cell.CELL_TYPE_STRING:
                strCellValue = String.valueOf(cellValue.getStringValue());
                break;
            case Cell.CELL_TYPE_FORMULA:
                //strCellValue = String.valueOf(cellValue.get());
                break;
            }
        }

    }
    return strCellValue;
}

From source file:com.phucdk.emailsender.utils.ExcelUtils.java

public static Object getCellValue(int row, int column, XSSFWorkbook myWorkBook) {
    XSSFSheet mySheet = myWorkBook.getSheetAt(1);
    Cell cell = getCell(row, column, mySheet);
    Object cellValueObject = "";
    FormulaEvaluator evaluator = myWorkBook.getCreationHelper().createFormulaEvaluator();
    if (cell != null) {
        CellValue cellValue = null;// ww  w . ja  v a  2 s  .  c  o m
        try {
            cellValue = evaluator.evaluate(cell);
        } catch (Exception ex) {
            log.error("Error when evaluate cell value", ex);
        }

        if (cellValue != null) {
            switch (cellValue.getCellType()) {
            case Cell.CELL_TYPE_NUMERIC:
                cellValueObject = cellValue.getNumberValue();
                break;
            case Cell.CELL_TYPE_BOOLEAN:
                cellValueObject = cellValue.getBooleanValue();
                break;
            case Cell.CELL_TYPE_STRING:
                cellValueObject = cellValue.getStringValue();
                break;
            case Cell.CELL_TYPE_FORMULA:
                //strCellValue = cellValue.getErrorValue();
                break;
            }
        }

    }
    return cellValueObject;
}

From source file:com.respam.comniq.models.POIexcelExporter.java

License:Open Source License

public void excelWriter(JSONObject parsedObj, int rownum) throws IOException {
    String path = System.getProperty("user.home") + File.separator + "comniq" + File.separator + "output";
    File file = new File(path + File.separator + "POImovieInfo.xlsx");

    String thumbnailPath = System.getProperty("user.home") + File.separator + "comniq" + File.separator
            + "output" + File.separator + "thumbnails";
    File posterFile = new File(thumbnailPath + File.separator + parsedObj.get("Title") + ".jpg");

    if (!file.exists()) {
        createFile();/*from   ww w  .ja v  a  2s .c o  m*/
    }

    if (file.exists() && checked.equals(false)) {
        findLastRow();
    }

    try {
        FileInputStream fis = new FileInputStream(file);
        XSSFWorkbook workbook = new XSSFWorkbook(fis);

        XSSFSheet sheet = workbook.getSheet("Movies");

        Map<String, Object[]> label = new TreeMap<>();
        label.put("1",
                new Object[] { "", parsedObj.get("Title"), parsedObj.get("Released"),
                        parsedObj.get("Metascore"), parsedObj.get("imdbRating"), parsedObj.get("Plot"),
                        parsedObj.get("imdbID"), parsedObj.get("Genre"), parsedObj.get("Director"),
                        parsedObj.get("Actors"), parsedObj.get("Rated"), parsedObj.get("Runtime") });

        Set<String> keyset = label.keySet();

        // Setting Style for the Label Row

        XSSFCellStyle contentStyle = workbook.createCellStyle();
        contentStyle.setWrapText(true);
        contentStyle.setVerticalAlignment(VerticalAlignment.TOP);

        rownum = rownum + lastRow;

        if (posterFile.exists()) {
            InputStream imageStream = new FileInputStream(
                    thumbnailPath + File.separator + parsedObj.get("Title") + ".jpg");
            byte[] imageBytes = IOUtils.toByteArray(imageStream);
            pictureureIdx = workbook.addPicture(imageBytes, Workbook.PICTURE_TYPE_PNG);
            imageStream.close();

            CreationHelper helper = workbook.getCreationHelper();
            drawing = sheet.createDrawingPatriarch();
            anchor = helper.createClientAnchor();

        }

        for (String key : keyset) {

            Row row = sheet.createRow(rownum++);
            row.setHeight((short) 2000);
            Object[] objArr = label.get(key);
            int cellnum = 0;
            for (Object obj : objArr) {
                Cell cell = row.createCell(cellnum++);
                cell.setCellStyle(contentStyle);
                cell.setCellValue((String) obj);
            }
            if (posterFile.exists()) {
                anchor.setCol1(0);
                anchor.setRow1(rownum - 1);
                anchor.setCol2(0);
                anchor.setRow2(rownum - 1);
                Picture pict = drawing.createPicture(anchor, pictureureIdx);
                pict.resize(1, 1);
            }
        }
        FileOutputStream out = new FileOutputStream(file);
        workbook.write(out);
        out.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.tikal.tallerWeb.servicio.reporte.cliente.BitacoraReporteCliente.java

License:Apache License

@Override
public BordeSeccion generar(BordeSeccion borde, ContextoSeccion contexto, ReporteCliente datos) {
    Sheet sheet = contexto.getSheet();/*www  .ja  v  a2 s.  com*/
    XSSFWorkbook wb = contexto.getWb();
    int initialRow = borde.getUpperRow();
    int initialColumn = borde.getLeftColumn();
    BordeSeccion r = new BordeSeccion();
    r.setLeftColumn(initialColumn);
    r.setUpperRow(initialRow);

    Row row = getRow(sheet, initialRow);
    Cell cell = row.createCell(initialColumn);
    cell.setCellValue("Bitacora");
    XSSFCellStyle cellStyle = wb.createCellStyle();
    addHeaderStyle(cellStyle, wb);
    addBorders(wb, cellStyle, CellStyle.BORDER_MEDIUM);
    cell.setCellStyle(cellStyle);

    for (int i = 1; i < 4; i++) {
        cell = row.createCell(initialColumn + i);
        cellStyle = wb.createCellStyle();
        addBorders(wb, cellStyle, CellStyle.BORDER_MEDIUM);
        cell.setCellStyle(cellStyle);
    }

    //merge de celdas
    sheet.addMergedRegion(new CellRangeAddress(initialRow, //first row (0-based)
            initialRow, //last row  (0-based)
            initialColumn, //first column (0-based)
            initialColumn + 3 //last column  (0-based)
    ));

    CreationHelper createHelper = wb.getCreationHelper();
    for (EventoRC x : datos.getBitacora()) {
        initialRow = initialRow + 1;
        row = getRow(sheet, initialRow);
        for (int i = 0; i < atributos.length; i++) {
            cell = row.createCell(initialColumn + i);
            cellStyle = wb.createCellStyle();
            try {
                if (atributos[i].equals("fecha")) {
                    cellStyle.setDataFormat(createHelper.createDataFormat().getFormat("yy/m/d h:mm:ss"));
                    cell.setCellValue((Date) PropertyUtils.getProperty(x, atributos[i]));
                } else {
                    cell.setCellValue(PropertyUtils.getProperty(x, atributos[i]).toString());
                }
            } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) {
                cell.setCellValue("");
            }
            addBorders(wb, cellStyle, CellStyle.BORDER_THIN);
            cell.setCellStyle(cellStyle);
        }
    }
    r.setLowerRow(initialRow);
    r.setRightColumn(initialColumn + 3);
    paintBorder(wb, sheet, CellStyle.BORDER_MEDIUM, r);
    return r;
}

From source file:de.bund.bfr.knime.openkrise.db.imports.custom.bfrnewformat.TraceGenerator.java

License:Open Source License

private int getFortraceRequests(String outputFolder, List<String> business2Trace)
        throws SQLException, IOException {
    int result = 0;
    String tracingBusinessesSQL = "";
    for (String s : business2Trace) {
        tracingBusinessesSQL += " OR " + MyDBI.delimitL("Station") + "." + MyDBI.delimitL("Betriebsart")
                + " = '" + s + "'";
    }/*  ww w .  j a  va 2 s .  com*/
    String sql = "Select * from " + MyDBI.delimitL("Lieferungen") + " LEFT JOIN " + MyDBI.delimitL("Chargen")
            + " ON " + MyDBI.delimitL("Chargen") + "." + MyDBI.delimitL("ID") + "="
            + MyDBI.delimitL("Lieferungen") + "." + MyDBI.delimitL("Charge") + " LEFT JOIN "
            + MyDBI.delimitL("Produktkatalog") + " ON " + MyDBI.delimitL("Produktkatalog") + "."
            + MyDBI.delimitL("ID") + "=" + MyDBI.delimitL("Chargen") + "." + MyDBI.delimitL("Artikel")
            + " LEFT JOIN " + MyDBI.delimitL("Station") + " ON " + MyDBI.delimitL("Station") + "."
            + MyDBI.delimitL("ID") + "=" + MyDBI.delimitL("Lieferungen") + "." + MyDBI.delimitL("Empfnger")
            + " LEFT JOIN " + MyDBI.delimitL("ChargenVerbindungen") + " ON " + MyDBI.delimitL("Lieferungen")
            + "." + MyDBI.delimitL("ID") + "=" + MyDBI.delimitL("ChargenVerbindungen") + "."
            + MyDBI.delimitL("Zutat") + " WHERE " + MyDBI.delimitL("ChargenVerbindungen") + "."
            + MyDBI.delimitL("Produkt") + " IS NULL " + " AND (" + MyDBI.delimitL("Station") + "."
            + MyDBI.delimitL("Betriebsart") + " IS NULL " + tracingBusinessesSQL + ")" + " ORDER BY "
            + MyDBI.delimitL("Station") + "." + MyDBI.delimitL("ID") + " ASC,"
            + MyDBI.delimitL("Produktkatalog") + "." + MyDBI.delimitL("Bezeichnung") + " ASC";
    //System.err.println(sql);
    ResultSet rs = DBKernel.getResultSet(sql, false);
    if (rs != null && rs.first()) {
        do {
            InputStream myxls = this.getClass().getResourceAsStream(
                    "/de/bund/bfr/knime/openkrise/db/imports/custom/bfrnewformat/BfR_Format_Fortrace_sug.xlsx");
            XSSFWorkbook workbook = new XSSFWorkbook(myxls);
            XSSFSheet sheetTracing = workbook.getSheet("FwdTracing");
            XSSFSheet sheetStations = workbook.getSheet("Stations");
            XSSFSheet sheetLookup = workbook.getSheet("LookUp");
            FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
            fillStations(sheetStations, evaluator);
            fillLookup(workbook, sheetLookup);
            LinkedHashSet<String> le = getLotExtra();
            LinkedHashSet<String> de = getDeliveryExtra();

            // Station in Focus
            XSSFRow row = sheetTracing.getRow(4);
            XSSFCell cell;
            String sid = null;
            if (rs.getObject("Lieferungen.Empfnger") != null) {
                sid = getStationLookup(rs.getString("Lieferungen.Empfnger"));
                cell = row.getCell(1);
                cell.setCellValue(sid);
                cell = row.getCell(2);
                evaluator.evaluateFormulaCell(cell);
            }

            // Ingredients for Lot(s)
            row = sheetTracing.getRow(7);
            int j = 0;
            for (String e : de) {
                if (e != null && !e.isEmpty()) {
                    cell = row.getCell(13 + j);
                    if (cell == null)
                        cell = row.createCell(13 + j);
                    cell.setCellValue(e);
                    j++;
                }
            }

            XSSFDataValidationHelper dvHelper = new XSSFDataValidationHelper(sheetTracing);
            LinkedHashSet<String> deliveryNumbers = new LinkedHashSet<>();
            int rowIndex = 9;
            row = sheetTracing.getRow(rowIndex);
            String dn = fillRow(dvHelper, sheetTracing, rs, row, evaluator, de, true, null);
            deliveryNumbers.add(dn);

            while (rs.next()) {
                if (rs.getObject("Station.Serial") == null)
                    break;
                String sl = getStationLookup(rs);
                if (!sl.equals(sid))
                    break;
                rowIndex++;
                row = copyRow(workbook, sheetTracing, 9, rowIndex);
                dn = fillRow(dvHelper, sheetTracing, rs, row, evaluator, de, true, null);
                deliveryNumbers.add(dn);
            }
            rs.previous();

            // Lot Information
            row = sheetTracing.getRow(rowIndex + 3);
            j = 0;
            for (String e : le) {
                if (e != null && !e.isEmpty()) {
                    cell = row.getCell(17 + j);
                    if (cell == null)
                        cell = row.createCell(17 + j);
                    cell.setCellValue(e);
                    j++;
                }
            }

            rowIndex += 5;
            int i = 0;
            row = sheetTracing.getRow(rowIndex);
            for (String dns : deliveryNumbers) {
                if (!dns.isEmpty()) {
                    if (i > 0)
                        row = copyRow(workbook, sheetTracing, rowIndex, rowIndex + i);
                    //todo cell = row.getCell(4); cell.setCellValue(dns);
                    insertDecCondition(dvHelper, sheetTracing, rowIndex + i, 1);
                    insertDropBox(dvHelper, sheetTracing, rowIndex + i, 2, "=Units");
                    insertDropBox(dvHelper, sheetTracing, rowIndex + i, 15, "=Treatment");
                    insertDropBox(dvHelper, sheetTracing, rowIndex + i, 16, "=Sampling");
                    i++;
                }
            }

            Name reference = workbook.createName();
            reference.setNameName("LotNumbers");
            String referenceString = sheetTracing.getSheetName() + "!$A$" + (rowIndex + 1) + ":$A$"
                    + (rowIndex + i);
            reference.setRefersToFormula(referenceString);

            // Products Out
            row = sheetTracing.getRow(rowIndex + i + 2);
            j = 0;
            for (String e : de) {
                if (e != null && !e.isEmpty()) {
                    cell = row.getCell(13 + j);
                    if (cell == null)
                        cell = row.createCell(13 + j);
                    cell.setCellValue(e);
                    j++;
                }
            }

            rowIndex += i + 4;
            for (i = 0; i < 86; i++) {
                insertCondition(dvHelper, sheetTracing, rowIndex + i, 3, "1", "31");
                insertCondition(dvHelper, sheetTracing, rowIndex + i, 4, "1", "12");
                insertCondition(dvHelper, sheetTracing, rowIndex + i, 5, "1900", "3000");
                insertCondition(dvHelper, sheetTracing, rowIndex + i, 6, "1", "31");
                insertCondition(dvHelper, sheetTracing, rowIndex + i, 7, "1", "12");
                insertCondition(dvHelper, sheetTracing, rowIndex + i, 8, "1900", "3000");
                insertDecCondition(dvHelper, sheetTracing, rowIndex + i, 9);
                insertDropBox(dvHelper, sheetTracing, rowIndex + i, 10, "=Units");
                insertDropBox(dvHelper, sheetTracing, rowIndex + i, 11, "=StationIDs");
                //row = sheetTracing.getRow(rowIndex+i);
                //cell = row.getCell(12);
                //cell.setCellFormula("INDEX(Companies,MATCH(L" + (row.getRowNum() + 1) + ",StationIDs,0),1)");
                //evaluator.evaluateFormulaCell(cell);
                insertDropBox(dvHelper, sheetTracing, rowIndex + i, 0, "=LotNumbers");
            }
            for (i = 0; i < deliveryNumbers.size(); i++) {
                insertDropBox(dvHelper, sheetTracing, 9 + i, 0, "=LotNumbers");
            }

            //System.err.println(rs.getInt("Lieferungen.ID") + "\t" + rs.getInt("Chargen.ID"));
            if (save(workbook, outputFolder + File.separator + "Fwdtrace_request_"
                    + getValidFileName(rs.getString("Station.Serial")) + ".xlsx")) { //  + "_" + getFormattedDate()
                result++;
            }
            myxls.close();
        } while (rs.next());
    }
    return result;
}

From source file:de.bund.bfr.knime.openkrise.db.imports.custom.bfrnewformat.TraceGenerator.java

License:Open Source License

private int getFwdStationRequests(String outputFolder, Station station) throws SQLException, IOException {
    int result = 0;
    String sql = "Select * from " + MyDBI.delimitL("Station") + " AS " + MyDBI.delimitL("S") + " LEFT JOIN "
            + MyDBI.delimitL("Lieferungen") + " ON " + MyDBI.delimitL("S") + "." + MyDBI.delimitL("ID") + "="
            + MyDBI.delimitL("Lieferungen") + "." + MyDBI.delimitL("Empfnger") + " LEFT JOIN "
            + MyDBI.delimitL("Chargen") + " ON " + MyDBI.delimitL("Chargen") + "." + MyDBI.delimitL("ID") + "="
            + MyDBI.delimitL("Lieferungen") + "." + MyDBI.delimitL("Charge") + " LEFT JOIN "
            + MyDBI.delimitL("Produktkatalog") + " ON " + MyDBI.delimitL("Produktkatalog") + "."
            + MyDBI.delimitL("ID") + "=" + MyDBI.delimitL("Chargen") + "." + MyDBI.delimitL("Artikel")
            + " LEFT JOIN " + MyDBI.delimitL("Station") + " ON " + MyDBI.delimitL("Station") + "."
            + MyDBI.delimitL("ID") + "=" + MyDBI.delimitL("Produktkatalog") + "." + MyDBI.delimitL("Station")
            + " LEFT JOIN " + MyDBI.delimitL("ChargenVerbindungen") + " ON "
            + MyDBI.delimitL("ChargenVerbindungen") + "." + MyDBI.delimitL("Zutat") + "="
            + MyDBI.delimitL("Lieferungen") + "." + MyDBI.delimitL("ID") + " WHERE " + MyDBI.delimitL("S") + "."
            + MyDBI.delimitL("Serial") + " = '" + station.getId() + "'" + " AND " + MyDBI.delimitL("Station")
            + "." + MyDBI.delimitL("ID") + " IS NOT NULL" + " ORDER BY " + MyDBI.delimitL("Produktkatalog")
            + "." + MyDBI.delimitL("Bezeichnung") + " ASC";
    /*/*from   w  ww  .jav  a2  s .  c  o m*/
    String sql = "Select * from " + MyDBI.delimitL("Lieferungen") +
    " LEFT JOIN " + MyDBI.delimitL("Chargen") +
    " ON " + MyDBI.delimitL("Chargen") + "." + MyDBI.delimitL("ID") + "=" + MyDBI.delimitL("Lieferungen") + "." + MyDBI.delimitL("Charge") +
    " LEFT JOIN " + MyDBI.delimitL("Produktkatalog") +
    " ON " + MyDBI.delimitL("Produktkatalog") + "." + MyDBI.delimitL("ID") + "=" + MyDBI.delimitL("Chargen") + "." + MyDBI.delimitL("Artikel") +
    " LEFT JOIN " + MyDBI.delimitL("Station") +
    " ON " + MyDBI.delimitL("Station") + "." + MyDBI.delimitL("ID") + "=" + MyDBI.delimitL("Lieferungen") + "." + MyDBI.delimitL("Empfnger") +
    " LEFT JOIN " + MyDBI.delimitL("ChargenVerbindungen") +
    " ON " + MyDBI.delimitL("Lieferungen") + "." + MyDBI.delimitL("ID") + "=" + MyDBI.delimitL("ChargenVerbindungen") + "." + MyDBI.delimitL("Zutat") +
    " WHERE " + MyDBI.delimitL("Station") + "." + MyDBI.delimitL("Serial") + " = '" + station.getId() + "'" +
    " ORDER BY " + MyDBI.delimitL("Produktkatalog") + "." + MyDBI.delimitL("Bezeichnung") + " ASC";
    */
    //System.err.println(sql);
    ResultSet rs = DBKernel.getResultSet(sql, false);
    if (rs != null && rs.first()) {
        InputStream myxls = this.getClass().getResourceAsStream(
                "/de/bund/bfr/knime/openkrise/db/imports/custom/bfrnewformat/BfR_Format_Fortrace_sug.xlsx");
        XSSFWorkbook workbook = new XSSFWorkbook(myxls);
        XSSFSheet sheetTracing = workbook.getSheet("FwdTracing");
        XSSFSheet sheetStations = workbook.getSheet("Stations");
        XSSFSheet sheetLookup = workbook.getSheet("LookUp");
        FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
        fillStations(sheetStations, evaluator);
        fillLookup(workbook, sheetLookup);
        LinkedHashSet<String> le = getLotExtra();
        LinkedHashSet<String> de = getDeliveryExtra();

        // Station in Focus
        XSSFRow row = sheetTracing.getRow(4);
        XSSFCell cell;
        String sid = station.getId();
        if (sid != null) {
            cell = row.getCell(1);
            cell.setCellValue(sid);
            cell = row.getCell(2);
            evaluator.evaluateFormulaCell(cell);
        }

        // Ingredients for Lot(s)
        row = sheetTracing.getRow(7);
        int j = 0;
        for (String e : de) {
            if (e != null && !e.isEmpty()) {
                cell = row.getCell(13 + j);
                if (cell == null)
                    cell = row.createCell(13 + j);
                cell.setCellValue(e);
                j++;
            }
        }

        XSSFDataValidationHelper dvHelper = new XSSFDataValidationHelper(sheetTracing);
        LinkedHashSet<String> deliveryNumbers = new LinkedHashSet<>();
        List<Integer> dbLots = new ArrayList<>();
        int rowIndex = 9;
        row = sheetTracing.getRow(rowIndex);
        String dn = fillRow(dvHelper, sheetTracing, rs, row, evaluator, de, true, null);
        deliveryNumbers.add(dn);
        dbLots.add(rs.getInt("ChargenVerbindungen.Produkt"));

        while (rs.next()) {
            if (rs.getObject("Station.Serial") == null)
                break;
            String sl = getStationLookup(rs);
            if (!sl.equals(sid))
                break;
            rowIndex++;
            row = copyRow(workbook, sheetTracing, 9, rowIndex);
            dn = fillRow(dvHelper, sheetTracing, rs, row, evaluator, de, true, null);
            deliveryNumbers.add(dn);
            dbLots.add(rs.getInt("ChargenVerbindungen.Produkt"));
        }

        // Lot Information
        row = sheetTracing.getRow(rowIndex + 3);
        j = 0;
        for (String e : le) {
            if (e != null && !e.isEmpty()) {
                cell = row.getCell(17 + j);
                if (cell == null)
                    cell = row.createCell(17 + j);
                cell.setCellValue(e);
                j++;
            }
        }

        rowIndex += 5;
        sql = "Select * from " + MyDBI.delimitL("Station") + " LEFT JOIN " + MyDBI.delimitL("Produktkatalog")
                + " ON " + MyDBI.delimitL("Station") + "." + MyDBI.delimitL("ID") + "="
                + MyDBI.delimitL("Produktkatalog") + "." + MyDBI.delimitL("Station") + " LEFT JOIN "
                + MyDBI.delimitL("Chargen") + " ON " + MyDBI.delimitL("Produktkatalog") + "."
                + MyDBI.delimitL("ID") + "=" + MyDBI.delimitL("Chargen") + "." + MyDBI.delimitL("Artikel")
                + " LEFT JOIN " + MyDBI.delimitL("Lieferungen") + " ON " + MyDBI.delimitL("Chargen") + "."
                + MyDBI.delimitL("ID") + "=" + MyDBI.delimitL("Lieferungen") + "." + MyDBI.delimitL("Charge")
                + " WHERE " + MyDBI.delimitL("Station") + "." + MyDBI.delimitL("Serial") + " = '"
                + station.getId() + "'" + " ORDER BY " + MyDBI.delimitL("Chargen") + "."
                + MyDBI.delimitL("ChargenNr") + " ASC";
        rs = DBKernel.getResultSet(sql, false);
        int i = 0;
        row = sheetTracing.getRow(rowIndex);
        LinkedHashMap<Integer, String> lotDb2Number = new LinkedHashMap<>();
        if (rs != null && rs.first()) {
            do {
                if (rs.getObject("Chargen.ID") != null && dbLots.contains(rs.getInt("Chargen.ID"))
                        && !lotDb2Number.containsKey(rs.getInt("Chargen.ID"))) {
                    if (i > 0)
                        row = copyRow(workbook, sheetTracing, rowIndex, rowIndex + i);
                    if (rs.getObject("Chargen.ChargenNr") != null) {
                        cell = row.getCell(0);
                        cell.setCellValue(rs.getString("Chargen.ChargenNr"));
                    }
                    if (rs.getObject("Chargen.Menge") != null) {
                        cell = row.getCell(1);
                        cell.setCellValue(rs.getDouble("Chargen.Menge"));
                    }
                    if (rs.getObject("Chargen.Einheit") != null) {
                        cell = row.getCell(2);
                        cell.setCellValue(rs.getString("Chargen.Einheit"));
                    }
                    if (rs.getObject("Produktkatalog.Bezeichnung") != null) {
                        cell = row.getCell(3);
                        cell.setCellValue(rs.getString("Produktkatalog.Bezeichnung"));
                    }

                    insertDecCondition(dvHelper, sheetTracing, rowIndex + i, 1);
                    insertDropBox(dvHelper, sheetTracing, rowIndex + i, 2, "=Units");
                    insertDropBox(dvHelper, sheetTracing, rowIndex + i, 15, "=Treatment");
                    insertDropBox(dvHelper, sheetTracing, rowIndex + i, 16, "=Sampling");
                    i++;
                    lotDb2Number.put(rs.getInt("Chargen.ID"), rs.getString("Chargen.ChargenNr"));
                }
            } while (rs.next());
        }
        if (i == 0)
            i = 1;

        Name reference = workbook.createName();
        reference.setNameName("LotNumbers");
        String referenceString = sheetTracing.getSheetName() + "!$A$" + (rowIndex + 1) + ":$A$"
                + (rowIndex + i);
        reference.setRefersToFormula(referenceString);

        for (int ii = 0; ii < dbLots.size(); ii++) {
            if (lotDb2Number.containsKey(dbLots.get(ii))) {
                row = sheetTracing.getRow(9 + ii);
                cell = row.getCell(0);
                if (cell == null)
                    cell = row.createCell(0);
                cell.setCellValue(lotDb2Number.get(dbLots.get(ii)));
            }
            insertDropBox(dvHelper, sheetTracing, 9 + ii, 0, "=LotNumbers");
        }

        // Products Out
        row = sheetTracing.getRow(rowIndex + i + 2);
        j = 0;
        for (String e : de) {
            if (e != null && !e.isEmpty()) {
                cell = row.getCell(13 + j);
                if (cell == null)
                    cell = row.createCell(13 + j);
                cell.setCellValue(e);
                j++;
            }
        }

        rowIndex += i + 4;

        if (rs != null && rs.first() && rs.getObject("Chargen.ChargenNr") != null) {
            boolean didOnce = false;
            do {
                if (didOnce)
                    row = copyRow(workbook, sheetTracing, rowIndex - 1, rowIndex);
                else
                    row = sheetTracing.getRow(rowIndex);
                fillRow(dvHelper, sheetTracing, rs, row, evaluator, de, false, null);
                rowIndex++;
                didOnce = true;
            } while (rs.next());
        }

        for (i = 0; i < 85; i++) {
            doFormats(dvHelper, sheetTracing, rowIndex + i, evaluator);
        }

        if (save(workbook, outputFolder + File.separator + "StationFwdtrace_request_"
                + getValidFileName(station.getId()) + ".xlsx")) { //  + "_" + getFormattedDate()
            result++;
        }
        myxls.close();
    }
    return result;
}

From source file:de.bund.bfr.knime.openkrise.db.imports.custom.bfrnewformat.TraceGenerator.java

License:Open Source License

private int getBackStationRequests(String outputFolder, Station station) throws SQLException, IOException {
    int result = 0;
    String sql = "Select * from " + MyDBI.delimitL("Station") + " LEFT JOIN " + MyDBI.delimitL("Produktkatalog")
            + " ON " + MyDBI.delimitL("Station") + "." + MyDBI.delimitL("ID") + "="
            + MyDBI.delimitL("Produktkatalog") + "." + MyDBI.delimitL("Station") + " LEFT JOIN "
            + MyDBI.delimitL("Chargen") + " ON " + MyDBI.delimitL("Produktkatalog") + "." + MyDBI.delimitL("ID")
            + "=" + MyDBI.delimitL("Chargen") + "." + MyDBI.delimitL("Artikel") + " LEFT JOIN "
            + MyDBI.delimitL("Lieferungen") + " ON " + MyDBI.delimitL("Chargen") + "." + MyDBI.delimitL("ID")
            + "=" + MyDBI.delimitL("Lieferungen") + "." + MyDBI.delimitL("Charge") + " WHERE "
            + MyDBI.delimitL("Station") + "." + MyDBI.delimitL("Serial") + " = '" + station.getId() + "'"
            + " ORDER BY " + MyDBI.delimitL("Chargen") + "." + MyDBI.delimitL("ChargenNr") + " ASC";
    //System.err.println(sql);
    ResultSet rs = DBKernel.getResultSet(sql, false);
    if (rs != null && rs.first()) {
        InputStream myxls = this.getClass().getResourceAsStream(
                "/de/bund/bfr/knime/openkrise/db/imports/custom/bfrnewformat/BfR_Format_Backtrace_sug.xlsx");
        XSSFWorkbook workbook = new XSSFWorkbook(myxls);
        XSSFSheet sheetTracing = workbook.getSheet("BackTracing");
        XSSFSheet sheetStations = workbook.getSheet("Stations");
        XSSFSheet sheetLookup = workbook.getSheet("LookUp");
        FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
        fillStations(sheetStations, evaluator);
        fillLookup(workbook, sheetLookup);
        LinkedHashSet<String> le = getLotExtra();
        LinkedHashSet<String> de = getDeliveryExtra();

        // Station in Focus
        XSSFRow row = sheetTracing.getRow(4);
        XSSFCell cell;/* w  ww .  jav  a2  s.c  om*/
        String sid = null;
        if (rs.getObject("Station.Serial") != null) {
            sid = getStationLookup(rs);
            cell = row.getCell(1);
            cell.setCellValue(sid);
            cell = row.getCell(2);
            evaluator.evaluateFormulaCell(cell);
        }

        // Products Out
        row = sheetTracing.getRow(7);
        int j = 0;
        for (String e : de) {
            if (e != null && !e.isEmpty()) {
                cell = row.getCell(13 + j);
                if (cell == null)
                    cell = row.createCell(13 + j);
                cell.setCellValue(e);
                j++;
            }
        }

        XSSFDataValidationHelper dvHelper = new XSSFDataValidationHelper(sheetTracing);
        LinkedHashMap<String, Lot> lotNumbers = new LinkedHashMap<>();
        LinkedHashMap<Integer, String> lotDb2Number = new LinkedHashMap<>();
        int rowIndex = 9;
        row = sheetTracing.getRow(rowIndex);
        String ln = fillRow(dvHelper, sheetTracing, rs, row, evaluator, de, false, null);
        if (!lotNumbers.containsKey(ln)) {
            Lot l = new Lot();
            l.setNumber(ln);
            if (rs.getObject("Chargen.Menge") != null)
                l.setUnitNumber(rs.getDouble("Chargen.Menge"));
            if (rs.getObject("Chargen.Einheit") != null)
                l.setUnitUnit(rs.getString("Chargen.Einheit"));
            if (rs.getObject("Produktkatalog.Bezeichnung") != null) {
                Product p = new Product();
                p.setName(rs.getString("Produktkatalog.Bezeichnung"));
                l.setProduct(p);
            }
            l.setDbId(rs.getInt("Chargen.ID"));
            lotNumbers.put(ln, l);
        }
        lotDb2Number.put(rs.getInt("Chargen.ID"), ln);

        while (rs.next()) {
            if (rs.getObject("Station.Serial") == null)
                break;
            String sl = getStationLookup(rs);
            if (!sl.equals(sid))
                break;
            rowIndex++;
            row = copyRow(workbook, sheetTracing, 9, rowIndex);
            ln = fillRow(dvHelper, sheetTracing, rs, row, evaluator, de, false, null);
            if (!lotNumbers.containsKey(ln)) {
                Lot l = new Lot();
                l.setNumber(ln);
                if (rs.getObject("Chargen.Menge") != null)
                    l.setUnitNumber(rs.getDouble("Chargen.Menge"));
                if (rs.getObject("Chargen.Einheit") != null)
                    l.setUnitUnit(rs.getString("Chargen.Einheit"));
                if (rs.getObject("Produktkatalog.Bezeichnung") != null) {
                    Product p = new Product();
                    p.setName(rs.getString("Produktkatalog.Bezeichnung"));
                    l.setProduct(p);
                }
                l.setDbId(rs.getInt("Chargen.ID"));
                lotNumbers.put(ln, l);
            }
            lotDb2Number.put(rs.getInt("Chargen.ID"), ln);
        }
        rs.previous();

        // Lot Information
        row = sheetTracing.getRow(rowIndex + 3);
        j = 0;
        for (String e : le) {
            if (e != null && !e.isEmpty()) {
                cell = row.getCell(17 + j);
                if (cell == null)
                    cell = row.createCell(17 + j);
                cell.setCellValue(e);
                j++;
            }
        }

        rowIndex += 5;
        int i = 0;
        row = sheetTracing.getRow(rowIndex);
        for (Lot lot : lotNumbers.values()) {
            if (lot != null && !lot.getNumber().isEmpty()) {
                if (i > 0)
                    row = copyRow(workbook, sheetTracing, rowIndex, rowIndex + i);
                cell = row.getCell(0);
                cell.setCellValue(lot.getNumber());
                if (lot.getUnitNumber() != null) {
                    cell = row.getCell(1);
                    cell.setCellValue(lot.getUnitNumber());
                }
                if (lot.getUnitUnit() != null) {
                    cell = row.getCell(2);
                    cell.setCellValue(lot.getUnitUnit());
                }
                if (lot.getProduct() != null && lot.getProduct().getName() != null) {
                    cell = row.getCell(3);
                    cell.setCellValue(lot.getProduct().getName());
                }
                LinkedHashSet<String> le0 = new LinkedHashSet<>();
                le0.add("Production Date");
                le0.add("Best before date");
                le0.add("Treatment of product during production");
                le0.add("Sampling");
                le0.addAll(le);
                fillExtraFields("Chargen", lot.getDbId(), row, le0, 13);
                insertDecCondition(dvHelper, sheetTracing, rowIndex + i, 1);
                insertDropBox(dvHelper, sheetTracing, rowIndex + i, 2, "=Units");
                insertDropBox(dvHelper, sheetTracing, rowIndex + i, 15, "=Treatment");
                insertDropBox(dvHelper, sheetTracing, rowIndex + i, 16, "=Sampling");
                i++;
            }
        }

        Name reference = workbook.createName();
        reference.setNameName("LotNumbers");
        String referenceString = sheetTracing.getSheetName() + "!$A$" + (rowIndex + 1) + ":$A$"
                + (rowIndex + i);
        reference.setRefersToFormula(referenceString);

        String sif = getValidFileName(rs.getString("Station.Serial")); //  + "_" + getFormattedDate()

        // Ingredients for Lot(s)
        row = sheetTracing.getRow(rowIndex + i + 2);
        j = 0;
        for (String e : de) {
            if (e != null && !e.isEmpty()) {
                cell = row.getCell(13 + j);
                if (cell == null)
                    cell = row.createCell(13 + j);
                cell.setCellValue(e);
                j++;
            }
        }
        rowIndex += i + 4;

        sql = "Select * from " + MyDBI.delimitL("Station") + " AS " + MyDBI.delimitL("S") + " LEFT JOIN "
                + MyDBI.delimitL("Lieferungen") + " ON " + MyDBI.delimitL("S") + "." + MyDBI.delimitL("ID")
                + "=" + MyDBI.delimitL("Lieferungen") + "." + MyDBI.delimitL("Empfnger") + " LEFT JOIN "
                + MyDBI.delimitL("Chargen") + " ON " + MyDBI.delimitL("Chargen") + "." + MyDBI.delimitL("ID")
                + "=" + MyDBI.delimitL("Lieferungen") + "." + MyDBI.delimitL("Charge") + " LEFT JOIN "
                + MyDBI.delimitL("Produktkatalog") + " ON " + MyDBI.delimitL("Produktkatalog") + "."
                + MyDBI.delimitL("ID") + "=" + MyDBI.delimitL("Chargen") + "." + MyDBI.delimitL("Artikel")
                + " LEFT JOIN " + MyDBI.delimitL("Station") + " ON " + MyDBI.delimitL("Station") + "."
                + MyDBI.delimitL("ID") + "=" + MyDBI.delimitL("Produktkatalog") + "."
                + MyDBI.delimitL("Station") + " LEFT JOIN " + MyDBI.delimitL("ChargenVerbindungen") + " ON "
                + MyDBI.delimitL("ChargenVerbindungen") + "." + MyDBI.delimitL("Zutat") + "="
                + MyDBI.delimitL("Lieferungen") + "." + MyDBI.delimitL("ID") + " WHERE " + MyDBI.delimitL("S")
                + "." + MyDBI.delimitL("Serial") + " = '" + station.getId() + "'" + " AND "
                + MyDBI.delimitL("Station") + "." + MyDBI.delimitL("ID") + " IS NOT NULL" + " ORDER BY "
                + MyDBI.delimitL("Produktkatalog") + "." + MyDBI.delimitL("Bezeichnung") + " ASC";
        //System.out.println(sql);
        rs = DBKernel.getResultSet(sql, false);
        if (rs != null && rs.first()) {
            LinkedHashSet<String> deliveryNumbers = new LinkedHashSet<>();
            row = sheetTracing.getRow(rowIndex);
            String dn = fillRow(dvHelper, sheetTracing, rs, row, evaluator, de, null, lotDb2Number);
            doFormats(dvHelper, sheetTracing, rowIndex, evaluator);
            deliveryNumbers.add(dn);

            boolean didOnce = false;
            while (rs.next()) {
                if (rs.getObject("Station.Serial") == null)
                    break;
                String sl = getStationLookup(rs);
                if (!sl.equals(sid))
                    break;
                rowIndex++;
                if (didOnce)
                    row = copyRow(workbook, sheetTracing, rowIndex - 1, rowIndex);
                else
                    row = sheetTracing.getRow(rowIndex);
                dn = fillRow(dvHelper, sheetTracing, rs, row, evaluator, de, null, lotDb2Number);
                doFormats(dvHelper, sheetTracing, rowIndex, evaluator);
                deliveryNumbers.add(dn);
                didOnce = true;
            }
            rowIndex++;
        }
        for (i = 0; i < 84; i++) {
            doFormats(dvHelper, sheetTracing, rowIndex + i, evaluator);
        }

        //System.err.println(rs.getInt("Lieferungen.ID") + "\t" + rs.getInt("Chargen.ID"));
        if (save(workbook, outputFolder + File.separator + "StationBacktrace_request_" + sif + ".xlsx")) {
            result++;
        }
        myxls.close();
    }
    return result;
}

From source file:de.bund.bfr.knime.openkrise.db.imports.custom.bfrnewformat.TraceGenerator.java

License:Open Source License

private int getBacktraceRequests(String outputFolder, List<String> business2Backtrace)
        throws SQLException, IOException {
    int result = 0;
    String sql;//w  w w  .  j  a  v  a 2  s. c o m
    String backtracingBusinessesSQL = "";
    for (String s : business2Backtrace) {
        backtracingBusinessesSQL += " OR " + MyDBI.delimitL("Station") + "." + MyDBI.delimitL("Betriebsart")
                + " = '" + s + "'";
    }
    sql = "Select * from " + MyDBI.delimitL("Lieferungen") + " LEFT JOIN " + MyDBI.delimitL("Chargen") + " ON "
            + MyDBI.delimitL("Chargen") + "." + MyDBI.delimitL("ID") + "=" + MyDBI.delimitL("Lieferungen") + "."
            + MyDBI.delimitL("Charge") + " LEFT JOIN " + MyDBI.delimitL("ChargenVerbindungen") + " ON "
            + MyDBI.delimitL("Chargen") + "." + MyDBI.delimitL("ID") + "="
            + MyDBI.delimitL("ChargenVerbindungen") + "." + MyDBI.delimitL("Produkt") + " LEFT JOIN "
            + MyDBI.delimitL("Produktkatalog") + " ON " + MyDBI.delimitL("Produktkatalog") + "."
            + MyDBI.delimitL("ID") + "=" + MyDBI.delimitL("Chargen") + "." + MyDBI.delimitL("Artikel")
            + " LEFT JOIN " + MyDBI.delimitL("Station") + " ON " + MyDBI.delimitL("Station") + "."
            + MyDBI.delimitL("ID") + "=" + MyDBI.delimitL("Produktkatalog") + "." + MyDBI.delimitL("Station")
            + " WHERE " + MyDBI.delimitL("ChargenVerbindungen") + "." + MyDBI.delimitL("Zutat") + " IS NULL "
            + " AND (" + MyDBI.delimitL("Station") + "." + MyDBI.delimitL("Betriebsart") + " IS NULL "
            + backtracingBusinessesSQL + ")" + " ORDER BY " + MyDBI.delimitL("Station") + "."
            + MyDBI.delimitL("ID") + " ASC," + MyDBI.delimitL("Chargen") + "." + MyDBI.delimitL("ChargenNr")
            + " ASC";
    //System.err.println(sql);
    ResultSet rs = DBKernel.getResultSet(sql, false);
    if (rs != null && rs.first()) {
        do {
            InputStream myxls = this.getClass().getResourceAsStream(
                    "/de/bund/bfr/knime/openkrise/db/imports/custom/bfrnewformat/BfR_Format_Backtrace_sug.xlsx");
            XSSFWorkbook workbook = new XSSFWorkbook(myxls);
            XSSFSheet sheetTracing = workbook.getSheet("BackTracing");
            XSSFSheet sheetStations = workbook.getSheet("Stations");
            XSSFSheet sheetLookup = workbook.getSheet("LookUp");
            FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
            fillStations(sheetStations, evaluator);
            fillLookup(workbook, sheetLookup);
            LinkedHashSet<String> le = getLotExtra();
            LinkedHashSet<String> de = getDeliveryExtra();

            // Station in Focus
            XSSFRow row = sheetTracing.getRow(4);
            XSSFCell cell;
            String sid = null;
            if (rs.getObject("Station.Serial") != null) {
                sid = getStationLookup(rs);
                cell = row.getCell(1);
                cell.setCellValue(sid);
                cell = row.getCell(2);
                evaluator.evaluateFormulaCell(cell);
            }

            // Products Out
            row = sheetTracing.getRow(7);
            int j = 0;
            for (String e : de) {
                if (e != null && !e.isEmpty()) {
                    cell = row.getCell(13 + j);
                    if (cell == null)
                        cell = row.createCell(13 + j);
                    cell.setCellValue(e);
                    j++;
                }
            }

            XSSFDataValidationHelper dvHelper = new XSSFDataValidationHelper(sheetTracing);
            LinkedHashMap<String, Lot> lotNumbers = new LinkedHashMap<>();
            int rowIndex = 9;
            row = sheetTracing.getRow(rowIndex);
            String ln = fillRow(dvHelper, sheetTracing, rs, row, evaluator, de, false, null);
            if (!lotNumbers.containsKey(ln)) {
                Lot l = new Lot();
                l.setNumber(ln);
                if (rs.getObject("Chargen.Menge") != null)
                    l.setUnitNumber(rs.getDouble("Chargen.Menge"));
                if (rs.getObject("Chargen.Einheit") != null)
                    l.setUnitUnit(rs.getString("Chargen.Einheit"));
                if (rs.getObject("Produktkatalog.Bezeichnung") != null) {
                    Product p = new Product();
                    p.setName(rs.getString("Produktkatalog.Bezeichnung"));
                    l.setProduct(p);
                }
                l.setDbId(rs.getInt("Chargen.ID"));
                lotNumbers.put(ln, l);
            }

            while (rs.next()) {
                if (rs.getObject("Station.Serial") == null)
                    break;
                String sl = getStationLookup(rs);
                if (!sl.equals(sid))
                    break;
                rowIndex++;
                row = copyRow(workbook, sheetTracing, 9, rowIndex);
                ln = fillRow(dvHelper, sheetTracing, rs, row, evaluator, de, false, null);
                if (!lotNumbers.containsKey(ln)) {
                    Lot l = new Lot();
                    l.setNumber(ln);
                    if (rs.getObject("Chargen.Menge") != null)
                        l.setUnitNumber(rs.getDouble("Chargen.Menge"));
                    if (rs.getObject("Chargen.Einheit") != null)
                        l.setUnitUnit(rs.getString("Chargen.Einheit"));
                    if (rs.getObject("Produktkatalog.Bezeichnung") != null) {
                        Product p = new Product();
                        p.setName(rs.getString("Produktkatalog.Bezeichnung"));
                        l.setProduct(p);
                    }
                    l.setDbId(rs.getInt("Chargen.ID"));
                    lotNumbers.put(ln, l);
                }
            }
            rs.previous();

            // Lot Information
            row = sheetTracing.getRow(rowIndex + 3);
            j = 0;
            for (String e : le) {
                if (e != null && !e.isEmpty()) {
                    cell = row.getCell(17 + j);
                    if (cell == null)
                        cell = row.createCell(17 + j);
                    cell.setCellValue(e);
                    j++;
                }
            }

            rowIndex += 5;
            int i = 0;
            row = sheetTracing.getRow(rowIndex);
            for (Lot lot : lotNumbers.values()) {
                if (lot != null && !lot.getNumber().isEmpty()) {
                    if (i > 0)
                        row = copyRow(workbook, sheetTracing, rowIndex, rowIndex + i);
                    cell = row.getCell(0);
                    cell.setCellValue(lot.getNumber());
                    if (lot.getUnitNumber() != null) {
                        cell = row.getCell(1);
                        cell.setCellValue(lot.getUnitNumber());
                    }
                    if (lot.getUnitUnit() != null) {
                        cell = row.getCell(2);
                        cell.setCellValue(lot.getUnitUnit());
                    }
                    if (lot.getProduct() != null && lot.getProduct().getName() != null) {
                        cell = row.getCell(3);
                        cell.setCellValue(lot.getProduct().getName());
                    }
                    LinkedHashSet<String> le0 = new LinkedHashSet<>();
                    le0.add("Production Date");
                    le0.add("Best before date");
                    le0.add("Treatment of product during production");
                    le0.add("Sampling");
                    le0.addAll(le);
                    fillExtraFields("Chargen", lot.getDbId(), row, le0, 13);
                    insertDecCondition(dvHelper, sheetTracing, rowIndex + i, 1);
                    insertDropBox(dvHelper, sheetTracing, rowIndex + i, 2, "=Units");
                    insertDropBox(dvHelper, sheetTracing, rowIndex + i, 15, "=Treatment");
                    insertDropBox(dvHelper, sheetTracing, rowIndex + i, 16, "=Sampling");
                    i++;
                }
            }

            Name reference = workbook.createName();
            reference.setNameName("LotNumbers");
            String referenceString = sheetTracing.getSheetName() + "!$A$" + (rowIndex + 1) + ":$A$"
                    + (rowIndex + i);
            reference.setRefersToFormula(referenceString);

            // Ingredients for Lot(s)
            row = sheetTracing.getRow(rowIndex + i + 2);
            j = 0;
            for (String e : de) {
                if (e != null && !e.isEmpty()) {
                    cell = row.getCell(13 + j);
                    if (cell == null)
                        cell = row.createCell(13 + j);
                    cell.setCellValue(e);
                    j++;
                }
            }

            rowIndex += i + 4;
            for (i = 0; i < 86; i++) {
                insertCondition(dvHelper, sheetTracing, rowIndex + i, 3, "1", "31");
                insertCondition(dvHelper, sheetTracing, rowIndex + i, 4, "1", "12");
                insertCondition(dvHelper, sheetTracing, rowIndex + i, 5, "1900", "3000");
                insertCondition(dvHelper, sheetTracing, rowIndex + i, 6, "1", "31");
                insertCondition(dvHelper, sheetTracing, rowIndex + i, 7, "1", "12");
                insertCondition(dvHelper, sheetTracing, rowIndex + i, 8, "1900", "3000");
                insertDecCondition(dvHelper, sheetTracing, rowIndex + i, 9);
                insertDropBox(dvHelper, sheetTracing, rowIndex + i, 10, "=Units");
                insertDropBox(dvHelper, sheetTracing, rowIndex + i, 11, "=StationIDs");
                //row = sheetTracing.getRow(rowIndex+i);
                //cell = row.getCell(12);
                //cell.setCellFormula("INDEX(Companies,MATCH(L" + (row.getRowNum() + 1) + ",StationIDs,0),1)");
                //evaluator.evaluateFormulaCell(cell);
                insertDropBox(dvHelper, sheetTracing, rowIndex + i, 0, "=LotNumbers");
            }

            //System.err.println(rs.getInt("Lieferungen.ID") + "\t" + rs.getInt("Chargen.ID"));
            if (save(workbook, outputFolder + File.separator + "Backtrace_request_"
                    + getValidFileName(rs.getString("Station.Serial")) + ".xlsx")) { //  + "_" + getFormattedDate()
                result++;
            }
            myxls.close();
        } while (rs.next());
    }
    return result;
}

From source file:de.escnet.ExcelTable.java

License:Open Source License

public ExcelTable(String excel, String sheetName) throws IOException {
    XSSFWorkbook wb = new XSSFWorkbook(excel);
    evaluator = wb.getCreationHelper().createFormulaEvaluator();
    theme = wb.getTheme();//from  w w  w .  j  a va 2 s . c  o  m
    sheet = sheetName == null ? wb.getSheetAt(0) : wb.getSheet(sheetName);

    for (Iterator rowIt = sheet.rowIterator(); rowIt.hasNext();) {
        Row row = (Row) rowIt.next();
        for (Iterator cellIt = row.cellIterator(); cellIt.hasNext();) {
            XSSFCell cell = (XSSFCell) cellIt.next();

            int rowIndex = cell.getRowIndex();
            rowMin = Math.min(rowMin, rowIndex);
            rowMax = Math.max(rowMax, rowIndex);

            int colIndex = cell.getColumnIndex();
            colMin = Math.min(colMin, colIndex);
            colMax = Math.max(colMax, colIndex);
        }
    }
}