日期:2014-05-17  浏览次数:20983 次

C#控制Excel的打印格式

Excel.Application appExcel=new Excel.Application(); 
Excel.Workbook workbook=appExcel.Application.Workbooks.Add(true); 
appExcel.Visible = true; 
 
//工作薄所在的位置(第一个工作薄) 
Excel.Worksheet xlSheet = (Excel.Worksheet)workbook.Worksheets.get_Item(1); 
 
//上边距 
double top = 0; 
//左边距 
double left = 0; 
//右边距 
double right = 0; 
下边距 
double footer = 0; 
 
xlSheet.DisplayAutomaticPageBreaks = true;//显示分页线    
xlSheet.PageSetup.CenterFooter = "第   &P   页,共   &N   页"; 
xlSheet.PageSetup.TopMargin = appExcel.InchesToPoints(top / 2.54);//上 
xlSheet.PageSetup.BottomMargin = appExcel.InchesToPoints(footer / 2.54);//下 
xlSheet.PageSetup.LeftMargin = appExcel.InchesToPoints(left / 2.54);//左 
xlSheet.PageSetup.RightMargin = appExcel.InchesToPoints(right / 2.54);//右 
xlSheet.PageSetup.CenterHorizontally = true;//水平居中   xlSheet.PageSetup.PrintTitleRows = "$1:$3";//顶端标题行    
xlSheet.PageSetup.PaperSize = Excel.XlPaperSize.xlPaperA3;//A3纸张大小   xlSheet.PageSetup.Orientation = Excel.XlPageOrientation.xlLandscape;//纸张方向.横向
?