java导入导出excel表格
一.导出
public void poiExport(Long[] ids, HttpServletRequest request, HttpServletResponse response) {
String orderBatchSn = "";
// 创建HSSFWorkbook对象(excel的文档对象)
HSSFWorkbook wb = new HSSFWorkbook();
// 建立新的sheet对象(excel的表单)
HSSFSheet sheet = wb.createSheet("身份信息");
// 输出Excel文件
FileOutputStream output = null;
// 在sheet里创建第一行,参数为行索引(excel的行),可以是0~65535之间的任何一个
HSSFRow rowTitle = sheet.createRow(0);
// 创建单元格并设置单元格内容
rowTitle.createCell(0).setCellValue("客户单号");
rowTitle.createCell(1).setCellValue("姓名");
rowTitle.createCell(2).setCellValue("地区");
rowTitle.createCell(3).setCellValue("地址");
rowTitle.createCell(4).setCellValue("手机号");
rowTitle.createCell(5).setCellValue("身份证号");
rowTitle.createCell(6).setCellValue("订单编号");
//表格行数
int i = 1;
if (ids == null || ids.length < 0) {
logger.info("{} requestParam = {} message = {}", method, ids, "主键id为空");
return;
}
//根据具体情况去自己的数据访问层查询需要导出的信息
List<PcOrderDetailResponse> pcOrderListResponse = pcOrderService.findlist(ids);
for (PcOrderDetailResponse order : pcOrderListResponse) {
try {
if (order == null) {
logger.debug("未查到此订单");
continue;
}
String authenticationRealName = order.getAuthenticationRealName();
Long isAuthenticationRealName = order.getIsAuthenticationRealName();
if (authenticationRealName == null) {
logger.debug("订单未做认证处理!");
continue;
}
if (isAuthenticationRealName == 1) {
logger.debug("订单已经鉴权过 ,并且通过!");
continue;
}
// 在sheet里创建第i行
//客户单号customerOrderSn 姓名(收货人)consignee 地区area 地址address 手机号phone 身份证号 card_id 订单编号sn
HSSFRow row = sheet.createRow(i);
row.createCell(0).setCellValue(