资源简介
ExcelUtils.java
代码片段和文件信息
package com.ansheng.util;
import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellstyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ExcelUtils {
static final short borderpx = 1;
/**
* 导出excel表格
* @param head
* @param body
* @return
*/
public static HSSFWorkbook expExcel(List head List> body) {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet(“Sheet1“);
HSSFRow row = sheet.createRow(0);
HSSFCell cell= null;
HSSFCellstyle cellstyle = workbook.createCellstyle();
setBorderstyle(cellstyle borderpx);
cellstyle.setFont(setFontstyle(workbook “黑体“ (short) 14));
cellstyle.setAlignment(HSSFCellstyle.ALIGN_CENTER);
for (int i = 0; i cell = row.createCell(i);
cell.setCellValue(head.get(i));
cell.setCellstyle(cellstyle);
}
HSSFCellstyle cellstyle2 = workbook.createCellstyle();
setBorderstyle(cellstyle2 borderpx);
cellstyle2.setFont(setFontstyle(workbook “宋体“ (short) 12));
cellstyle2.setAlignment(HSSFCellstyle.ALIGN_CENTER);
for (int i = 0; i < body.size(); i++) {
row = sheet.createRow(i + 1);
List paramList = body.get(i);
for (int p = 0; p < paramList.size(); p++) {
cell = row.createCell(p);
cell.setCellValue(paramList.get(p));
cell.setCellstyle(cellstyle2);
}
}
for (int i = 0 isize = head.size(); i < isize; i++) {
sheet.autoSizeColumn(i);
}
return workbook;
}
/**
* 文件输出
* @author LiuYang
* @param workbook 填充好的workbook
* @param path 存放的位置
*/
public static void outFile(HSSFWorkbook workbookString pathHttpServletResponse response) {
SimpleDateFormat fdate=new SimpleDateFormat(“yyyyMMdd-HH点mm分“);
path = path.substring(0 path.lastIndexOf(“.“)) + fdate.format(new Date()) + path.substring(path.lastIndexOf(“.“));
OutputStream os=null;
File file = null;
try {
file = new File(path);
String filename = file.getName();
os = new FileOutputStream(file);
response.addHeader(“Content-Disposition“ “attach
- 上一篇:基于jsp的登录系统
- 下一篇:Java(OOP)练习及作业
相关资源
- java培训视频资源获取.zip
- 一个基于androidstudio开发的二手交易平
- java书籍Java从入门到精通(第三版)
- Android开发从入门到精通第2版.rar
- Android智能穿戴设备开发实战详解.ra
- MD5加密的jar包.zip
- androidlog.7z
- java8.txt
- JavaSocket建立连接和发送消息.zip
- java基于socket公共聊天室的实现.zip
- javaismy.txt
- 《Java从入门到精通》第4版光盘资源
- BAT大牛带你深度剖析Android10大开源框
- Java从入门到精通视频+Java架构师vip视
- JAVA面试实际项目经验.rar
- 2015年传智播客java第33期全套完整.tx
- 轻量级JavaEE企业级应用实战.txt
- 毕向东javaSE基础视频35天.txt
- JetbrainsCrack-2.6.10-release-enc.jar
- C开发Android应用实战_pdf_以及.zip
- jAVA从入门到精通.docx
- 百度网盘javaEE.txt
- Android安卓开发全套112GB教程很全.txt
- SMS4国密封装接口直接可用java.zip
- Android 仿QQ侧滑删除—一个满足ListVi
- 企业快信java.rar
- zw_huangyx123456-10303904-基于Java的迷宫程
- zw_page_sh_null_jar.zip
- zw_mysql-connector-java-5.1.7-bin.zip
- 轻量级javaee企业应用实战第四版.doc
评论
共有 条评论