posts - 24,  comments - 25,  trackbacks - 0

private File upload;

FileInputStream fis 
= new FileInputStream(getUpload());

Workbook workbook 
= Workbook.getWorkbook(fis);

for (int i = 0; i < workbook.getNumberOfSheets(); i++)
            
{
                Sheet sheet 
= workbook.getSheet(i);
                    String sheetName = sheet.getName();
              
// 行
                for (int row = 0; row < sheet.getRows(); row++)
                
{
                  
// 列
                    int columns = sheet.getColumns();
                    
                    Cell cell_1 
= sheet.getCell(0, row);
                 String orderNo = cell_1.getContents().trim();
                    if (cell_1.getType() == CellType.DATE)
                    {
                        DateCell dc = (DateCell) cell_1;
                        date = dc.getDate();
                    }

                }

            }

            workbook.close();


response.setHeader("Content-Disposition""attachment; filename=\"" + fileName + ".xls\"");
        response.setCharacterEncoding(
"utf-8");
        response.setContentType(
"application/actet-stream; charset=utf-8");
        ServletOutputStream os 
= response.getOutputStream();
        
// 创建Excel工作簿。
        WritableWorkbook workbook = Workbook.createWorkbook(os);
        
// 添加一个工作表。
        WritableSheet sheet = workbook.createSheet("sheet 1"0);
        
// 格式化数字和日期
        NumberFormat nf = new NumberFormat("#########");
        DateFormat df 
= new DateFormat("yyyy-MM-dd");
        WritableCellFormat wcfN 
= new WritableCellFormat(nf);
        WritableCellFormat wcfD 
= new WritableCellFormat(df);
for (int i = 0; i < lst.size(); i++)
        
{
            
// Label(列号, 行号 ,内容)。
            sheet.addCell(new Label(0, i + 1, lst.get(i).getOrderNo()));
            sheet.addCell(
new Label(1, i + 1, lst.get(i).getCustomerNo()));
            sheet.addCell(
new Label(2, i + 1, lst.get(i).getAreaName()));
            sheet.addCell(
new Label(3, i + 1, lst.get(i).getCustomerAdress()));
            sheet.addCell(
new DateTime(4, i + 1, lst.get(i).getOutDate(), wcfD));
            sheet.addCell(
new Number(5, i + 1, lst.get(i).getOutBranch(), wcfN));
            sheet.addCell(
new Label(6, i + 1, lst.get(i).getProductNo()));
            sheet.addCell(
new Label(7, i + 1, lst.get(i).getProductName()));
            sheet.addCell(
new Label(8, i + 1, lst.get(i).getLotNo()));
            sheet.addCell(
new Label(9, i + 1, lst.get(i).getUnit()));
            sheet.addCell(
new Number(10, i + 1, lst.get(i).getOutNum(), wcfN));
        }


        workbook.write();
        workbook.close();
posted on 2009-03-27 16:24 Jarry 阅读(350) 评论(0)  编辑  收藏 所属分类: POI-Excel/Word

只有注册用户登录后才能发表评论。


网站导航: