当前位置: 代码迷 >> Java Web开发 >> 如何让导出的EXCEL单元格是数字型的?
  详细解决方案

如何让导出的EXCEL单元格是数字型的?

热度:120   发布时间:2010-07-01 10:26:50.0
如何让导出的EXCEL单元格是数字型的?
代码如下:
WritableWorkbook copy = Workbook.createWorkbook(new File(Constant.LILE_UPLOAD_PLAN_FOLDER+sDate+"-"+user.getRole().getKcppai()+"-销售日报.xls"));
            //第0个sheet是
            WritableSheet sheet = copy.createSheet("销售日报", 0);  
            //样式
            WritableFont font = new WritableFont(WritableFont.TIMES, 8);
            font.setColour(Colour.RED);// 红色字体
            WritableCellFormat format = new WritableCellFormat(font);
            sheet.addCell(new Label(0,0,"系列",this.getAllUCell()));
            sheet.mergeCells(0, 0, 0, 1);//第一个参数为列起始下标,第二个参数为行起始下标,第三个参数为列终止下标,第四个参数为行终止下标
            sheet.addCell(new Label(1,0,"月",this.getAllUCell()));
            sheet.mergeCells(1, 0, 5, 0);
            sheet.addCell(new Label(6,0,"年",this.getAllUCell()));
            sheet.mergeCells(6, 0, 8, 0);
            sheet.addCell(new Label(1,1,"月初库存",this.getAllUCell()));
            sheet.addCell(new Label(2,1,"入库",this.getAllUCell()));
            sheet.addCell(new Label(3,1,"开发票",this.getAllUCell()));
            sheet.addCell(new Label(4,1,"销售额(万元)",this.getAllUCell()));
            sheet.addCell(new Label(5,1,"月末库存",this.getAllUCell()));
            sheet.addCell(new Label(6,1,"年入库",this.getAllUCell()));
            sheet.addCell(new Label(7,1,"年开发票",this.getAllUCell()));
            sheet.addCell(new Label(8,1,"年销售额(万元)",this.getAllUCell()));
            
            for(int i=0; i<dataList.size();i++){                    
                ReportInterim dt = dataList.get(i);                    
                sheet.addCell(new Label(0,i+2,dt.getChar2(),this.getAllUCell()));
                sheet.addCell(new Label(1,i+2,dt.getChar3(),this.getAllUCell()));
                sheet.addCell(new Label(2,i+2,dt.getChar4(),this.getAllUCell()));
                sheet.addCell(new Label(3,i+2,dt.getChar5(),this.getAllUCell()));
                sheet.addCell(new Label(4,i+2,dt.getChar6(),this.getAllUCell()));
                sheet.addCell(new Label(5,i+2,dt.getChar7(),this.getAllUCell()));
            }

上面代码导出的excel单元格都是文本型的,无法参加计算,如何让导出的格式为数字型的?急等解答,谢谢
搜索更多相关主题的帖子: EXCEL  数字  单元  

----------------解决方案--------------------------------------------------------
你写的应该是用了JXL,在JXL中cell这个接口有好几个实现类,有关于日期的,关于数字的等,你使用的 sheet.addCell(new Label(1,1,"月初库存",this.getAllUCell()));
的Label就是专门处理文本的,要是数字可以看看cell这个接口有一个实现类是Number.可以这样写:sheet.addCell(new Number(1,1,5.8));
----------------解决方案--------------------------------------------------------
  相关解决方案