Overview
Setting up pagination for Excel tables is handy for previewing and printing documents, especially for irregular forms that contain a lot of complex data, and the page breaks play a great role in ensuring that the typography of each page is printed or the integrity of the data's pre-and post-connection. Therefore, this article describes the way that C # sets up Excel paging. Of course, for page breaks already in an Excel table, if we can also delete the pagination ourselves as needed.
Example Essentials Grooming
- Insert Paging
1.1 Inserting a horizontal page-out
1.2 Inserting a vertical page-out
- Delete Paging
2.1 Remove all pagination
2.2 Delete specified paging
Code actions and effects
First, insert Excel paging
C#
using Spire.Xls;namespace ExcelPageBreak_XLS{ class Program { static void Main(string[] args) { //实例化一个Wordbook类对象,并加载需要设置分页的Excel文档 Workbook workbook = new Workbook(); workbook.LoadFromFile("Sample.xlsx"); //获取第一个工作表 Worksheet sheet = workbook.Worksheets[0]; //插入两个横向分页符(指定单元格上方插入分页) sheet.HPageBreaks.Add(sheet.Range["A11"]); sheet.HPageBreaks.Add(sheet.Range["A20"]); //插入一个纵向分页符(指定单元格左侧插入分页) //sheet.VPageBreaks.Add(sheet.Range["E1"]); //将视图设置为分页预览模式查看效果 sheet.ViewMode = ViewMode.Preview; //保存并打开文档 workbook.SaveToFile("AddPageBreak.xlsx", FileFormat.Version2010); System.Diagnostics.Process.Start("AddPageBreak.xlsx"); } }}
Add pagination
1. Horizontal page-out effect
2. Vertical page-out effect
Second, delete paging
using Spire.Xls;namespace DeletePageBreak_XLS{ class Program { static void Main(string[] args) { //创建一个Workbook类对象,并加载Excel文档 Workbook workbook = new Workbook(); workbook.LoadFromFile("sample.xlsx"); //获取第一个worksheet Worksheet sheet = workbook.Worksheets[0]; //删除所有横向分页 sheet.HPageBreaks.Clear(); //删除第一个横向分页 //sheet.HPageBreaks.RemoveAt(0); //设置分页预览模式查看分页效果 sheet.ViewMode = ViewMode.Preview; //保存并打开文档 workbook.SaveToFile("删除分页1.xlsx",FileFormat.Version2010); System.Diagnostics.Process.Start("删除分页1.xlsx"); } }}
To delete a paging effect:
1. Delete all pagination
2. Delete the specified paging
The free version of Spire.xls for. NET 8.3 is used here, you can download the installation by yourself or nuget, note that when you do code editing, do not forget to reference the Spire.Xls.dll file, DLL files can be obtained in the Bin folder under the installation path.
All of the above is the "C # Insert, delete Excel pagination method" of the entire content, code for reference.
If you want to reprint, please specify the source!
Thanks for reading!
C # Insert, delete Excel page breaks