在使用C#.NET生成的Excel表中显示页码 [英] Display page numbers in a excel sheet generated using C#.NET

查看:466
本文介绍了在使用C#.NET生成的Excel表中显示页码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人想知道如何在使用C#代码生成的Excel表中包含或输入页码。



我使用Microsoft.Office中可用的库.Interop.Excel来生成文件。



然而默认情况下,输出中我看不到页码。我知道通过



excel选项(View - > Header and Footer ...)启用此功能,但是我想通过C#自动执行此操作。



这是可能的,如果是,请同意分享该片段。



感谢
常规学习者

解决方案

如果我不知道如何在Office中编写代码,我将我的操作记录为一个宏,然后我查看生成的代码内置Visual Basic编辑器。这是为添加页码而生成的相关代码:

  ActiveSheet.PageSetup.CenterFooter =Page& P & N

LeftFooter和RightFooter也可用。


Does anyone have an idea on how to include or input the page numbers in the excel sheet generated using C# code.

I use the libraries available in Microsoft.Office.Interop.Excel to generate the file.

However by default in the output i cannot see the page numbers. I know to enable this via

excel options (View --> Header and Footer ...) but i want to automate this via C#.

Is this possible, if yes kindly share the snippet for the same.

Thanks Constant Learner

解决方案

If I don't know how to code something in Office, I record my action as a macro and then I look at the generated code in the built-in Visual Basic editor. This is the relevant code it generated for adding a footer with page numbers:

ActiveSheet.PageSetup.CenterFooter = "Page &P of &N"

LeftFooter and RightFooter are also available.

这篇关于在使用C#.NET生成的Excel表中显示页码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆