java后台生成excel文件

public void ExportExcel(Nsxx nsxx,ZcfzList zcfzList,LrxxList lrxxList,XjllList xjllList,String djxh) throws Exception{

	System.out.println(nsxx);
	System.out.println(""+nsxx.getZsfs());
	String fileName = "modelteble.xls";//excel模板路径 
	//String realPath = request.getSession().getServletContext().getRealPath(fileUrl);
	String realPath = modelexcelurl;//模板文件所在文件夹
	File fi = new File(realPath, fileName);
	System.out.println(realPath);
	POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(fi)); 

	//获取项目的webroot路径
	//String pathStr = request.getSession().getServletContext().getRealPath(fileUrl);
	String pathStr =excelUrl;//生成的excel存储地址
	FileOutputStream fos = null;
	try { 
		fos = new FileOutputStream(pathStr+djxh+".xls");
	} catch (FileNotFoundException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}  

	//读取excel模板    
	HSSFWorkbook wb = new HSSFWorkbook(fs); 

	//读取了模板内所有sheet内容    
	HSSFSheet sheet = wb.getSheetAt(0);   //读取报告模板中的第一个sheet页 
	//在相应的单元格进行赋值    
	setCellValue(sheet,2,1,nsxx.getNsrmc()); 

	setCellValue(sheet,3,1,nsxx.getFddbrxm());
	setCellValue(sheet,3,3,nsxx.getFddbryddh());
	setCellValue(sheet,3,5,nsxx.getCwfzrxm());
	setCellValue(sheet,3,7,nsxx.getCwfzryddh());

	//设置单元格为只读  这个是解锁的时候所设置的密码
	//sheet.protectSheet("abcd2019");
	protectSheet(sheet);//将sheet页设置为只读
	
	//资产负债
	//读取了模板内所有sheet内容    
	HSSFSheet sheetzcfz = wb.getSheetAt(1);  
	//在相应的单元格进行赋值    
	setCellValue(sheetzcfz,1,3,zcfzList.getSsrq()); 

	setCellValue(sheetzcfz,2,1,zcfzList.getNsrsbh());
	setCellValue(sheetzcfz,2,5,zcfzList.getNsrmc());

	List List = zcfzList.getZcfzList();
	if(null!=List&&List.size()>0){
		for (int j=0,i=5;j ListLr = lrxxList.getLrxxList();
	if(null!=ListLr&&ListLr.size()>0){
		for (int j=0,i=5;j ListXjl = xjllList.getXjllList();
	if(null!=ListXjl&&ListXjl.size()>0){
		for (int j=0,i=5;j

你可能感兴趣的:(java开发类)