0
我打开和写在一个Excel xlsx文件,并且每件事情似乎工作正常,但是当我打开文件以查看结果时,列没有我期望的信息 。写入xlsx Excel文件时出错。与apache poi
只有前两列有信息。而第二栏则有相应的值。
你能告诉我我的错误在哪里吗?
在POI上有错误吗?
这是我的代码。
String exceloutp = "filename.xlsx"; //File name where to write the values.
File fileop = new File(exceloutp);
FileInputStream fs = new FileInputStream(exceloutp);
XSSFWorkbook wb = new XSSFWorkbook(fs);
// get a reference to the worksheet
XSSFSheet sheet = wb.getSheetAt(0);
Iterator it = dataResultados.iterator();
BeanResultadosPaginaFormato27 b = null;
XSSFCell cell = null;
//Create style for the cells
XSSFCellStyle normalFormat = wb.createCellStyle();
normalFormat.setBorderBottom(CellStyle.BORDER_THIN);
normalFormat.setBorderTop(CellStyle.BORDER_THIN);
normalFormat.setBorderLeft(CellStyle.BORDER_THIN);
normalFormat.setBorderRight(CellStyle.BORDER_THIN);
normalFormat.setAlignment(CellStyle.ALIGN_LEFT);
XSSFFont normalFont = wb.createFont();
normalFont.setFontHeightInPoints((short) 8);
normalFont.setFontName("Arial");
normalFormat.setFont(normalFont);
//end create a style for the cells.
//Start filling the cells in every row width data.
//starting from line 26.
fila = 26;
columna = 0;
while((fila < 47) && (it.hasNext()))
{
columna = 0;
b = (BeanResultadosPaginaFormato27) it.next();
cell = null;
cell = sheet.getRow(fila).createCell(columna++);
cell.setCellType(Cell.CELL_TYPE_STRING);
cell.setCellStyle(normalFormat);
cell.setCellValue(b.getParametro());//String 1st column
cell = sheet.getRow(fila).createCell(columna++);
cell.setCellType(Cell.CELL_TYPE_STRING);
cell.setCellStyle(normalFormat);
cell.setCellValue(b.getUnidad());//String 2nd column
cell = sheet.getRow(fila).createCell(columna++);
cell.setCellType(Cell.CELL_TYPE_STRING);
cell.setCellStyle(normalFormat);
cell.setCellValue(b.getMetodologia());//String 3rd column
cell = sheet.getRow(fila).createCell(columna++);
cell.setCellType(Cell.CELL_TYPE_STRING);
cell.setCellStyle(normalFormat);
cell.setCellValue(b.getUsuario());//String
cell = sheet.getRow(fila).createCell(columna++);
cell.setCellType(Cell.CELL_TYPE_STRING);
cell.setCellStyle(normalFormat);
cell.setCellValue(b.getConcentracion());//String
cell = sheet.getRow(fila).createCell(columna++);
cell.setCellType(Cell.CELL_TYPE_STRING);
cell.setCellStyle(normalFormat);
cell.setCellValue(b.getLimites()); //String
fila++; //Next row.
}
//------End filling cells with data.
//Save the file and open.
OutputStream out = response.getOutputStream();
response.setHeader("Pragma", "no-cache");
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename=\""+ fileop.getName() +"\"");
wb.write(out);
out.flush();
out.close();
你看到一个错误?
谢谢你的帮助。