poi and formating celds with colors (backgound)

From: [Miren] (boli_NOSPAM__at_excite.com)
Date: 01/28/05


Date: Fri, 28 Jan 2005 20:39:52 +0100

Hello y have the bellow code, using one xml i am trying to build one excel
file.
i cannot formatting celds. i want to put background collor and bold (font)
but i cannot make it (i don't know how can i make it).
i have read the http://jakarta.apache.org/poi/hssf/quick-guide.html#Borders
page but i don't know how to aplly to the bellow code

Can you help me?
thanks

..........
    SimpleDateFormat fechabase = new
SimpleDateFormat("dd-MM-yyyy_HH_mm_ss");
    short rowNum = 0;
    short colNum = 0;
    HSSFRow row = null;
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSF*** *** = wb.create***(fechabase.format(new Date()));
    String fichero="xx.xls";
    String path="c:\\";
    public String getNombreFichero() {
        return fichero;
    }

    public void setNombreFichero(String fichero) {
        this.fichero = fichero;
    }
    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public void getEXCEL(String xml) {
        Document doc = null;
        DocumentBuilder db = null;
        try{
            db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            doc = db.parse(new ByteArrayInputStream(xml.getBytes()));
        }catch(Exception e){
            System.out.println("Error en el metodo inicoexcel de la
creaccion del excel: " + e.getMessage());
        }
        row = ***.createRow(rowNum);
        try{
            buscar(doc, 0);
        }catch(Exception e){
            e.printStackTrace();
        }
        try{
            FileOutputStream fileOut = new FileOutputStream(path+fichero);
            wb.write(fileOut);
            fileOut.close();
        }catch(Exception e){
            e.printStackTrace();
            System.out.println("Error creando el fichero de excel
"+e.getMessage());
        }
    }

    public void buscar(Node node, int level) {
        NodeList listar = node.getChildNodes();
        for (int i=0; i<listar.getLength(); i++) {
            Node childNode = listar.item(i);
            if (level==3 && childNode.getNodeType()==Node.TEXT_NODE) {
                System.out.println(childNode.getParentNode().getNodeName()+"-"+childNode.getNodeValue());
                if(childNode.getParentNode().getNodeName().equals("cabecera")){
                    row.setHeightInPoints(35);
                    row.createCell(colNum++).setCellValue(childNode.getNodeValue());
//**********
//**********here i want to put background collor and bold font
//**********
                }else{
                row.createCell(colNum++).setCellValue(childNode.getNodeValue());
                }
                } else if (level==1 && childNode.getNodeType()==1) {
                colNum = 0;
                row = ***.createRow(rowNum);
                ++rowNum;
            }
            buscar(childNode, level+1);
        }
    }
.............


Quantcast