/**
* 导出/入料件与企业版本号关系表
* @param request
* @param response
* @param doExportCopyRightExcel
*/
@Override
public void getDoExportCopyRightExcelInformationApi(HttpServletRequest request, HttpServletResponse response, DoExportCopyRightExcel doExportCopyRightExcel) {
InputStream is=null;
ByteArrayOutputStream os=null;
ServletOutputStream out1=null;
try{
List<DoExportCopyFeignDTO> data = exportDomainSecortDevelopOra8FeignClient.doExportCopyRightExcelInformationApi(doExportCopyRightExcel).getData();
HSSFWorkbook hssfWorkbook = new HSSFWorkbook();
HSSFSheet hssfSheet = hssfWorkbook.createSheet();
HSSFRow row = hssfSheet.createRow(0);
row.createCell(0).setCellValue("账套编号");
row.createCell(1).setCellValue("成品内部货号编号");
row.createCell(2).setCellValue("成品内部货号");
row.createCell(3).setCellValue("成品货号描述");
row.createCell(4).setCellValue("料件货号编号");
hssfSheet.setColumnWidth(0,20*256);
hssfSheet.setColumnWidth(1,20*256);
hssfSheet.setColumnWidth(2,20*256);
hssfSheet.setColumnWidth(3,20*256);
hssfSheet.setColumnWidth(4,20*256);
int i = 1;
for(DoExportCopyFeignDTO cdfListDto:data){
HSSFRow hssfRow = hssfSheet.createRow(i++);
hssfRow.createCell(0).setCellValue(cdfListDto.getIncn());
if (cdfListDto.getSitm()==null){
hssfRow.createCell(1).setCellValue(cdfListDto.getSitm());
}else {
hssfRow.createCell(1).setCellValue(cdfListDto.getSitm().trim());
}
if (cdfListDto.getVern()==null){
hssfRow.createCell(2).setCellValue(cdfListDto.getVern());
}else {
hssfRow.createCell(2).setCellValue(cdfListDto.getVern().trim());
}
if (cdfListDto.getLogn1()==null){
hssfRow.createCell(3).setCellValue(cdfListDto.getLogn1());
}else {
hssfRow.createCell(3).setCellValue(cdfListDto.getLogn1().trim());
}
if (cdfListDto.getDate1()==null){
hssfRow.createCell(4).setCellValue(cdfListDto.getDate1());
}else {
hssfRow.createCell(4).setCellValue(cdfListDto.getDate1().trim());
}
}
os = new ByteArrayOutputStream();
hssfWorkbook.write(os);
byte[] content = os.toByteArray();
is = new ByteArrayInputStream(content);
response.reset();
response.setContentType("application/vnd.ms-excel;charset=utf-8");
response.setHeader("Content-Disposition", "attachment;filename="+ new String(("货号料件企业版本号.xls").getBytes(), "UTF-8"));
response.setHeader("Access-Control-Allow-Origin","*");
out1 = response.getOutputStream();
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
bis = new BufferedInputStream(is);
bos = new BufferedOutputStream(out1);
byte[] buff = new byte[2048];
int bytesRead;
// Simple read/write loop.
while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff, 0, bytesRead);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (bis != null) {
bis.close();
}
if (bos != null) {
bos.close();
}
}
catch (Exception e){
e.printStackTrace();
}finally {
try {
if (is != null) {
is.close();
}
if (os != null) {
os.close();
}
if (out1 != null) {
out1.close();
}
}catch (Exception e){
e.printStackTrace();
}
}
}
导出excel---Demo
最新推荐文章于 2023-05-31 15:45:43 发布