import java.io.File;
import java.io.FileOutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFDataFormatter;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/**
* 创建movieExcel* @param movieList 影片list
* @param path 保存地址
* @return true 成功 false 失败
*/
public static boolean CreateMovieDetailExcel(List<Movie> movieList,String path){
boolean flag = true;
try {
XSSFWorkbook wb = new XSSFWorkbook(); // 创建Excel的工作 Workbook
XSSFSheet sheet = wb.createSheet("sheet1"); // 创建Excel的工作sheet
CreationHelper createHelper = wb.getCreationHelper();
CellStyle cellStyle1 = wb.createCellStyle();
cellStyle1.setDataFormat(createHelper.createDataFormat().getFormat("yyyy/mm/dd HH:mm:ss"));
CellStyle cellStyle2 = wb.createCellStyle();
cellStyle2.setDataFormat(createHelper.createDataFormat().getFormat("yyyy/mm/dd"));
XSSFRow row = sheet.createRow(0); // 创建Excel的sheet的一行
XSSFCell cell0 = row.createCell(0); // 创建一个Excel的单元格
cell0.setCellValue("序号");
row.createCell(1).setCellValue("影片编号");
row.createCell(2).setCellValue("影片名");
row.createCell(3).setCellValue("影片类型");
row.createCell(4).setCellValue("文件格式");
row.createCell(5).setCellValue("导演");
row.createCell(6).setCellValue("演员");
row.createCell(7).setCellValue("上映日期");
row.createCell(8).setCellValue("版权购买日");
row.createCell(9).setCellValue("版权到期日");
row.createCell(10).setCellValue("创建日期");
row.createCell(11).setCellValue("国家/地区");
row.createCell(12).setCellValue("分钟");
row.createCell(13).setCellValue("豆瓣评分");
row.createCell(14).setCellValue("分类");
row.createCell(15).setCellValue("简介");
row.createCell(16).setCellValue("海报");
DateFormat dformat = new SimpleDateFormat("yyyy-MM-dd");
int i = 0;
for(Movie movie : movieList){
i++;
row = sheet.createRow(i);
row.createCell(0).setCellValue(i);
row.createCell(1).setCellValue(movie.getMid());
row.createCell(2).setCellValue(movie.getMovie_name());
int movie_type = movie.getMovie_type();
String _movie_type = "";
if(movie_type == 1){
_movie_type = "自制节目";
}else if(movie_type == 2){
_movie_type = "节目中心";
}else{
_movie_type = "七天大片";
}
row.createCell(3).setCellValue(_movie_type);
String movieformat = "AC3";
if(movie.getMovieformat().equals("1")){
movieformat = "PCM";
}
row.createCell(4).setCellValue(movieformat);
row.createCell(5).setCellValue(movie.getDirector());
row.createCell(6).setCellValue(movie.getCast());
row.createCell(7).setCellValue(movie.getPublishdate().substring(0, movie.getPublishdate().indexOf(" ")));
row.createCell(8).setCellValue(dformat.format(movie.getMovie_starttime()));
row.createCell(9).setCellValue(dformat.format(movie.getMovie_endtime()));
row.createCell(10).setCellValue(movie.getCreatetime());
row.createCell(11).setCellValue(movie.getCountry());
row.createCell(12).setCellValue(movie.getFilmlength());
row.createCell(13).setCellValue(movie.getScore());
row.createCell(14).setCellValue(movie.getCategory());
row.createCell(15).setCellValue(movie.getBrief());
row.createCell(16).setCellValue(movie.getPoster());
}
FileOutputStream os = new FileOutputStream(path);
wb.write(os);
os.close();
} catch (Exception e) {
flag = false;
}
return flag;
}