`
roddy
  • 浏览: 16875 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

Java to Excel 2

    博客分类:
  • Java
 
阅读更多
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
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();  
			        }



分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics