POI excel 复制模版sheet(包括打印设置)

            HSSFSheet fromsheet = wb.getSheetAt(0); //模版页
            for(int num=0;num<addSheetNum;num++)//新增
            {
                String numStr = String.valueOf(num+2);

                HSSFSheet newsheet = wb.createSheet("第"+numStr+"页");  
                //设置打印参数  
                newsheet.setMargin(HSSFSheet.TopMargin,fromsheet.getMargin(HSSFSheet.TopMargin));// 页边距(上)  
                newsheet.setMargin(HSSFSheet.BottomMargin,fromsheet.getMargin(HSSFSheet.BottomMargin));// 页边距(下)  
                newsheet.setMargin(HSSFSheet.LeftMargin,fromsheet.getMargin(HSSFSheet.LeftMargin) );// 页边距(左)  
                newsheet.setMargin(HSSFSheet.RightMargin,fromsheet.getMargin(HSSFSheet.RightMargin));// 页边距(右  

                HSSFPrintSetup ps = newsheet.getPrintSetup();  
                ps.setLandscape(false); // 打印方向,true:横向,false:纵向(默认)  
                ps.setVResolution((short)600);  
                ps.setPaperSize(HSSFPrintSetup.A4_PAPERSIZE); //纸张类型  
                
                SheetFunc.copyRows(wb, 0, num+1,0 , 46, 0);//复制
                wb.getSheetAt(num+1).setColumnWidth((short)0, (short)2400);//256,31.38
            }
posted @ 2012-05-09 15:16  logzh  阅读(5597)  评论(1编辑  收藏  举报