poi and formating celds with colors (backgound)

M

[Miren]

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();
HSSFSheet sheet = wb.createSheet(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 = sheet.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 = sheet.createRow(rowNum);
++rowNum;
}
buscar(childNode, level+1);
}
}
..............
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top