C # Insert, delete Excel page breaks

Source: Internet
Author: User

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
    1. Insert Paging
      1.1 Inserting a horizontal page-out
      1.2 Inserting a vertical page-out
    2. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.