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