2.6.4 use npoi to Operate Excel -- lock Columns

Source: Internet
Author: User
In Excel, there may be too many columns or too many rows. In this case, you can lock the column to freeze some columns and do not slide with the scroll bar for easy viewing. To freeze columns in an Excel file, follow these steps:

Similarly, using npoi Code The above results can also be achieved: Hssfsheet sheet1 = Hssfworkbook. createsheet ( " Sheet1 " );
Hssfrow row1 = Sheet1.createrow ( 0 );
Row1.createcell ( 0 ). Setcellvalue ( " Freeze Columns " );
Sheet1.createfreezepane ( 1 , 0 , 1 , 0 );

The code execution result is as follows:

The parameters of createfreezepane are described below:
The first parameter indicates the number of columns to be frozen;
The second parameter indicates the number of rows to be frozen. Here, only columns are frozen, so the value is 0;
The third parameter indicates the sequence number of the first column visible in the right area, which is calculated from 1;
The fourth parameter indicates the sequence number of the first line visible in the following area. It is also calculated from 1. Here, the column is frozen, so it is 0;

For example, it may be better understood to set the parameters as follows:

Sheet1.createfreezepane ( 2 , 0 , 5 , 0 );

 

The result is as follows:

Note that the C, D, and E columns in the figure are not visible by default, and can be seen only by scrolling. This is the third parameter 5. Is it easy to understand :)

Next, let's take a look at the effect of freezing rows. Slightly modify the above Code: Hssfsheet sheet1 = Hssfworkbook. createsheet ( " Sheet1 " );
Hssfrow row1 = Sheet1.createrow ( 0 );
Row1.createcell ( 0 ). Setcellvalue ( " Freeze rows " );
Sheet1.createfreezepane ( 0 , 1 , 0 , 1 );

The Excel files generated after execution can be found in:

So how can we freeze rows and columns at the same time? You must be smart ~~

 

Returned directory

 

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.