Ver Mensaje Individual
  #7 (permalink)  
Antiguo 27/01/2010, 10:05
juliogalleg
 
Fecha de Ingreso: noviembre-2007
Mensajes: 8
Antigüedad: 16 años, 5 meses
Puntos: 0
Respuesta: Crear Ficheros XLSX a traves de la libreria XSSF

Buenas Tardes,

Te adjunto un ejemplo que estoy realizando y los fallos de compilacion que me dan por si me puedes echar una mano.

Ejemplo:

package com.cittec.facturas.excel;


import com.cittec.Suministro;
import com.cittec.dao.ParametrosDAO;
import com.cittec.dao.SuministrosDAO;
import com.cittec.form.CalcularCostesForm;

import com.cittec.form.SeleccionContratosForm;
import com.cittec.util.LogClass;

import com.cittec.util.StringApi;

import java.io.FileOutputStream;

import java.io.IOException;
import java.io.OutputStream;

import java.text.SimpleDateFormat;

import java.util.HashMap;

import java.util.Locale;
import java.util.Vector;


import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;

import org.apache.poi.hssf.util.HSSFColor;


import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFRow;

import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

/**
* Clase donde haremos las exportacion de los listados de huecos de la curva de
* de datos de consumos y de cierres, resultantes de los parametros de entrada
* que hemos seleccionado en el formulario
* **/
public class GeneradorListadosPruebasX {
public GeneradorListadosPruebasX() {
}
private String thisClass = this.getClass().getName() + " - ";

private XSSFWorkbook xb = new XSSFWorkbook();
XSSFCellStyle style = xb.createCellStyle();
XSSFFont fontx = xb.createFont();

private static short celdaForegroundColor = HSSFColor.BLACK.index;



HashMap suministrosHuecos = new HashMap();
HashMap suministrosHuecosContrato = new HashMap();
Vector suministrosListar = new Vector();
SeleccionContratosForm cliForm = new SeleccionContratosForm();
HashMap inicioFinSum = new HashMap();



public String generaExcelX() throws Exception {
String nombreFichero;
String soloNombre = "";
try {

SimpleDateFormat simpleDateFormat =
new SimpleDateFormat("yyyy-MM-dd-kk-mm-ss",
new Locale("es", "ES"));
soloNombre = "listadosHuecos-" + (simpleDateFormat.format((new java.util.Date()).getTime()) + ".xlsx");
nombreFichero = soloNombre; //Falta el directorio
XSSFSheet sheet = xb.createSheet("ListadosHuecos");

//Datos de la factura
int indiceFila = crearResultadosListadosX(xb, sheet);


//Damos la anchura adecuada a cada columna.
sheet.setColumnWidth((short)0,
(short)((50 * 8) / ((double)1 / 20)));
sheet.setColumnWidth((short)1,
(short)((50 * 8) / ((double)1 / 20)));
sheet.setColumnWidth((short)2,
(short)((50 * 8) / ((double)1 / 20)));
sheet.setColumnWidth((short)3,
(short)((40 * 8) / ((double)1 / 20)));
sheet.setColumnWidth((short)4,
(short)((40 * 8) / ((double)1 / 20)));
sheet.setColumnWidth((short)5,
(short)((40 * 8) / ((double)1 / 20)));
sheet.setColumnWidth((short)6,
(short)((40 * 8) / ((double)1 / 20)));
sheet.setColumnWidth((short)7,
(short)((25 * 8) / ((double)1 / 20)));
sheet.setColumnWidth((short)8,
(short)((25 * 8) / ((double)1 / 20)));
sheet.setColumnWidth((short)9,
(short)((25 * 8) / ((double)1 / 20)));
sheet.setColumnWidth((short)10,
(short)((25 * 8) / ((double)1 / 20)));
sheet.setColumnWidth((short)11,
(short)((25 * 8) / ((double)1 / 20)));
sheet.setColumnWidth((short)12,
(short)((25 * 8) / ((double)1 / 20)));
sheet.setColumnWidth((short)13,
(short)((25 * 8) / ((double)1 / 20)));
sheet.setColumnWidth((short)14,
(short)((25 * 8) / ((double)1 / 20)));
sheet.setColumnWidth((short)15,
(short)((25 * 8) / ((double)1 / 20)));
sheet.setColumnWidth((short)16,
(short)((25 * 8) / ((double)1 / 20)));
sheet.setColumnWidth((short)17,
(short)((25 * 8) / ((double)1 / 20)));
sheet.setColumnWidth((short)18,
(short)((25 * 8) / ((double)1 / 20)));
sheet.setColumnWidth((short)19,
(short)((25 * 8) / ((double)1 / 20)));
sheet.setColumnWidth((short)20,
(short)((25 * 8) / ((double)1 / 20)));
sheet.setColumnWidth((short)21,
(short)((25 * 8) / ((double)1 / 20)));
sheet.setColumnWidth((short)22,
(short)((25 * 8) / ((double)1 / 20)));
sheet.setColumnWidth((short)23,
(short)((25 * 8) / ((double)1 / 20)));
sheet.setColumnWidth((short)24,
(short)((25 * 8) / ((double)1 / 20)));
sheet.setColumnWidth((short)25,
(short)((25 * 8) / ((double)1 / 20)));
sheet.setColumnWidth((short)26,
(short)((25 * 8) / ((double)1 / 20)));
sheet.setColumnWidth((short)27,
(short)((25 * 8) / ((double)1 / 20)));
sheet.setColumnWidth((short)28,
(short)((25 * 8) / ((double)1 / 20)));
sheet.setColumnWidth((short)29,
(short)((25 * 8) / ((double)1 / 20)));
sheet.setColumnWidth((short)30,
(short)((25 * 8) / ((double)1 / 20)));

ParametrosDAO padao= new ParametrosDAO();
FileOutputStream fileOut = new FileOutputStream(padao.getParametro("DIRDOCLOCAL") +nombreFichero);
xb.write(fileOut);
fileOut.close();

} catch (Exception fnfe) {
throw new Exception("No se puede crear el fichero de informe");
}

return soloNombre;
}


private int crearResultadosListadosX(XSSFWorkbook wb, XSSFSheet sheet) {
XSSFRow row = sheet.createRow((short)0);


for (int i = 0; i < 70000; i++)
{
createCell(xb, row, (short)0, "00000",
estiloCabecera(wb));



}
return 8;
}
private static void createCell(XSSFWorkbook wb, XSSFRow row, short column,
String value,
XSSFCellStyle cellStyle) {
XSSFCell cell = row.createCell(column);
cell.setCellValue(value);

}
private XSSFCellStyle estiloCabecera(XSSFWorkbook wb) {
XSSFCellStyle style = wb.createCellStyle();

style.setFillForegroundColor(celdaForegroundColor) ;

return style;

}


/**
* Escribe la hoja Excel en OutputStream, para devolverlo al cliente
*
* @param out OutputStream que se le devolverá al cliente
*/
public void write(OutputStream out){
try{
xb.write(out);
}
catch (IOException e) {
LogClass.getLogger().error(thisClass +
"Error Generando Excel Factura: " +
e.toString());
}

}
}


Y los Errores que me da:

Error: Sheet not found in class org.apache.poi.xssf.usermodel.XSSFSheet in class org.apache.poi.xssf.usermodel.XSSFWorkbook
Error: Workbook not found in class org.apache.poi.xssf.usermodel.XSSFWorkbook
Error: Row not found in class org.apache.poi.xssf.usermodel.XSSFRow
Error: class MissingCellPolicy not found in class com.cittec.facturas.excel.GeneradorListadosPruebas X
Error: class MissingCellPolicy not found in method createCell(org.apache.poi.xssf.usermodel.XSSFWorkb ook, org.apache.poi.xssf.usermodel.XSSFRow, short, java.lang.String, org.apache.poi.xssf.usermodel.XSSFCellStyle)
Error(49,35): PictureData not found in class org.apache.poi.xssf.usermodel.XSSFPictureData in class org.apache.poi.xssf.usermodel.XSSFWorkbook in class com.cittec.facturas.excel.GeneradorListadosPruebas X
Error(50,5): CellStyle not found in class org.apache.poi.xssf.usermodel.XSSFCellStyle in class com.cittec.facturas.excel.GeneradorListadosPruebas X
Error(51,5): Font not found in class org.apache.poi.xssf.usermodel.XSSFFont in class com.cittec.facturas.excel.GeneradorListadosPruebas X
Error(175,9): Cell not found in class org.apache.poi.xssf.usermodel.XSSFCell in class com.cittec.facturas.excel.GeneradorListadosPruebas X
Error(176,9): RichTextString not found in class com.cittec.facturas.excel.GeneradorListadosPruebas X