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

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

Introduction

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

Prototype

Drawing<?> createDrawingPatriarch();

Source Link

Document

Creates the top-level drawing patriarch.

Usage

From source file:poi.xssf.usermodel.examples.WorkingWithPictures.java

License:Apache License

public static void main(String[] args) throws IOException {

    //create a new workbook
    Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
    CreationHelper helper = wb.getCreationHelper();

    //add a picture in this workbook.
    InputStream is = new FileInputStream(args[0]);
    byte[] bytes = IOUtils.toByteArray(is);
    is.close();//from  ww  w  .  j  a v  a 2 s . c  o  m
    int pictureIdx = wb.addPicture(bytes, Workbook.PICTURE_TYPE_JPEG);

    //create sheet
    Sheet sheet = wb.createSheet();

    //create drawing
    Drawing drawing = sheet.createDrawingPatriarch();

    //add a picture shape
    ClientAnchor anchor = helper.createClientAnchor();
    anchor.setCol1(1);
    anchor.setRow1(1);
    Picture pict = drawing.createPicture(anchor, pictureIdx);

    //auto-size picture
    pict.resize(2);

    //save workbook
    String file = "picture.xls";
    if (wb instanceof XSSFWorkbook)
        file += "x";
    FileOutputStream fileOut = new FileOutputStream(file);
    wb.write(fileOut);
    fileOut.close();
}

From source file:rpt.GUI.ProgramStrategist.CyclePlans.CompareDialogController.java

private int writeRow(Workbook wb, Sheet sheet, Row row, TableVariant variant,
        Map<String, Map<String, String>> diffList, Boolean colorChanges, Boolean addOldSOP) {
    //Used for placing comment at the right position
    CreationHelper factory = wb.getCreationHelper();
    Drawing drawing = sheet.createDrawingPatriarch();
    ClientAnchor anchor = factory.createClientAnchor();

    //Create new style
    XSSFCellStyle styleRed = (XSSFCellStyle) wb.createCellStyle();
    XSSFCellStyle styleBlack = (XSSFCellStyle) wb.createCellStyle();
    XSSFFont fontRed = (XSSFFont) wb.createFont();
    fontRed.setColor(new XSSFColor(new java.awt.Color(255, 0, 0)));
    XSSFFont fontBlack = (XSSFFont) wb.createFont();
    fontBlack.setColor(new XSSFColor(new java.awt.Color(0, 0, 0)));
    styleRed.setFont(fontRed);// w  w w .  j  a v a  2s  .  com
    styleBlack.setFont(fontBlack);

    //xEtract differences to highlight
    Map<String, String> differences;

    if (diffList != null) {
        differences = diffList.get(variant.getVariantID());
    } else {
        differences = new HashMap<String, String>();
    }

    //Start with column 0
    int cols = 0;

    //Create string with columns to print
    String[] columns = { "Plant", "Platform", "Vehicle", "Propulsion", "Denomination", "Fuel", "EngineFamily",
            "Generation", "EngineCode", "Displacement", "EnginePower", "ElMotorPower", "Torque",
            "TorqueOverBoost", "GearboxType", "Gears", "Gearbox", "Driveline", "TransmissionCode", "CertGroup",
            "EmissionClass", "StartOfProd", "EndOfProd" };

    Cell cell;

    for (int i = 0; i < columns.length; i++) {
        cell = row.createCell(i);

        if (differences.containsKey(columns[i])) {
            cell.setCellStyle(styleRed);

            // position the comment
            anchor.setCol1(cell.getColumnIndex());
            anchor.setCol2(cell.getColumnIndex() + 1);
            anchor.setRow1(row.getRowNum());
            anchor.setRow2(row.getRowNum() + 3);

            // Create the comment and set the text+author
            Comment comment = drawing.createCellComment(anchor);
            RichTextString str = factory.createRichTextString(differences.get(columns[i]));
            comment.setString(str);
            comment.setAuthor("RPT");

            // Assign the comment to the cell
            cell.setCellComment(comment);
        } else {
            cell.setCellStyle(styleBlack);
        }
        cell.setCellValue(variant.getValue(columns[i]));
        cols++;
    }

    if (addOldSOP) {
        cell = row.createCell(23);
        cell.setCellValue(variant.getOldSOP());
        cols++;
    }

    if (addOldSOP) {
        cell = row.createCell(24);
        cell.setCellValue(variant.getOldEOP());
        cols++;
    }

    return cols;
}

From source file:searchPatternClassifierPackage.ScatterChart.java

License:Apache License

public static void exampeScatterChart() {
    Workbook wb = new XSSFWorkbook();
    Sheet sheet = wb.createSheet("Sheet 1");
    final int NUM_OF_ROWS = 3;
    final int NUM_OF_COLUMNS = 10;

    // Create a row and put some cells in it. Rows are 0 based.
    Row row;/*from   ww w .  ja v  a2 s .c om*/
    Cell cell;
    for (int rowIndex = 0; rowIndex < NUM_OF_ROWS; rowIndex++) {
        row = sheet.createRow((short) rowIndex);
        for (int colIndex = 0; colIndex < NUM_OF_COLUMNS; colIndex++) {
            cell = row.createCell((short) colIndex);
            cell.setCellValue(colIndex * (rowIndex + 1));
        }
    }

    Drawing drawing = sheet.createDrawingPatriarch();
    ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, 5, 10, 15);

    Chart chart = drawing.createChart(anchor);
    ChartLegend legend = chart.getOrCreateLegend();
    legend.setPosition(LegendPosition.TOP_RIGHT);

    ScatterChartData data = chart.getChartDataFactory().createScatterChartData();

    ValueAxis bottomAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.BOTTOM);
    ValueAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);
    leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);

    ChartDataSource<Number> xs = DataSources.fromNumericCellRange(sheet,
            new CellRangeAddress(0, 0, 0, NUM_OF_COLUMNS - 1));
    ChartDataSource<Number> ys1 = DataSources.fromNumericCellRange(sheet,
            new CellRangeAddress(1, 1, 0, NUM_OF_COLUMNS - 1));
    ChartDataSource<Number> ys2 = DataSources.fromNumericCellRange(sheet,
            new CellRangeAddress(2, 2, 0, NUM_OF_COLUMNS - 1));

    data.addSerie(xs, ys1);
    data.addSerie(xs, ys2);

    chart.plot(data, bottomAxis, leftAxis);

    try {
        // Write the output to a file
        FileOutputStream fileOut = new FileOutputStream("ooxml-scatter-chart.xlsx");
        wb.write(fileOut);
        fileOut.close();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:sistemas.Utils.java

public static void chartExcel(ArrayList<Object> actuales, ArrayList<Object> futuros, String path)
        throws Exception {
    Workbook wb = new XSSFWorkbook();
    Sheet sheet = wb.createSheet("linechart");
    final int NUM_OF_ROWS = 30;
    final int NUM_OF_COLUMNS = 5;

    // Create a row and put some cells in it. Rows are 0 based.
    Row row;//from  www.  j ava  2  s. c om
    Cell cell;
    for (int i = 0; i < 15; i++) {
        row = sheet.createRow((short) i);
        cell = row.createCell((short) 0);
        cell.setCellValue(i + 1);
        cell = row.createCell((short) 1);
        if (actuales.get(i) instanceof Integer)
            cell.setCellValue((Integer) actuales.get(i));
        else
            cell.setCellValue((Double) actuales.get(i));
        cell = row.createCell((short) 3);
        cell.setCellValue(i + 1);
        cell = row.createCell((short) 4);
        cell.setCellValue((Double) futuros.get(i));
    }
    for (int i = 15; i < 30; i++) {
        row = sheet.createRow((short) i);
        cell = row.createCell(3);
        cell.setCellValue(i + 1);
        cell = row.createCell(4);
        cell.setCellValue((Double) futuros.get(i));
    }

    Drawing drawing = sheet.createDrawingPatriarch();
    ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, 35, 10, 45);

    Chart chart = drawing.createChart(anchor);
    ChartLegend legend = chart.getOrCreateLegend();
    legend.setPosition(LegendPosition.TOP_RIGHT);

    LineChartData data = chart.getChartDataFactory().createLineChartData();

    // Use a category axis for the bottom axis.
    ChartAxis bottomAxis = chart.getChartAxisFactory().createCategoryAxis(AxisPosition.BOTTOM);
    ValueAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);
    leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);

    ChartDataSource<Number> xs = DataSources.fromNumericCellRange(sheet, new CellRangeAddress(0, 29, 3, 3));
    ChartDataSource<Number> ys1 = DataSources.fromNumericCellRange(sheet, new CellRangeAddress(0, 29, 1, 1));
    ChartDataSource<Number> ys2 = DataSources.fromNumericCellRange(sheet, new CellRangeAddress(0, 29, 4, 4));

    data.addSeries(xs, ys1);
    data.addSeries(xs, ys2);

    chart.plot(data, bottomAxis, leftAxis);

    // Write the output to a file
    FileOutputStream fileOut = new FileOutputStream(path);
    wb.write(fileOut);
    fileOut.close();
}

From source file:utilities.XLSResultsManager.java

License:Open Source License

private void closeRecord(ArrayList<CellItem> record, Sheet sheet, Map<String, CellStyle> styles,
        boolean embedImages) throws IOException {

    CreationHelper createHelper = wb.getCreationHelper();

    Row row = sheet.createRow(rowIndex++);
    if (embedImages) {
        row.setHeight((short) 1000);
    }//  ww  w.  j  ava2  s  .c om

    for (int i = 0; i < record.size(); i++) {
        CellItem ci = record.get(i);

        Cell cell = row.createCell(i);

        if (ci.v != null && (ci.v.startsWith("https://") || ci.v.startsWith("http://"))) {

            if (embedImages) {
                if (ci.v.endsWith(".jpg") || ci.v.endsWith(".png")) {
                    int idx = ci.v.indexOf("attachments");
                    int idxName = ci.v.lastIndexOf('/');
                    if (idx > 0 && idxName > 0) {
                        String fileName = ci.v.substring(idxName);
                        String stem = basePath + "/" + ci.v.substring(idx, idxName);
                        String imageName = stem + "/thumbs" + fileName + ".jpg";
                        try {
                            InputStream inputStream = new FileInputStream(imageName);
                            byte[] imageBytes = IOUtils.toByteArray(inputStream);
                            int pictureureIdx = wb.addPicture(imageBytes, Workbook.PICTURE_TYPE_JPEG);
                            inputStream.close();

                            ClientAnchor anchor = createHelper.createClientAnchor();
                            anchor.setCol1(i);
                            anchor.setRow1(rowIndex - 1);
                            anchor.setCol2(i + 1);
                            anchor.setRow2(rowIndex);
                            anchor.setAnchorType(ClientAnchor.MOVE_AND_RESIZE);
                            //sheet.setColumnWidth(i, 20 * 256);
                            Drawing drawing = sheet.createDrawingPatriarch();
                            Picture pict = drawing.createPicture(anchor, pictureureIdx);
                            //pict.resize();
                        } catch (Exception e) {
                            log.info("Error: Missing image file: " + imageName);
                        }
                    }
                }
            }

            cell.setCellStyle(styles.get("link"));
            if (isXLSX) {
                XSSFHyperlink url = (XSSFHyperlink) createHelper.createHyperlink(Hyperlink.LINK_URL);
                url.setAddress(ci.v);
                cell.setHyperlink(url);
            } else {
                HSSFHyperlink url = new HSSFHyperlink(HSSFHyperlink.LINK_URL);
                url.setAddress(ci.v);
                cell.setHyperlink(url);
            }

            cell.setCellValue(ci.v);

        } else {

            /*
             * Write the value as double or string
             */
            boolean cellWritten = false;

            if (ci.type == CellItem.DECIMAL || ci.type == CellItem.INTEGER && ci.v != null) {
                try {
                    double vDouble = Double.parseDouble(ci.v);

                    cell.setCellStyle(styles.get("default"));
                    cell.setCellValue(vDouble);
                    cellWritten = true;
                } catch (Exception e) {
                    // Ignore
                }
            } else if (ci.type == CellItem.DATETIME) {
                DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                try {
                    java.util.Date date = dateFormat.parse(ci.v);
                    cell.setCellStyle(styles.get("datetime"));
                    cell.setCellValue(date);
                    cellWritten = true;
                } catch (Exception e) {
                    // Ignore
                }
            } else if (ci.type == CellItem.DATE) {
                DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                try {
                    java.util.Date date = dateFormat.parse(ci.v);
                    cell.setCellStyle(styles.get("date"));
                    cell.setCellValue(date);
                    cellWritten = true;
                } catch (Exception e) {
                    // Ignore
                }
            }

            if (!cellWritten) {
                cell.setCellStyle(styles.get("default"));
                cell.setCellValue(ci.v);
            }
        }
    }
}

From source file:Valuacion.Exporta.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    if(t_orden.getText().compareTo("")!=0)
    {// w  w w  .j a v a2 s.c  om
        FileNameExtensionFilter filtroImagen=new FileNameExtensionFilter("XLS","xls");
        aviso.setFileFilter(filtroImagen);
        int r=aviso.showSaveDialog(null);
        if(r==aviso.APPROVE_OPTION)
        {
            boolean respuesta=true;
            File a=aviso.getSelectedFile();
            File archivoXLS=null;
            if(a.exists()==true)
            {
                int i=JOptionPane.showConfirmDialog(null, "Deseas remplazar el archivo?", "confirmacin", JOptionPane.YES_NO_OPTION);
                if(i!=0)
                {
                    respuesta=false;
                }
                else
                    archivoXLS=a;
            }
            else
            {
                if(a.getName().indexOf(".xls")==-1)
                    a= new File(a.getAbsoluteFile()+".xls");
                archivoXLS=a;
            }
            if(respuesta==true)
            {
                Session session = HibernateUtil.getSessionFactory().openSession();
                try
                {
                    orden_act = (Orden)session.get(Orden.class, orden_act.getIdOrden());
                    //if(orden_act.getPedidos().isEmpty()==true)
                    //{
                        //File archivoXLS = new File(t_orden.getText()+".xls");
                        if(archivoXLS.exists())
                            archivoXLS.delete();
                        Biff8EncryptionKey.setCurrentUserPassword("04650077");
                        archivoXLS.createNewFile();
                        Workbook libro = new HSSFWorkbook();
                        FileOutputStream archivo = new FileOutputStream(archivoXLS);
                        Sheet hoja1 = libro.createSheet("especialidad");
                        Sheet hoja2 = libro.createSheet("catalogo");
                        Sheet hoja3 = libro.createSheet("marca");
                        Sheet hoja4 = libro.createSheet("tipo");
                        Sheet hoja5 = libro.createSheet("ejemplar");
                        Sheet hoja6 = libro.createSheet("orden");
                        Sheet hoja7 = libro.createSheet("partida");
                        Sheet hoja8 = libro.createSheet("compania");
                        Sheet hoja9 = libro.createSheet("imagen");

                        //***************************imagen*******************************
                        Foto[] fotos = (Foto[]) orden_act.getFotos().toArray(new Foto[0]);
                        for(int k=0;k<fotos.length-1;k++) 
                        {
                            for(int f=0;f<(fotos.length-1)-k;f++) 
                            {
                                if (fotos[f].getFecha().after(fotos[f+1].getFecha())==true) 
                                {
                                    Foto aux;
                                    aux=fotos[f];
                                    fotos[f]=fotos[f+1];
                                    fotos[f+1]=aux;
                                }
                            }
                        }

                        if(fotos.length>0)
                        {
                            try
                            {
                                InputStream is = new FileInputStream(ruta+"ordenes/"+orden_act.getIdOrden()+"/miniatura/"+fotos[0].getDescripcion());
                                byte[] bytes = IOUtils.toByteArray(is);
                                int pictureIdx = libro.addPicture(bytes, Workbook.PICTURE_TYPE_JPEG);
                                is.close();
                                CreationHelper helper = libro.getCreationHelper();
                                Drawing drawing = hoja9.createDrawingPatriarch();
                                ClientAnchor anchor = helper.createClientAnchor();
                                anchor.setCol1(3);
                                anchor.setRow1(2);
                                Picture pict = drawing.createPicture(anchor, pictureIdx);
                                pict.resize();
                            }catch(Exception e){e.printStackTrace();}
                        }
                            
                        //************************especialidad*****************************
                        Especialidad[] especialidad = (Especialidad[])session.createCriteria(Especialidad.class).list().toArray(new Especialidad[0]);
                        Row h1r0=hoja1.createRow(0);
                        h1r0.createCell(0).setCellValue("Partida");
                        h1r0.createCell(1).setCellValue("sub");
                        h1r0.createCell(2).setCellValue("registro");
                        if(especialidad.length>0)
                        {
                            for(int i=0; i<especialidad.length; i++)
                            {
                                Row fh1 = hoja1.createRow(i+1);
                                fh1.createCell(0).setCellValue(especialidad[i].getIdGrupoMecanico());
                                if(especialidad[i].getDescripcion()!=null)
                                    fh1.createCell(1).setCellValue(especialidad[i].getDescripcion());
                                else
                                    fh1.createCell(1).setCellValue("");
                                fh1.createCell(2).setCellValue("o");
                            }
                        }

                        //************************catalogo*****************************
                        Catalogo[] catalogo = (Catalogo[])session.createCriteria(Catalogo.class).list().toArray(new Catalogo[0]);
                        Row h2r0=hoja2.createRow(0);
                        h2r0.createCell(0).setCellValue("id_catalogo");
                        h2r0.createCell(1).setCellValue("nombre");
                        h2r0.createCell(2).setCellValue("id_especialidad");
                        h2r0.createCell(3).setCellValue("registro");
                        if(catalogo.length>0)
                        {
                            for(int i=0; i<catalogo.length; i++)
                            {
                                Row fh2 = hoja2.createRow(i+1);
                                fh2.createCell(0).setCellValue(catalogo[i].getIdCatalogo());
                                if(catalogo[i].getNombre()!=null)
                                    fh2.createCell(1).setCellValue(catalogo[i].getNombre());
                                else
                                    fh2.createCell(1).setCellValue("");
                                fh2.createCell(2).setCellValue(catalogo[i].getEspecialidad().getIdGrupoMecanico());
                                fh2.createCell(3).setCellValue("o");
                            }
                        }

                        //************************marca*****************************
                        Marca[] marca = (Marca[])session.createCriteria(Marca.class).list().toArray(new Marca[0]);
                        Row h3r0=hoja3.createRow(0);
                        h3r0.createCell(0).setCellValue("id_marca");
                        h3r0.createCell(1).setCellValue("nombre_marca");
                        h3r0.createCell(2).setCellValue("registro");
                        if(marca.length>0)
                        {
                            for(int i=0; i<marca.length; i++)
                            {
                                Row fh3 = hoja3.createRow(i+1);
                                fh3.createCell(0).setCellValue(marca[i].getIdMarca());
                                fh3.createCell(1).setCellValue(marca[i].getMarcaNombre());
                                fh3.createCell(2).setCellValue("o");
                            }
                        }

                        //************************tipo*****************************
                        Tipo[] tipo = (Tipo[])session.createCriteria(Tipo.class).list().toArray(new Tipo[0]);
                        Row h4r0=hoja4.createRow(0);
                        h4r0.createCell(0).setCellValue("tipo_nombre");
                        h4r0.createCell(1).setCellValue("e_pesado");
                        h4r0.createCell(2).setCellValue("registro");
                        if(tipo.length>0)
                        {
                            for(int i=0; i<tipo.length; i++)
                            {
                                Row fh4 = hoja4.createRow(i+1);
                                fh4.createCell(0).setCellValue(tipo[i].getTipoNombre());
                                fh4.createCell(1).setCellValue(tipo[i].getEPesado());
                                fh4.createCell(2).setCellValue("o");
                            }
                        }

                        //************************ejemplar*****************************
                        Ejemplar[] ejemplar = (Ejemplar[])session.createCriteria(Ejemplar.class).list().toArray(new Ejemplar[0]);
                        Row h5r0=hoja5.createRow(0);
                        h5r0.createCell(0).setCellValue("id_parte");
                        h5r0.createCell(1).setCellValue("id_marca");
                        h5r0.createCell(2).setCellValue("tipo_nombre");
                        h5r0.createCell(3).setCellValue("modelo");
                        h5r0.createCell(4).setCellValue("id_catalogo");
                        h5r0.createCell(5).setCellValue("comentario");
                        h5r0.createCell(6).setCellValue("registro");
                        if(ejemplar.length>0)
                        {
                            for(int i=0; i<ejemplar.length; i++)
                            {
                                Row fh5 = hoja5.createRow(i+1);
                                fh5.createCell(0).setCellValue(ejemplar[i].getIdParte());
                                if(ejemplar[i].getMarca()!=null)
                                    fh5.createCell(1).setCellValue(ejemplar[i].getMarca().getIdMarca());
                                else
                                    fh5.createCell(1).setCellValue("");
                                if(ejemplar[i].getTipo()!=null)
                                    fh5.createCell(2).setCellValue(ejemplar[i].getTipo().getTipoNombre());
                                else
                                    fh5.createCell(2).setCellValue("");
                                if(ejemplar[i].getModelo()!=null)
                                    fh5.createCell(3).setCellValue(ejemplar[i].getModelo());
                                else
                                    fh5.createCell(3).setCellValue("");
                                if(ejemplar[i].getCatalogo()!=null)
                                    fh5.createCell(4).setCellValue(ejemplar[i].getCatalogo());
                                else
                                    fh5.createCell(4).setCellValue("");
                                if(ejemplar[i].getComentario()!=null)
                                    fh5.createCell(5).setCellValue(ejemplar[i].getComentario());
                                else
                                    fh5.createCell(5).setCellValue("");
                                fh5.createCell(6).setCellValue("o");
                            }
                        }

                        //************************orden*****************************
                        orden_act = (Orden)session.get(Orden.class, orden_act.getIdOrden());
                        Row h6r0=hoja6.createRow(0);
                        h6r0.createCell(0).setCellValue("id_orden");
                        h6r0.createCell(1).setCellValue("aseguradora");
                        h6r0.createCell(2).setCellValue("poliza");
                        h6r0.createCell(3).setCellValue("siniestro");
                        h6r0.createCell(4).setCellValue("inciso");
                        h6r0.createCell(5).setCellValue("reporte");
                        h6r0.createCell(6).setCellValue("fecha");
                        h6r0.createCell(7).setCellValue("nombre");
                        h6r0.createCell(8).setCellValue("tipo_cliente");
                        h6r0.createCell(9).setCellValue("id_marca");
                        h6r0.createCell(10).setCellValue("tipo");
                        h6r0.createCell(11).setCellValue("anio");
                        h6r0.createCell(12).setCellValue("registro");

                        Row fh6 = hoja6.createRow(1);
                        fh6.createCell(0).setCellValue(orden_act.getIdOrden());
                        fh6.createCell(1).setCellValue(orden_act.getCompania().getIdCompania());
                        if(orden_act.getPoliza()!=null)
                            fh6.createCell(2).setCellValue(orden_act.getPoliza());
                        else
                            fh6.createCell(2).setCellValue("");
                        if(orden_act.getSiniestro()!=null)
                            fh6.createCell(3).setCellValue(orden_act.getSiniestro());
                        else
                            fh6.createCell(3).setCellValue("");
                        if(orden_act.getInciso()!=null)
                            fh6.createCell(4).setCellValue(orden_act.getInciso());
                        else
                            fh6.createCell(4).setCellValue("");
                        if(orden_act.getNoReporte()!=null)
                            fh6.createCell(5).setCellValue(orden_act.getNoReporte());
                        else
                            fh6.createCell(5).setCellValue("");
                        fh6.createCell(6).setCellValue(orden_act.getFecha());
                        fh6.createCell(7).setCellValue(orden_act.getClientes().getNombre());
                        fh6.createCell(8).setCellValue(orden_act.getTipoCliente());
                        fh6.createCell(9).setCellValue(orden_act.getMarca().getIdMarca());
                        fh6.createCell(10).setCellValue(orden_act.getTipo().getTipoNombre());
                        fh6.createCell(11).setCellValue(orden_act.getModelo());
                        fh6.createCell(12).setCellValue("o");

                        Compania com=orden_act.getCompania();
                        Row h8r0=hoja8.createRow(0);
                        h8r0.createCell(0).setCellValue("id_compania");
                        h8r0.createCell(1).setCellValue("nombre");
                        h8r0.createCell(2).setCellValue("importe_hota");
                        h8r0.createCell(3).setCellValue("importe_max");
                        h8r0.createCell(4).setCellValue("registro");

                        Row fh8 = hoja8.createRow(1);
                        fh8.createCell(0).setCellValue(com.getIdCompania());
                        fh8.createCell(1).setCellValue(com.getNombre());
                        fh8.createCell(2).setCellValue(com.getImporteHora());
                        fh8.createCell(3).setCellValue(com.getImporteMax());
                        fh8.createCell(4).setCellValue("o");


                        //************************partida*****************************
                        Partida[] cuentas = (Partida[])session.createCriteria(Partida.class).add(Restrictions.eq("ordenByIdOrden.idOrden", orden_act.getIdOrden())).addOrder(Order.asc("idEvaluacion")).addOrder(Order.asc("subPartida")).list().toArray(new Partida[0]);
                        Partida[] enlazadas = (Partida[])session.createCriteria(Partida.class).add(Restrictions.eq("ordenByEnlazada.idOrden", orden_act.getIdOrden())).addOrder(Order.asc("idEvaluacion")).addOrder(Order.asc("subPartida")).list().toArray(new Partida[0]);
                        Row h7r0=hoja7.createRow(0);
                        h7r0.createCell(0).setCellValue("id_partida");
                        h7r0.createCell(1).setCellValue("id_evaluacion");
                        h7r0.createCell(2).setCellValue("sub_partida");
                        h7r0.createCell(3).setCellValue("esp_hoj");
                        h7r0.createCell(4).setCellValue("esp_mec");
                        h7r0.createCell(5).setCellValue("esp_sus");
                        h7r0.createCell(6).setCellValue("esp_ele");
                        h7r0.createCell(7).setCellValue("dm");
                        h7r0.createCell(8).setCellValue("cam");
                        h7r0.createCell(9).setCellValue("rep_min");
                        h7r0.createCell(10).setCellValue("rep_med");
                        h7r0.createCell(11).setCellValue("rep_max");
                        h7r0.createCell(12).setCellValue("pint");
                        h7r0.createCell(13).setCellValue("cant");
                        h7r0.createCell(14).setCellValue("med");
                        h7r0.createCell(15).setCellValue("id_catalogo");
                        h7r0.createCell(16).setCellValue("id_parte");
                        h7r0.createCell(17).setCellValue("incluida");
                        h7r0.createCell(18).setCellValue("ori");
                        h7r0.createCell(19).setCellValue("nal");
                        h7r0.createCell(20).setCellValue("desm");
                        h7r0.createCell(21).setCellValue("pd");
                        h7r0.createCell(22).setCellValue("tot");
                        h7r0.createCell(23).setCellValue("int_desm");
                        h7r0.createCell(24).setCellValue("int_camb");
                        h7r0.createCell(25).setCellValue("int_rep_min");
                        h7r0.createCell(26).setCellValue("int_rep_med");
                        h7r0.createCell(27).setCellValue("int_rep_max");
                        h7r0.createCell(28).setCellValue("int_pin_min");
                        h7r0.createCell(29).setCellValue("int_pin_med");
                        h7r0.createCell(30).setCellValue("int_pin_max");
                        h7r0.createCell(31).setCellValue("instruccion");
                        h7r0.createCell(32).setCellValue("tipo");
                        h7r0.createCell(33).setCellValue("enlazada");
                        h7r0.createCell(34).setCellValue("autorizado_valuacion");
                        h7r0.createCell(35).setCellValue("c_u");
                        h7r0.createCell(36).setCellValue("porcentaje");
                        h7r0.createCell(37).setCellValue("precio_cia");
                        h7r0.createCell(38).setCellValue("cant_aut");
                        h7r0.createCell(39).setCellValue("precio_aut");
                        h7r0.createCell(40).setCellValue("autorizado");
                        h7r0.createCell(41).setCellValue("horas");
                        h7r0.createCell(42).setCellValue("ref_coti");
                        h7r0.createCell(43).setCellValue("ref_com");
                        h7r0.createCell(44).setCellValue("so");
                        h7r0.createCell(45).setCellValue("pedido");
                        h7r0.createCell(46).setCellValue("entrega");
                        h7r0.createCell(47).setCellValue("id_orden");
                        h7r0.createCell(48).setCellValue("pcp");
                        h7r0.createCell(49).setCellValue("registro");


                        if(cuentas.length>0)
                        {
                            for(int i=0; i<cuentas.length; i++)
                            {
                                Row fh7 = hoja7.createRow(i+1);
                                fh7.createCell(0).setCellValue(cuentas[i].getIdPartida());
                                fh7.createCell(1).setCellValue(cuentas[i].getIdEvaluacion());
                                fh7.createCell(2).setCellValue(cuentas[i].getSubPartida());
                                fh7.createCell(3).setCellValue(cuentas[i].isEspHoj());
                                fh7.createCell(4).setCellValue(cuentas[i].isEspMec());
                                fh7.createCell(5).setCellValue(cuentas[i].isEspSus());
                                fh7.createCell(6).setCellValue(cuentas[i].isEspEle());
                                fh7.createCell(7).setCellValue(cuentas[i].getDm());
                                fh7.createCell(8).setCellValue(cuentas[i].getCam());
                                fh7.createCell(9).setCellValue(cuentas[i].getRepMin());
                                fh7.createCell(10).setCellValue(cuentas[i].getRepMed());
                                fh7.createCell(11).setCellValue(cuentas[i].getRepMax());
                                fh7.createCell(12).setCellValue(cuentas[i].getPint());
                                fh7.createCell(13).setCellValue(cuentas[i].getCant());
                                fh7.createCell(14).setCellValue(cuentas[i].getMed());
                                fh7.createCell(15).setCellValue(cuentas[i].getCatalogo().getIdCatalogo());
                                if(cuentas[i].getEjemplar()!=null)
                                    fh7.createCell(16).setCellValue(cuentas[i].getEjemplar().getIdParte());
                                else
                                    fh7.createCell(16).setCellValue("");
                                fh7.createCell(17).setCellValue(cuentas[i].isIncluida());
                                fh7.createCell(18).setCellValue(cuentas[i].isOri());
                                fh7.createCell(19).setCellValue(cuentas[i].isNal());
                                fh7.createCell(20).setCellValue(cuentas[i].isDesm());
                                fh7.createCell(21).setCellValue(cuentas[i].isPd());
                                if(cuentas[i].getProveedor()!=null)
                                    fh7.createCell(22).setCellValue(cuentas[i].getProveedor().getIdProveedor());
                                else
                                    fh7.createCell(22).setCellValue("");
                                fh7.createCell(23).setCellValue(cuentas[i].getIntDesm());
                                fh7.createCell(24).setCellValue(cuentas[i].getIntCamb());
                                fh7.createCell(25).setCellValue(cuentas[i].getIntRepMin());
                                fh7.createCell(26).setCellValue(cuentas[i].getIntRepMed());
                                fh7.createCell(27).setCellValue(cuentas[i].getIntRepMax());
                                fh7.createCell(28).setCellValue(cuentas[i].getIntPinMin());
                                fh7.createCell(29).setCellValue(cuentas[i].getIntPinMed());
                                fh7.createCell(30).setCellValue(cuentas[i].getIntPinMax());
                                if(cuentas[i].getInstruccion()!=null)
                                    fh7.createCell(31).setCellValue(cuentas[i].getInstruccion());
                                else
                                    fh7.createCell(31).setCellValue("");
                                fh7.createCell(32).setCellValue(cuentas[i].getTipo());
                                if(cuentas[i].getOrdenByEnlazada()!=null)
                                    fh7.createCell(33).setCellValue(cuentas[i].getOrdenByEnlazada().getIdOrden());
                                else
                                    fh7.createCell(33).setCellValue("");
                                fh7.createCell(34).setCellValue(cuentas[i].isAutorizadoValuacion());
                                fh7.createCell(35).setCellValue(cuentas[i].getCU());
                                fh7.createCell(36).setCellValue(cuentas[i].getPorcentaje());
                                fh7.createCell(37).setCellValue(cuentas[i].getPrecioCiaSegurosCU());
                                fh7.createCell(38).setCellValue(cuentas[i].getCantidadAut());
                                fh7.createCell(39).setCellValue(cuentas[i].getPrecioAutCU());
                                fh7.createCell(40).setCellValue(cuentas[i].isAutorizado());
                                fh7.createCell(41).setCellValue(cuentas[i].getHoras());
                                fh7.createCell(42).setCellValue(cuentas[i].isRefCoti());
                                fh7.createCell(43).setCellValue(cuentas[i].isRefComp());
                                fh7.createCell(44).setCellValue(cuentas[i].isSo());
                                if(cuentas[i].getPedido()!=null)
                                {
                                    fh7.createCell(45).setCellValue(cuentas[i].getPedido().getIdPedido());
                                    if(cuentas[i].getPlazo()!=null)
                                        fh7.createCell(46).setCellValue(cuentas[i].getPlazo());
                                    else
                                        fh7.createCell(46).setCellValue("");
                                }
                                else
                                {
                                    fh7.createCell(45).setCellValue("");
                                    fh7.createCell(46).setCellValue("");
                                }
                                fh7.createCell(47).setCellValue(cuentas[i].getOrdenByIdOrden().getIdOrden());
                                fh7.createCell(48).setCellValue(cuentas[i].getPcp());
                                fh7.createCell(49).setCellValue("o");
                            }
                        }
                        libro.write(archivo);
                        Biff8EncryptionKey.setCurrentUserPassword(null);
                        archivo.close();
                        JOptionPane.showMessageDialog(null, "Archivo guardado!");
                    /*}
                    else
                    {
                        if(session.isOpen())
                            session.close();
                        JOptionPane.showMessageDialog(null, "La orden ya contiene partidas!");
                    }*/
                            
                }
                catch (Exception he)
                {
                    he.printStackTrace();
                    session.getTransaction().rollback();
                }
                if(session!=null)
                    if(session.isOpen())
                        session.close();
            }
        }
    }
    else
        JOptionPane.showMessageDialog(this, "Debes seleccionar una orden de taller primero");
}

From source file:y.graphs.XLSHelper.java

License:Open Source License

public static boolean saveElfData(String filename, ElfDb db, double sensibilita, boolean save_grafico) {
    final DateTime[] times = db.getPeriods();
    final ElfValue[][] dayvalues = db.getSampledData();
    final int[] mediane = db.getOpValues();
    final int[] maxs = db.getOpMaxDay();
    final int[] counts = db.getOpValueCount();
    final int maxi = db.getMaxidx();

    Workbook wb = null;/*from w w w  .j  ava  2s . c  om*/

    try {
        if (Utils.abortOnExistingAndDontOverwrite(filename))
            return false;

        wb = new XSSFWorkbook();

        CreationHelper createHelper = wb.getCreationHelper();
        Sheet sheet = wb.createSheet(Config.getResource("TitleStats"));

        int rown = 0;
        Row row = sheet.createRow(rown++);
        Cell cell = row.createCell(0);
        cell.setCellValue(Config.getResource("TitleDate"));
        cell = row.createCell(1);
        cell.setCellValue(Config.getResource("TitleMediana"));
        cell = row.createCell(2);
        cell.setCellValue(Config.getResource("TitleMaxM"));
        cell = row.createCell(3);
        cell.setCellValue(Config.getResource("TitleNumberOfData"));

        CellStyle dateStyle1 = wb.createCellStyle();
        dateStyle1.setDataFormat(createHelper.createDataFormat().getFormat("d/m/yy"));
        CellStyle doubleFormat1 = wb.createCellStyle();
        DataFormat format1 = wb.createDataFormat();
        doubleFormat1.setDataFormat(format1.getFormat("0.00"));

        for (int i = 0; i < mediane.length; i++) {
            row = sheet.createRow(rown++);

            cell = row.createCell(0);
            cell.setCellStyle(dateStyle1);
            cell.setCellValue(Utils.toDateString(dayvalues[i][0].getTime()));

            cell = row.createCell(1);
            cell.setCellStyle(doubleFormat1);
            cell.setCellValue(ElfValue.valueIntToDouble(mediane[i]));

            cell = row.createCell(2);
            cell.setCellStyle(doubleFormat1);
            cell.setCellValue(ElfValue.valueIntToDouble(maxs[i]));

            cell = row.createCell(3);
            cell.setCellValue(counts[i]);
        }

        // line with DataFunction max
        row = sheet.createRow(rown++);
        row = sheet.createRow(rown++);
        cell = row.createCell(0);
        cell.setCellValue(Config.getResource("MsgMax") + "(" + db.getOperationPerformed().getName() + ") - "
                + Utils.toDateString(times[maxi]));

        cell = row.createCell(1);
        cell.setCellStyle(doubleFormat1);
        cell.setCellValue(ElfValue.valueIntToDouble(mediane[maxi]));

        cell = row.createCell(2);
        cell.setCellStyle(doubleFormat1);
        cell.setCellValue(ElfValue.valueIntToDouble(maxs[maxi]));

        cell = row.createCell(3);
        cell.setCellValue(counts[maxi]);

        // line with max
        final ElfValue maxvalue = db.getSelectedElfValue(new Comparator<ElfValue>() {
            @Override
            public int compare(ElfValue o1, ElfValue o2) {
                return o1.getValue() - o2.getValue();
            }
        });
        row = sheet.createRow(rown++);
        cell = row.createCell(0);
        cell.setCellValue(Config.getResource("MsgMax") + "(" + Utils.toDateString(maxvalue.getTime()) + ")");

        cell = row.createCell(1);
        cell.setCellStyle(doubleFormat1);
        cell.setCellValue(MeasurementValue.valueIntToDouble(maxvalue.getValue()));

        cell = row.createCell(2);
        cell.setCellStyle(doubleFormat1);
        cell.setCellValue(MeasurementValue.valueIntToDouble(maxvalue.getMax()));

        cell = row.createCell(3);
        cell.setCellValue(counts[maxi]);

        // sheet containing all raw data
        Sheet sheetdata = wb.createSheet(Config.getResource("TitleSheetDatas"));
        CellStyle dateTimeStyle2 = wb.createCellStyle();
        dateTimeStyle2.setDataFormat(createHelper.createDataFormat().getFormat("m/d/yy h:mm"));

        CellStyle doubleFormat2 = wb.createCellStyle();
        DataFormat format2 = wb.createDataFormat();
        doubleFormat2.setDataFormat(format2.getFormat("0.00"));

        rown = 0;
        row = sheetdata.createRow(rown++);
        cell = row.createCell(0);
        cell.setCellValue(Config.getResource("TitleDate"));
        cell = row.createCell(1);
        cell.setCellValue(Config.getResource("TitleValue"));
        cell = row.createCell(2);
        cell.setCellValue(Config.getResource("TitlePeak"));
        cell = row.createCell(3);
        cell.setCellValue(Config.getResource("TitleMediana"));
        cell = row.createCell(4);
        cell.setCellValue(Config.getResource("TitleDayMax"));
        cell = row.createCell(5);
        cell.setCellValue(Config.getResource("TitleMedianaMax"));
        cell = row.createCell(6);
        cell.setCellValue(Config.getResource("TitleSens"));
        cell = row.createCell(7);
        cell.setCellValue(Config.getResource("TitleQualityTarget"));
        cell = row.createCell(8);
        cell.setCellValue(Config.getResource("TitleAttentionValue"));

        for (int i = 0; i < dayvalues.length; i++) {
            final ElfValue[] day = dayvalues[i];

            for (int k = 0; k < day.length; k++) {
                final ElfValue value = day[k];
                final DateTime time = value.getTime();

                row = sheetdata.createRow(rown++);
                cell = row.createCell(0);
                cell.setCellStyle(dateTimeStyle2);
                cell.setCellValue(Utils.toDateString(time));

                cell = row.createCell(1);
                cell.setCellStyle(doubleFormat2);

                if (value.isValid())
                    cell.setCellValue(ElfValue.valueIntToDouble(value.getValue()));
                else
                    cell.setCellValue("");

                cell = row.createCell(2);
                cell.setCellStyle(doubleFormat2);
                if (value.isValid())
                    cell.setCellValue(ElfValue.valueIntToDouble(value.getMax()));
                else
                    cell.setCellValue("");

                cell = row.createCell(3);
                cell.setCellStyle(doubleFormat2);
                cell.setCellValue(ElfValue.valueIntToDouble(mediane[i]));

                cell = row.createCell(4);
                cell.setCellStyle(doubleFormat2);
                cell.setCellValue(ElfValue.valueIntToDouble(maxs[i]));

                cell = row.createCell(5);
                cell.setCellStyle(doubleFormat2);
                cell.setCellValue(ElfValue.valueIntToDouble(mediane[maxi]));

                cell = row.createCell(6);
                cell.setCellStyle(doubleFormat2);
                cell.setCellValue(sensibilita);
                cell = row.createCell(7);
                cell.setCellStyle(doubleFormat2);
                cell.setCellValue(3);
                cell = row.createCell(8);
                cell.setCellStyle(doubleFormat2);
                cell.setCellValue(10);
            }
        }

        if (save_grafico) {
            final int maxline = rown - 1;

            sheet = wb.createSheet(Config.getResource("TitleChart"));

            Drawing drawing = sheet.createDrawingPatriarch();
            ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 18, 25);

            Chart chart = drawing.createChart(anchor);
            ChartLegend legend = chart.getOrCreateLegend();
            legend.setPosition(LegendPosition.TOP_RIGHT);

            ScatterChartData data = chart.getChartDataFactory().createScatterChartData();
            //           LineChartData data = chart.getChartDataFactory().createLineChartData();

            ValueAxis bottomAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.BOTTOM);
            ValueAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);

            leftAxis.setMinimum(0.0);
            leftAxis.setMaximum(10.0);
            leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);

            ChartDataSource<String> xs = DataSources.fromStringCellRange(sheetdata,
                    new CellRangeAddress(1, maxline, 0, 0));
            ChartDataSource<Number> ys_val = DataSources.fromNumericCellRange(sheetdata,
                    new CellRangeAddress(1, maxline, 1, 1));
            ChartDataSource<Number> ys_sens = DataSources.fromNumericCellRange(sheetdata,
                    new CellRangeAddress(1, maxline, 6, 6));
            ChartDataSource<Number> ys_qual = DataSources.fromNumericCellRange(sheetdata,
                    new CellRangeAddress(1, maxline, 7, 7));
            ChartDataSource<Number> ys_att = DataSources.fromNumericCellRange(sheetdata,
                    new CellRangeAddress(1, maxline, 8, 8));

            ScatterChartSeries data_val = data.addSerie(xs, ys_val);
            data_val.setTitle(Config.getResource("TitleMeasuredValues"));

            ScatterChartSeries data_sens = data.addSerie(xs, ys_sens);
            data_sens.setTitle(Config.getResource("TitleInstrumentSens"));

            ScatterChartSeries data_qual = data.addSerie(xs, ys_qual);
            data_qual.setTitle(Config.getResource("TitleQualityTarget"));

            ScatterChartSeries data_att = data.addSerie(xs, ys_att);
            data_att.setTitle(Config.getResource("TitleAttentionValue"));

            chart.plot(data, bottomAxis, leftAxis);
        }

        FileOutputStream fileOut = new FileOutputStream(filename);
        wb.write(fileOut);
        fileOut.close();
        return true;
    } catch (Exception e) {
        Utils.MessageBox(Config.getResource("MsgErrorXlsx") + "\n" + e.toString(),
                Config.getResource("TitleError"));
        return false;
    } finally {
        if (wb != null)
            try {
                wb.close();
            } catch (IOException e) {
            }
    }
}

From source file:y.graphs.XLSHelper.java

License:Open Source License

public static boolean saveCurrentsData(String filename, CurrentDb db, boolean save_grafico) {
    final DateTime[] times = db.getPeriods();
    final CurrentValue[][] dayvalues = db.getSampledData();
    final int[] mediane = db.getOpValues();
    final int[] maxs = db.getOpMaxDay();
    final int[] counts = db.getOpValueCount();
    final int maxi = db.getMaxidx();

    Workbook wb = null;/*from w w  w . j av a2s .c  om*/

    try {
        if (Utils.abortOnExistingAndDontOverwrite(filename))
            return false;

        wb = new XSSFWorkbook();

        CreationHelper createHelper = wb.getCreationHelper();
        Sheet sheet = wb.createSheet(Config.getResource("TitleStats"));

        int rown = 0;
        Row row = sheet.createRow(rown++);
        Cell cell = row.createCell(0);
        cell.setCellValue(Config.getResource("TitleDate"));
        cell = row.createCell(1);
        cell.setCellValue(Config.getResource("TitleMediana"));
        cell = row.createCell(2);
        cell.setCellValue(Config.getResource("TitleMaxM"));
        cell = row.createCell(3);
        cell.setCellValue(Config.getResource("TitleNumberOfData"));

        CellStyle dateStyle1 = wb.createCellStyle();
        dateStyle1.setDataFormat(createHelper.createDataFormat().getFormat("d/m/yy"));
        CellStyle doubleFormat1 = wb.createCellStyle();
        DataFormat format1 = wb.createDataFormat();
        doubleFormat1.setDataFormat(format1.getFormat("0.00"));

        for (int i = 0; i < mediane.length; i++) {
            row = sheet.createRow(rown++);

            cell = row.createCell(0);
            cell.setCellStyle(dateStyle1);
            cell.setCellValue(Utils.toDateString(dayvalues[i][0].getTime()));

            cell = row.createCell(1);
            cell.setCellStyle(doubleFormat1);
            cell.setCellValue(ElfValue.valueIntToDouble(mediane[i]));

            cell = row.createCell(2);
            cell.setCellStyle(doubleFormat1);
            cell.setCellValue(ElfValue.valueIntToDouble(maxs[i]));

            cell = row.createCell(3);
            cell.setCellValue(counts[i]);
        }

        // line with DataFunction max
        row = sheet.createRow(rown++);
        row = sheet.createRow(rown++);
        cell = row.createCell(0);
        cell.setCellValue(Config.getResource("MsgMax") + "(" + db.getOperationPerformed().getName() + ") - "
                + Utils.toDateString(times[maxi]));

        cell = row.createCell(1);
        cell.setCellStyle(doubleFormat1);
        cell.setCellValue(ElfValue.valueIntToDouble(mediane[maxi]));

        cell = row.createCell(2);
        cell.setCellStyle(doubleFormat1);
        cell.setCellValue(ElfValue.valueIntToDouble(maxs[maxi]));

        cell = row.createCell(3);
        cell.setCellValue(counts[maxi]);

        // line with max
        final CurrentValue maxvalue = db.getSelectedCurrentValue(new Comparator<CurrentValue>() {
            @Override
            public int compare(CurrentValue o1, CurrentValue o2) {
                return o1.getValue() - o2.getValue();
            }
        });
        row = sheet.createRow(rown++);
        cell = row.createCell(0);
        cell.setCellValue(Config.getResource("MsgMax") + "(" + Utils.toDateString(maxvalue.getTime()) + ")");

        cell = row.createCell(1);
        cell.setCellStyle(doubleFormat1);
        cell.setCellValue(MeasurementValue.valueIntToDouble(maxvalue.getValue()));

        cell = row.createCell(2);
        cell.setCellStyle(doubleFormat1);
        cell.setCellValue("");

        cell = row.createCell(3);
        cell.setCellValue(counts[maxi]);

        // sheet containing all raw data
        Sheet sheetdata = wb.createSheet(Config.getResource("TitleSheetDatas"));
        CellStyle dateTimeStyle2 = wb.createCellStyle();
        dateTimeStyle2.setDataFormat(createHelper.createDataFormat().getFormat("m/d/yy h:mm"));

        CellStyle doubleFormat2 = wb.createCellStyle();
        DataFormat format2 = wb.createDataFormat();
        doubleFormat2.setDataFormat(format2.getFormat("0.00"));

        rown = 0;
        row = sheetdata.createRow(rown++);
        cell = row.createCell(0);
        cell.setCellValue(Config.getResource("TitleDate"));
        cell = row.createCell(1);
        cell.setCellValue(Config.getResource("TitleValue"));
        cell = row.createCell(2);
        cell.setCellValue(Config.getResource("TitlePeak"));
        cell = row.createCell(3);
        cell.setCellValue(Config.getResource("TitleMediana"));
        cell = row.createCell(4);
        cell.setCellValue(Config.getResource("TitleDayMax"));
        cell = row.createCell(5);
        cell.setCellValue(Config.getResource("TitleMedianaMax"));

        for (int i = 0; i < dayvalues.length; i++) {
            final CurrentValue[] day = dayvalues[i];

            for (int k = 0; k < day.length; k++) {
                final CurrentValue value = day[k];
                final DateTime time = value.getTime();

                row = sheetdata.createRow(rown++);
                cell = row.createCell(0);
                cell.setCellStyle(dateTimeStyle2);
                cell.setCellValue(Utils.toDateString(time));

                cell = row.createCell(1);
                cell.setCellStyle(doubleFormat2);

                cell.setCellValue(ElfValue.valueIntToDouble(value.getValue()));

                cell = row.createCell(2);
                //                cell.setCellStyle(doubleFormat2);
                cell.setCellValue("");

                cell = row.createCell(3);
                cell.setCellStyle(doubleFormat2);
                cell.setCellValue(ElfValue.valueIntToDouble(mediane[i]));

                cell = row.createCell(4);
                cell.setCellStyle(doubleFormat2);
                cell.setCellValue(ElfValue.valueIntToDouble(maxs[i]));

                cell = row.createCell(5);
                cell.setCellStyle(doubleFormat2);
                cell.setCellValue(ElfValue.valueIntToDouble(mediane[maxi]));
            }
        }

        if (save_grafico) {
            final int maxline = rown - 1;

            sheet = wb.createSheet(Config.getResource("TitleChart"));

            Drawing drawing = sheet.createDrawingPatriarch();
            ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 18, 25);

            Chart chart = drawing.createChart(anchor);
            ChartLegend legend = chart.getOrCreateLegend();
            legend.setPosition(LegendPosition.TOP_RIGHT);

            ScatterChartData data = chart.getChartDataFactory().createScatterChartData();
            //           LineChartData data = chart.getChartDataFactory().createLineChartData();

            ValueAxis bottomAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.BOTTOM);
            ValueAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);

            leftAxis.setMinimum(0.0);
            leftAxis.setMaximum(10.0);
            leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);

            ChartDataSource<String> xs = DataSources.fromStringCellRange(sheetdata,
                    new CellRangeAddress(1, maxline, 0, 0));
            ChartDataSource<Number> ys_val = DataSources.fromNumericCellRange(sheetdata,
                    new CellRangeAddress(1, maxline, 1, 1));
            ChartDataSource<Number> ys_sens = DataSources.fromNumericCellRange(sheetdata,
                    new CellRangeAddress(1, maxline, 6, 6));

            ScatterChartSeries data_val = data.addSerie(xs, ys_val);
            data_val.setTitle(Config.getResource("TitleMeasuredValues"));

            ScatterChartSeries data_sens = data.addSerie(xs, ys_sens);
            data_sens.setTitle(Config.getResource("TitleInstrumentSens"));

            chart.plot(data, bottomAxis, leftAxis);
        }

        FileOutputStream fileOut = new FileOutputStream(filename);
        wb.write(fileOut);
        fileOut.close();
        return true;
    } catch (Exception e) {
        Utils.MessageBox(Config.getResource("MsgErrorXlsx") + "\n" + e.toString(),
                Config.getResource("TitleError"));
        return false;
    } finally {
        if (wb != null)
            try {
                wb.close();
            } catch (IOException e) {
            }
    }
}