-
导出excel
- <span style="font-size:18px;">
- public String ToExcel(String sql,String contentTitle,String filepath,String filename) {
- WritableWorkbook workbook = null;
- try{
-
-
- List<Map> list = null;
-
- if(list!=null && list.isEmpty()){
-
- Map<String,String> columnMap = list.get(0);
- Set<String> keySet = columnMap.keySet();
-
-
- File file = new File(filepath);
- if (!file.exists()) {
- file.mkdirs();
- }
-
- filename =file+"/"+filename+ ".xls";
-
- File excelfile = new File(filename);
- excelfile.createNewFile();
- workbook = Workbook.createWorkbook(new FileOutputStream(excelfile));
-
-
-
- WritableSheet sheet = workbook.createSheet("sheet名称", 0);
- Label nL = null;
- jxl.write.WritableFont headerFont = new jxl.write.WritableFont(WritableFont.ARIAL, 18, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLACK);
- jxl.write.WritableCellFormat headerFormat = new jxl.write.WritableCellFormat(headerFont);
- jxl.write.WritableFont titleFont = new jxl.write.WritableFont(WritableFont.ARIAL, 11, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLACK);
- jxl.write.WritableCellFormat titleFormat = new jxl.write.WritableCellFormat(titleFont);
-
-
- nL = new Label(0, 0, contentTitle, headerFormat);
- sheet.addCell(nL);
-
- Label label;
- int index = 0;
- for(String key:keySet){
- nL = new Label(index, 1, key, titleFormat);
- sheet.addCell(nL);
- for (int j = 0; j < list.size(); j++) {
-
- String value = (String) list.get(j).get(key);
-
- Label obj = new Label(index, j + 2, value);
- sheet.addCell(obj);
- }
- index++;
- }
- workbook.write();
- workbook.close();
- }
- }catch(Exception e){
- e.printStackTrace();
- }
- return filename;
- }</span>
-
相关阅读:
rapidjson代码封装类
CEF3.2623使用记录:windows编译
ACE主动对象模式
理解i++和++i
ubuntu安装vmplayer出现问题的解决方法
WinSpy涉及的windows api
winXP下安装opensshd服务
资源下载链接
FPM打包工具
mysql error code
-
原文地址:https://www.cnblogs.com/challengeof/p/4281857.html
Copyright © 2020-2023
润新知