package com.poi.excel;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
public class CreateExcel {
public static void create()
{
//创建工作表
HSSFWorkbook wb=new HSSFWorkbook();
//创建第一个工作区
HSSFSheet sheet=wb.createSheet("周工作报表");
//创建标题行
HSSFRow row=sheet.createRow(0);
//创建第一行的第一个单元格
HSSFCell cell=row.createCell(0);
cell.setCellValue("序号");
cell=row.createCell(1);
cell.setCellValue("星期一");
cell=row.createCell(2);
cell.setCellValue("星期二");
cell=row.createCell(3);
cell.setCellValue("星期三");
cell=row.createCell(4);
cell.setCellValue("星期四");
cell=row.createCell(5);
cell.setCellValue("星期五");
cell=row.createCell(6);
cell.setCellValue("星期六");
cell=row.createCell(7);
cell.setCellValue("星期日");
List list=new ArrayList();
list.add("开会");
list.add("下订单");
list.add("拜访客户");
list.add("研讨");
list.add("再次拜访");
list.add("达成协议");
list.add("签署协议");
for (int i = 0; i < list.size(); i++) {
row=sheet.createRow(i+1);
cell=row.createCell(0);
cell.setCellValue(i+1);
cell=row.createCell(1);
cell.setCellValue(list.get(0).toString());
cell=row.createCell(2);
cell.setCellValue(list.get(1).toString());
cell=row.createCell(3);
cell.setCellValue(list.get(2).toString());
cell=row.createCell(4);
cell.setCellValue(list.get(3).toString());
cell=row.createCell(5);
cell.setCellValue(list.get(4).toString());
cell=row.createCell(6);
cell.setCellValue(list.get(5).toString());
cell=row.createCell(7);
cell.setCellValue(list.get(6).toString());
}
File f=new File("计划书11.xls");
try {
wb.write(new FileOutputStream(f));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
CreateExcel.create();
}
}