Complete Excel production operations using NPOI Components

Source: Internet
Author: User

In the end, we still need to use NPOi. At the beginning, I used the com component. I found that my computer would not be able to use it if it was not excel-based. Later I changed one of them to use Itextsharp to generate pdf files, but there were several batches of Excel files to be produced, you can only use NPOI. However, this is also a learning method.

1. Let's talk about how I feel about using Com and NPOi components.

NPOI does not need to be installed with Excel, which is also the main reason why I want to change NPOI

The NPOi component produces an Excel file faster than the COM component.

NPOI's operations on Excel are not as powerful as the COM component. It may be something from Microsoft after all. For example, COM can be used to set styles in a region. NPOI seems to have only one cell set.

2. Use Process

(1) how to generate

           strFileName =;             strPath = AppConfigString.FilePath + strFileName+".xls";            HSSFWorkbook workbook = = = =

(2) Excel

                sheet.AddMergedRegion( CellRangeAddress(, , , = sheet.CreateRow(= ()= row.CreateCell(                  cell.CellStyle = styleHead;

The code above indicates to merge 1st rows to 3rd rows, 1st columns to 5th columns of cells, set the height to 28.5, and then assign values and set styles to the merged cells.

Of course, you can also assign values to a cell without merging. In this case, the code in the first line will be removed.

                                sheet.SetColumnWidth(, ()(( + ) * ));                sheet.SetColumnWidth(, ()(( + ) * ));                sheet.SetColumnWidth(, ()(( + ) * ));

              ICellStyle style == HorizontalAlignment.CENTER;                style.VerticalAlignment = VerticalAlignment.CENTER;                style.WrapText = ;                style.BorderBottom = CellBorderType.THIN;                style.BorderLeft = CellBorderType.THIN;                style.BorderRight = CellBorderType.THIN;                style.BorderTop = CellBorderType.THIN;                style.FillForegroundColor = HSSFColor.YELLOW.index;                style.FillPattern = FillPatternType.SOLID_FOREGROUND;                IFont font == = = .MaxValue;                style.SetFont(font);

               IBeginCount = ;                 IColumnCount = ;                 ITotalCount = dt.Rows.Count;                 IFoot = IBeginCount + ITotalCount;                 ( i = IBeginCount; i < IBeginCount + ITotalCount; i++= ( j = ; j < IColumnCount; j++=- (j == ==

 

The above four operations can generate basic excel files.

 

3. My own research

The following are some of my own research processes. I am not sure about some of them yet.

 

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.