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.