package com.wls.excel;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.List;
import jxl.Workbook;
import jxl.format.Colour;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import com.wls.app.pojo.TestBean;
import com.wls.app.service.TestService;
import com.wls.app.service.impl.TestServiceImpl;
public class TestExcel {
public static void main(String[] args) {
try{
// WritableWorkbook book=Workbook.createWorkbook(new File("D:/wap18日销量.xls"));
OutputStream os = new FileOutputStream("D:/wap.xls");
WritableWorkbook book=Workbook.createWorkbook(os);
//生成名为"第一页"的工作表,参数0表示这是第一页
WritableSheet sheet=book.createSheet("第一页",0);
//设置字体为宋体,16号字,加粗,颜色为红色
WritableFont font1=new WritableFont(WritableFont.createFont("宋体"),10,WritableFont.NO_BOLD);
font1.setColour(Colour.RED);
WritableCellFormat format1=new WritableCellFormat(font1);
format1.setAlignment(jxl.format.Alignment.CENTRE);
format1.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
Label labelA = new Label(0,0,"姓名",format1);
Label labelB = new Label(1,0,"年龄",format1);
Label labelC = new Label(2,0,"性别",format1);
Label labelD = new Label(3,0,"地址",format1);
//将定义好的单元格添加到工作表中
sheet.addCell(labelA);
sheet.addCell(labelB);
sheet.addCell(labelC);
sheet.addCell(labelD);
//写入数据并关闭文件
book.write();
book.close();
System.out.println("创建文件成功!");
}catch(Exception e)
{
System.out.println(e);
}
}
}