jxl写excel文件

 

以下内容转自:http://www.blogjava.net/ctguzhupan/archive/2006/10/27/73886.html

 

package com.zhupan.util;

import java.io.OutputStream;
import java.util.List;

import jxl.Workbook;
import jxl.format.Colour;
import jxl.format.UnderlineStyle;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import com.ctgusec.model.Course_info;
import com.ctgusec.model.Student_info;

public class ExcelBean {

    
public String expordExcel(OutputStream os, List courseList,List studentList)
            
throws Exception {

        WritableWorkbook wbook 
= Workbook.createWorkbook(os); // 建立excel文件
        String tmptitle = "课程“"+((Course_info)courseList.get(0)).getCource_name()+"”的选课学生列表"// 标题
        WritableSheet wsheet = wbook.createSheet("第一页"0); // sheet名称
        
// 设置excel标题
        WritableFont wfont = new WritableFont(WritableFont.ARIAL, 16,
                WritableFont.BOLD, 
false, UnderlineStyle.NO_UNDERLINE,
                Colour.BLACK);
        WritableCellFormat wcfFC 
= new WritableCellFormat(wfont);
        wsheet.addCell(
new Label(10, tmptitle, wcfFC));
        wfont 
= new jxl.write.WritableFont(WritableFont.ARIAL, 14,
                WritableFont.BOLD, 
false, UnderlineStyle.NO_UNDERLINE,
                Colour.BLACK);
        wcfFC 
= new WritableCellFormat(wfont);
        
// 开始生成主体内容                
        wsheet.addCell(new Label(02"课程名称"));
        wsheet.addCell(
new Label(12"学 号"));
        wsheet.addCell(
new Label(22"姓 名"));
        wsheet.addCell(
new Label(32"性 别"));
        wsheet.addCell(
new Label(42"学 院"));
        wsheet.addCell(
new Label(52"班 级"));
        wsheet.addCell(
new Label(62"专 业"));
        wsheet.addCell(
new Label(72"备 注"));
        
for(int i=3;i<studentList.size()+3;i++)
        
{
            wsheet.addCell(
new Label(0, i, ((Course_info)courseList.get(0)).getCource_name()));
            wsheet.addCell(
new Label(1, i, ((Student_info)studentList.get(0)).getStudentID()));
            wsheet.addCell(
new Label(2, i, ((Student_info)studentList.get(0)).getName()));
            wsheet.addCell(
new Label(3, i, ((Student_info)studentList.get(0)).getSex()));
            wsheet.addCell(
new Label(4, i, ((Student_info)studentList.get(0)).getUnit()));
            wsheet.addCell(
new Label(5, i, ((Student_info)studentList.get(0)).getClass_()));
            wsheet.addCell(
new Label(6, i, ((Student_info)studentList.get(0)).getSpecialty()));
            wsheet.addCell(
new Label(7, i, ((Student_info)studentList.get(0)).getRemark()));
        }
        
        
// 主体内容生成结束        
        wbook.write(); // 写入文件
        wbook.close();
        os.close();
        
return "success";
    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值