读书人

C#统制Excel的打印格式

发布时间: 2012-11-08 08:48:11 作者: rapoo

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;//纸张方向.横向
?

读书人网 >C#

热点推荐