问题:VC输出excel数据,设置打印的页脚页码

这次要解决VC输出excel并打印的页面设置页码的问题。

经过搜索发现

可以参考的页面C#的代码:

https://blog.csdn.net/weixin_33895516/article/details/90094350?utm_medium=distribute.pc_relevant.none-task-blog-baidujs-9

摘抄参考代码:

//页面设置
exce.ActiveWindow.DisplayGridlines=false;//不显示网格线
sheets.DisplayAutomaticPageBreaks=true;//显示分页线
sheets.PageSetup.CenterFooter="第&P页,共&N页";
sheets.PageSetup.TopMargin=exce.InchesToPoints(0.590551181102362);//上1.5
sheets.PageSetup.BottomMargin=exce.InchesToPoints(0.590551181102362);//下1.5
sheets.PageSetup.LeftMargin=exce.InchesToPoints(0.78740157480315);//左边距2
sheets.PageSetup.RightMargin=exce.InchesToPoints(0.393700787401575);//右边距1
sheets.PageSetup.HeaderMargin=exce.InchesToPoints(0.393700787401575);//页眉1
sheets.PageSetup.FooterMargin=exce.InchesToPoints(0.393700787401575);//页脚1
sheets.PageSetup.CenterHorizontally=true;//水平居中
sheets.PageSetup.PrintTitleRows="$1:$3";//顶端标题行
sheets.PageSetup.PaperSize=Excel.XlPaperSize.xlPaperA3;//.xlPaperB4;//纸张大小
sheets.PageSetup.Orientation=Excel.XlPageOrientation.xlLandscape;//纸张方向.横向

参考的关键点是:

sheets.PageSetup.CenterFooter="第&P页,共&N页";

 

于是我在我的代码里面做出:

	PageSetup page = sheet.GetPageSetup();

	page.SetCenterFooter("Page &P of &N");

完成打印英文的页脚的页码的内容

该段比较完整的代码如下:

	PageSetup page = sheet.GetPageSetup();

	//设置打印页面方向 0 默认 1 纵向 2 横向
	page.SetOrientation(2);
	//
	page.SetLeftMargin(app.InchesToPoints(0.6));
	page.SetRightMargin(app.InchesToPoints(0.4));
	page.SetTopMargin(app.InchesToPoints(0.5));
	page.SetBottomMargin(app.InchesToPoints(0.6));
	VARIANT vt=(_variant_t)1;
	page.SetFitToPagesWide(vt);
	page.SetCenterFooter("Page &P of &N");

	COleVariant covTrue((short)true);

	COleVariant covFalse((short)FALSE);
//	_Workbook objbook;
	book.PrintOut( covOptional,
		covOptional,
		COleVariant(long(1)),     //打印份数
		covFalse,
		covOptional,
		covOptional,
		covOptional,
		covOptional
		);

	book.Save();
	book.ReleaseDispatch();
	range.ReleaseDispatch();
	sheet.ReleaseDispatch();
	sheets.ReleaseDispatch();

	app.Quit();
	app.ReleaseDispatch();

 

你可能感兴趣的:(VC)