Example usage for org.apache.poi.ss.usermodel ClientAnchor setCol1

List of usage examples for org.apache.poi.ss.usermodel ClientAnchor setCol1

Introduction

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

Prototype

public void setCol1(int col1);

Source Link

Document

Sets the column (0 based) of the first cell.

Usage

From source file:packtest.WorkingWithPictures.java

License:Apache License

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

    //create a new workbook
    Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
    try {/*from  w ww.  j  ava 2s.  co m*/
        CreationHelper helper = wb.getCreationHelper();

        //add a picture in this workbook.
        InputStream is = new FileInputStream(args[0]);
        byte[] bytes = IOUtils.toByteArray(is);
        is.close();
        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"; // NOSONAR
        OutputStream fileOut = new FileOutputStream(file);
        try {
            wb.write(fileOut);
        } finally {
            fileOut.close();
        }
    } finally {
        wb.close();
    }
}

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 w  ww .j  a v  a  2 s. co 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);//www  .ja v  a  2s .c om
    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:uk.co.spudsoft.birt.emitters.excel.handlers.PageHandler.java

License:Open Source License

/**
 * <p>/*from   w w w .j a v  a  2 s  .  c o m*/
 * Process a CellImage from the images list and place the image on the sheet.
 * </p><p>
 * This involves changing the row height as necesssary and determining the column spread of the image.
 * </p>
 * @param cellImage
 * The image to be placed on the sheet.
 */
private void processCellImage(HandlerState state, Drawing drawing, CellImage cellImage) {
    Coordinate location = cellImage.location;

    Cell cell = state.currentSheet.getRow(location.getRow()).getCell(location.getCol());

    IImageContent image = cellImage.image;

    StyleManagerUtils smu = state.getSmu();
    float ptHeight = cell.getRow().getHeightInPoints();
    if (image.getHeight() != null) {
        ptHeight = smu.fontSizeInPoints(image.getHeight().toString());
    }

    // Get image width
    int endCol = cell.getColumnIndex();
    double lastColWidth = ClientAnchorConversions
            .widthUnits2Millimetres((short) state.currentSheet.getColumnWidth(endCol)) + 2.0;
    int dx = smu.anchorDxFromMM(lastColWidth, lastColWidth);
    double mmWidth = 0.0;
    if (smu.isAbsolute(image.getWidth())) {
        mmWidth = image.getWidth().convertTo(DimensionType.UNITS_MM);
    } else if (smu.isPixels(image.getWidth())) {
        mmWidth = ClientAnchorConversions.pixels2Millimetres(image.getWidth().getMeasure());
    }
    // Allow image to span multiple columns
    CellRangeAddress mergedRegion = getMergedRegionBegunBy(state.currentSheet, location.getRow(),
            location.getCol());
    if ((cellImage.spanColumns) || (mergedRegion != null)) {
        log.debug("Image size: ", image.getWidth(), " translates as mmWidth = ", mmWidth);
        if (mmWidth > 0) {
            double mmAccumulatedWidth = 0;
            int endColLimit = cellImage.spanColumns ? 256 : mergedRegion.getLastColumn();
            for (endCol = cell.getColumnIndex(); mmAccumulatedWidth < mmWidth
                    && endCol < endColLimit; ++endCol) {
                lastColWidth = ClientAnchorConversions
                        .widthUnits2Millimetres((short) state.currentSheet.getColumnWidth(endCol)) + 2.0;
                mmAccumulatedWidth += lastColWidth;
                log.debug("lastColWidth = ", lastColWidth, "; mmAccumulatedWidth = ", mmAccumulatedWidth);
            }
            if (mmAccumulatedWidth > mmWidth) {
                mmAccumulatedWidth -= lastColWidth;
                --endCol;
                double mmShort = mmWidth - mmAccumulatedWidth;
                dx = smu.anchorDxFromMM(mmShort, lastColWidth);
            }
        }
    } else {
        float widthRatio = (float) (mmWidth / lastColWidth);
        ptHeight = ptHeight / widthRatio;
    }

    int rowsSpanned = state.findRowsSpanned(cell.getRowIndex(), cell.getColumnIndex());
    float neededRowHeightPoints = ptHeight;

    for (int i = 0; i < rowsSpanned; ++i) {
        int rowIndex = cell.getRowIndex() + 1 + i;
        neededRowHeightPoints -= state.currentSheet.getRow(rowIndex).getHeightInPoints();
    }

    if (neededRowHeightPoints > cell.getRow().getHeightInPoints()) {
        cell.getRow().setHeightInPoints(neededRowHeightPoints);
    }

    // ClientAnchor anchor = wb.getCreationHelper().createClientAnchor();
    ClientAnchor anchor = state.getWb().getCreationHelper().createClientAnchor();
    anchor.setCol1(cell.getColumnIndex());
    anchor.setRow1(cell.getRowIndex());
    anchor.setCol2(endCol);
    anchor.setRow2(cell.getRowIndex() + rowsSpanned);
    anchor.setDx2(dx);
    anchor.setDy2(smu.anchorDyFromPoints(ptHeight, cell.getRow().getHeightInPoints()));
    anchor.setAnchorType(ClientAnchor.MOVE_DONT_RESIZE);
    drawing.createPicture(anchor, cellImage.imageIdx);
}

From source file:uk.co.spudsoft.birt.emitters.excel2.handlers.PageHandler.java

License:Open Source License

/**
 * <p>/*from  ww w.j a  va  2  s . c o m*/
 * Process a CellImage from the images list and place the image on the sheet.
 * </p><p>
 * This involves changing the row height as necesssary and determining the column spread of the image.
 * </p>
 * @param cellImage
 * The image to be placed on the sheet.
 */
private void processCellImage(HandlerState state, Drawing drawing, CellImage cellImage) {
    Coordinate location = cellImage.location;

    Cell cell = state.currentSheet.getRow(location.getRow()).getCell(location.getCol());

    IImageContent image = cellImage.image;

    StyleManagerUtils smu = state.getSmu();
    float ptHeight = cell.getRow().getHeightInPoints();
    if (image.getHeight() != null) {
        ptHeight = smu.fontSizeInPoints(image.getHeight().toString());
    }

    // Get image width
    int endCol = cell.getColumnIndex();
    double lastColWidth = ClientAnchorConversions
            .widthUnits2Millimetres((short) state.currentSheet.getColumnWidth(endCol)) + 2.0;
    double mmWidth = 0.0;
    if (smu.isAbsolute(image.getWidth())) {
        mmWidth = image.getWidth().convertTo(DimensionType.UNITS_MM);
    } else if (smu.isPixels(image.getWidth())) {
        mmWidth = ClientAnchorConversions.pixels2Millimetres(image.getWidth().getMeasure());
    }
    int dx = smu.anchorDxFromMM(mmWidth, lastColWidth);
    // Allow image to span multiple columns
    CellRangeAddress mergedRegion = getMergedRegionBegunBy(state.currentSheet, location.getRow(),
            location.getCol());
    if ((cellImage.spanColumns) || (mergedRegion != null)) {
        log.debug("Image size: ", image.getWidth(), " translates as mmWidth = ", mmWidth);
        if (mmWidth > 0) {
            double mmAccumulatedWidth = 0;
            int endColLimit = cellImage.spanColumns ? 256 : mergedRegion.getLastColumn();
            for (endCol = cell.getColumnIndex(); mmAccumulatedWidth < mmWidth
                    && endCol < endColLimit; ++endCol) {
                lastColWidth = ClientAnchorConversions
                        .widthUnits2Millimetres((short) state.currentSheet.getColumnWidth(endCol)) + 2.0;
                mmAccumulatedWidth += lastColWidth;
                log.debug("lastColWidth = ", lastColWidth, "; mmAccumulatedWidth = ", mmAccumulatedWidth);
            }
            if (mmAccumulatedWidth > mmWidth) {
                mmAccumulatedWidth -= lastColWidth;
                --endCol;
                double mmShort = mmWidth - mmAccumulatedWidth;
                dx = smu.anchorDxFromMM(mmShort, lastColWidth);
            }
        }
        /*
              } else {
                 float widthRatio = (float)(mmWidth / lastColWidth);
                 ptHeight = ptHeight * widthRatio;
        */
    }

    int rowsSpanned = state.findRowsSpanned(cell.getRowIndex(), cell.getColumnIndex());
    float neededRowHeightPoints = ptHeight;

    for (int i = 0; i < rowsSpanned; ++i) {
        int rowIndex = cell.getRowIndex() + 1 + i;
        neededRowHeightPoints -= state.currentSheet.getRow(rowIndex).getHeightInPoints();
    }

    if (neededRowHeightPoints > cell.getRow().getHeightInPoints()) {
        cell.getRow().setHeightInPoints(neededRowHeightPoints);
    }

    // ClientAnchor anchor = wb.getCreationHelper().createClientAnchor();
    ClientAnchor anchor = state.getWb().getCreationHelper().createClientAnchor();
    anchor.setCol1(cell.getColumnIndex());
    anchor.setRow1(cell.getRowIndex());
    anchor.setCol2(endCol);
    anchor.setRow2(cell.getRowIndex() + rowsSpanned);
    anchor.setDx2(dx);
    anchor.setDy2(smu.anchorDyFromPoints(ptHeight, cell.getRow().getHeightInPoints()));
    anchor.setAnchorType(ClientAnchor.MOVE_DONT_RESIZE);
    drawing.createPicture(anchor, cellImage.imageIdx);
}

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);
    }/*from w w w. j av a2s  .co m*/

    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 ww.  j  a  v a 2  s .c  o  m*/
        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");
}