Greetings Im working in a java aplication in a jboss server and I was reading jbos's docs and i found how to export data. (it was very usefull actually ) but i can't find anithying about importing a file. of course i tried to solve this by my way using HSSWorkbook class and this is what I got:
public void saveexcelproducts() {
try {
System.out.println("into try");
HSSFWorkbook libro = new HSSFWorkbook(xlsStr);
// loop page by page , and record by record
HSSFSheet hojita;
HSSFRow filita= null;
xlsTotalCarga = 0;
xlsTotalLista = 0;
erroresExcel = new ArrayList<HashMap>();
cargaExcel = true;
System.out.println("Before first for");
for (int cntHoja = 0; cntHoja < libro.getNumberOfSheets(); cntHoja++) {
hojita = libro.getSheetAt(cntHoja);
System.out.println("first for executed");
if (hojita.getLastRowNum() > 0)
System.out.println("Files found: "+ hojita.getLastRowNum());
//System.out.println("Type of cell: "+ filita.getCell(0).getCellType());
//System.out.println("the number is "+ filita.getCell(0));
System.out.println(" cnthoja > 0 ");
for (int numRow = 1; numRow <= hojita.getLastRowNum(); numRow++) {
System.out.println("Second for");
xlsTotalLista++;
filita = hojita.getRow(numRow);
if (filita.getCell(0) != null && filita.getCell(0).getCellType() != HSSFCell.CELL_TYPE_BLANK
&& filita.getCell(1) != null
&& filita.getCell(1).getCellType() != HSSFCell.CELL_TYPE_BLANK
&& filita.getCell(2) != null
&& filita.getCell(2).getCellType() != HSSFCell.CELL_TYPE_BLANK
&& filita.getCell(4) != null
&& filita.getCell(4).getCellType() != HSSFCell.CELL_TYPE_BLANK
&& filita.getCell(5) != null
&& filita.getCell(5).getCellType() != HSSFCell.CELL_TYPE_BLANK
&& filita.getCell(7) != null
&& filita.getCell(7).getCellType() != HSSFCell.CELL_TYPE_BLANK
&& filita.getCell(8) != null
&& filita.getCell(8).getCellType() != HSSFCell.CELL_TYPE_BLANK
&& filita.getCell(9) != null
&& filita.getCell(9).getCellType() != HSSFCell.CELL_TYPE_BLANK
) {
System.out.println("IF executed");
Marca tmpMrc = marcaHome.registrarMarca(filita.getCell(4).getStringCellValue());
Proveedor tmpPrv = proveedorHome.registrarProveedor(filita.getCell(5).getStringCellValue());
Producto prd = new Producto();
prd.setCodigo(filita.getCell(0).getStringCellValue());
prd.setProveedor(tmpPrv);
prd.setMarca(tmpMrc);
prd.setLineaProducto(lineaProductoHome.registrarLineaProducto(
filita.getCell(2).getStringCellValue() )) ;
prd.setCategoria(categoriaHome
.getCategoria(filita.getCell(3).getStringCellValue()));
prd.setCosto((float) Math.round(new Float(filita.getCell(7).getNumericCellValue()) * 100) / 100);
prd.setTrasegar(Boolean.valueOf(filita.getCell(6).getStringCellValue()));
prd.setExento(false);
prd.setGravable(true);
prd.setNoSujeto(false);
prd.setNombre(filita.getCell(1).getStringCellValue());
prd.setDescripcion(filita.getCell(9).getStringCellValue());
prd.setMadre(buscarMadre(filita.getCell(8).getStringCellValue()));
select(prd);
boolean res = save();
if (!res) {
// Error
// save the product
HashMap<String, String> errUnk = new HashMap<String, String>();
errUnk.put("row", numRow - 1 + "");
errUnk.put("cod", filita.getCell(0).getStringCellValue());
errUnk.put("msg", "Error saving the product.");
errUnk.put("sheet", hojita.getSheetName());
erroresExcel.add(errUnk);
} else
xlsTotalCarga++;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
cargaExcel = false;
setXlsTotalCarga(xlsTotalCarga);
setXlsTotalLista(xlsTotalLista);
setErroresExcel(erroresExcel);
}
apparently all the values in the cell are null (even if they are filled) any help is wellcome
Aucun commentaire:
Enregistrer un commentaire