2019独角兽企业重金招聘Python工程师标准>>>
ExcelController
/**
* ExcelController
* @author lenovo
* @version 1.0
*
*/
@RequestMapping("/excel/*")
public class ExcelController extends AbstractAction{
@Autowired
private IYhxwService yhService;
@RequestMapping(value = "exportjl.htm")
@ResponseBody
public void exportjl(HttpServletResponse response,
@RequestParam(value="cBh", required=false) String cBh,
@RequestParam(value="startDate", required=false) String startDate,
@RequestParam(value="endDate", required=false) String endDate
) throws UnsupportedEncodingException{
Map map = new HashMap();
if(!StringUtils.isBlank(cBh)){
cBh = null;
}
map.put("cBh", cBh);
map.put("startDate",
StringUtils.isEmpty(startDate) ? null
: DateUtils.parseDate(startDate));
map.put(
"endDate",
StringUtils.isEmpty(endDate) ? null
: DateUtils.toEndDate(DateUtils.parseDate(endDate)));
List List = yhService.loadListByCondition(map);
SimpleDateFormat exportSdf = new SimpleDateFormat("yyyyMMdd-HHmmss");
String exportTime = exportSdf.format(System.currentTimeMillis());
String fileName = "记录" + exportTime +".xls"; //文件名
String sheetName = "记录";
String []title ={"编号", "用户", "请求", "时间"};
String [][]values = new String[List.size()][];
for(int i=0; i
ExcelUtil
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/**
* ExcelUtil
* @author lenovo
* @version 1.0
*
*/
public class ExcelUtil {
public static XSSFWorkbook getXSSFWorkbook(String sheetName,String []title,String [][]values, XSSFWorkbook wb){
// 第一步,创建一个webbook,对应一个Excel文件
if(wb == null){
wb = new XSSFWorkbook();
}
// 第二步,在webbook中添加一个sheet,对应Excel文件中的sheet
XSSFSheet sheet = wb.createSheet(sheetName);
// 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short
XSSFRow row = sheet.createRow(0);
// 第四步,创建单元格,并设置值表头 设置表头居中
XSSFCellStyle style = wb.createCellStyle();
style.setAlignment(XSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式
XSSFCell cell = null;
//创建标题
for(int i=0;i
pom.xml
org.apache.poi
poi-ooxml
3.16
$('#exportEx').click(function(){
window.location.href="/***/excel/exportjl.htm?cBh="+$('#cBhHide').val()+"&startDate="+$('#startDateHide').val()+"&endDate="+$('#endDateHide').val();
});