Java to Excel 2
2016-07-26 14:04
405 查看
Use Jar:
poi-3.14-20160307.jar
poi-ooxml-3.14-20160307.jar
poi-ooxml-schemas-3.14-20160307.jar
mlbeans-2.6.0.jar
poi-3.14-20160307.jar
poi-ooxml-3.14-20160307.jar
poi-ooxml-schemas-3.14-20160307.jar
mlbeans-2.6.0.jar
阅读更多
try {
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("sheet1");
XSSFRow row = sheet.createRow(0);
XSSFFont font = workbook.createFont();
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
// Set font into style
XSSFCellStyle style = workbook.createCellStyle();
style.setFont(font);
XSSFCell cellNo = row.createCell(0);
cellNo.setCellValue("No");
cellNo.setCellStyle(style);
XSSFCell cellSeq = row.createCell(1);
cellSeq.setCellValue("Seq");
cellSeq.setCellStyle(style);
XSSFCell cellDocId = row.createCell(2);
cellDocId.setCellValue("DocId");
cellDocId.setCellStyle(style);
XSSFCell cellBrand = row.createCell(3);
cellBrand.setCellValue("Brand");
cellBrand.setCellStyle(style);
XSSFCell cellPubName = row.createCell(4);
cellPubName.setCellValue("Pub Name");
cellPubName.setCellStyle(style);
XSSFCell cellDateTime = row.createCell(5);
cellDateTime.setCellValue("Date Time");
cellDateTime.setCellStyle(style);
XSSFCell cellHeadline = row.createCell(6);
cellHeadline.setCellValue("Headline");
cellHeadline.setCellStyle(style);
XSSFCell cellContent = row.createCell(7);
cellContent.setCellValue("Content");
cellContent.setCellStyle(style);
XSSFCell cellLink = row.createCell(8);
cellLink.setCellValue("链接");
cellLink.setCellStyle(style);
XSSFCell cellAuthor = row.createCell(9);
cellAuthor.setCellValue("消费者");
cellAuthor.setCellStyle(style);
XSSFCell cellUrl = row.createCell(10);
cellUrl.setCellValue("消费者Url");
cellUrl.setCellStyle(style);
XSSFCell cellRegion = row.createCell(11);
cellRegion.setCellValue("省份");
cellRegion.setCellStyle(style);
XSSFCell cellCity = row.createCell(12);
cellCity.setCellValue("城市");
cellCity.setCellStyle(style);
int count = 1;
for(LorealReportBean dongfong : dongfongList){
row = sheet.createRow(count);
cellNo = row.createCell(0);
cellNo.setCellValue(count);
cellSeq = row.createCell(1);
cellSeq.setCellValue(dongfong.getSeq());
cellDocId = row.createCell(2);
cellDocId.setCellValue(dongfong.getDocId());
cellBrand = row.createCell(3);
cellBrand.setCellValue(dongfong.getBrand());
cellPubName = row.createCell(4);
cellPubName.setCellValue(dongfong.getPubname());
cellDateTime = row.createCell(5);
cellDateTime.setCellValue(dongfong.getPubDate());
cellHeadline = row.createCell(6);
cellHeadline.setCellValue(dongfong.getHeadline());
cellContent = row.createCell(7);
cellContent.setCellValue(dongfong.getContent());
cellLink = row.createCell(8);
cellLink.setCellValue(dongfong.getLink());
cellAuthor = row.createCell(9);
cellAuthor.setCellValue(dongfong.getAuthor());
cellUrl = row.createCell(10);
cellUrl.setCellValue(dongfong.getUrl());
cellRegion = row.createCell(11);
cellRegion.setCellValue(dongfong.getRegion());
cellCity = row.createCell(12);
cellCity.setCellValue(dongfong.getCity());
count ++;
}
FileOutputStream fileOutputStream = new FileOutputStream("C:/tmp/dongfong.xlsx");
workbook.write(fileOutputStream);
fileOutputStream.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
相关文章推荐
- java 读取excel 文件 Unable to recognize OLE stream 错误 .
- java excel To json
- java读取excel文件显示Unable to recognize OLE stream
- Using Java to process excel file
- java 读取excel 文件 Unable to recognize OLE stream 错误
- java 读取excel 文件 Unable to recognize OLE stream 错误
- java读取Excel 错误: jxl.read.biff.BiffException: Unable to recognize OLE stream
- java 读取excel 文件 Unable to recognize OLE stream 错误
- Java Excel API - A Java API to read, write and modify Excel(收集)
- java读取Excel 错误: jxl.read.biff.BiffException: Unable to recognize OLE stream
- Java 读取excel 文件 Unable to recognize OLE stream 错误
- java读取Excel 错误: jxl.read.biff.BiffException: Unable to recognize OLE stream
- SB的方法对付SB的java API,处理excel,word经常出现类似于: IOException:Unable to read entire block;
- Apache Project:POI-HSSF - Java API To Access Microsoft Excel Format Files(ZT)
- POI-HSSF and POI-XSSF - Java API To Access Microsoft Excel Format Files
- java 读取excel 文件 Unable to recognize OLE stream 错误
- java读取Excel 错误: jxl.read.biff.BiffException: Unable to recognize OLE stream
- java response to excel (create excel)
- Java 下载解析Excel文件 报错:jxl.read.biff.BiffException: Unable to recognize OLE stream
- java读取Excel 错误: jxl.read.biff.BiffException: Unable to recognize OLE stream