日期:2014-05-18 浏览次数:20721 次
public static String writeExcel(List listtitle, List listtype, List listcontent,List<Integer> widths,
List<Boolean> iswrap, String filedirpath, String filesavename, String title, int titlesize) {
File filepath = new File(filedirpath);
if (filepath.exists()) {
// log.info("路径已经存在!<br/>");
} else {
filepath.mkdir();
}
String sCurrPath = filedirpath + "/" + filesavename ;
// String myfilepath = request.getRealPath(sCurrPath);
File file = new File(sCurrPath);
try {
file.createNewFile();
// 获取文件的URL地址
} catch (Exception e) {
// log.error("创建文件失败!");
}
// 以下开始输出到EXCEL
try {
/************ 创建工作簿 *************/
WritableWorkbook workbook = Workbook.createWorkbook(new File(
sCurrPath));
/************ 创建工作表 *************/
WritableSheet sheet = workbook.createSheet("导出项目", 0);
// sheet.setPageSetup(5,true);
/************ 设置纵横打印(默认为纵打)、打印纸 ******************/
// sheet.setPageSetup(PageOrientation.LANDSCAPE.LANDSCAPE,0,0);
// sheet.setPageSetup(PageOrientation.LANDSCAPE.LANDSCAPE,PaperSize.A4,0,0);
// sheet.addRowPageBreak(12);
jxl.SheetSettings sheetset = sheet.getSettings();
sheetset.setProtected(false);
// sheet.setColumnView(0,5);
// sheet.setColumnView(1,12);
/************** 设置单元格字体 ***************/
WritableFont NormalFont = new WritableFont(WritableFont.ARIAL, 10,WritableFont.BOLD);
WritableFont BoldFont = new WritableFont(WritableFont.ARIAL, 10,WritableFont.BOLD);
WritableFont Font = new WritableFont(WritableFont.ARIAL, 10,WritableFont.NO_BOLD);
/************** 以下设置几种格式的单元格 *************/
// 用于正文居左
WritableCellFormat wcf_left = new WritableCellFormat(NormalFont);