When it comes to reading and writing excel through pure. net, the first thing that comes to mind is the well-known npoi. Even Microsoft's official msdn has a dedicated article to introduce its usage. Today, I used the Excel export function in a project and tried it out specially. Although it is powerful enough, it is not easy to use. Probably because of its origins and Java's poi, most of the APIS still have a strong Java flavor. For example, to write data to a cell, createrow () must be created before createcell () can be written. Statements like cells [rowindex, colindex] = value cannot be used in one step.
As a result, I searched the internet. Are you still using npoi in the article "using Excel? Coming soon, linqtoexcel found another library: linqtoexcel. This library can quickly convert the LINQ query results to the Excel format, which is a bit similar to the doddlereport library I have previously introduced. However, it is also limited to this. The complex functions cannot be done, and in most cases cannot meet business needs.
Finally, I found a very powerful library-epplus, which basically has all the functions and friendly APIs. The following is a simple example:
???? Using (var p = newexcelpackage ())
???? {
???????? VaR sheet = P. Workbook. worksheets. Add ("My sheet ");
???????? // The initial index of cells is 1.
???????? Sheet. cells [1, 1]. value = 0;
???????? Sheet. cells [2, 1]. value = 1;
???????? Sheet. cells [3, 1]. value = 2;
???????? Sheet. cells [4, 1]. value = 3;
???????? P. saveas (newfileinfo (@ "R: \ output.xlsx "));
????}
I feel much better than npoi. The effect is as follows:
????
This example is relatively simple, more complex example can refer to this article: http://zeeshanumardotnet.blogspot.com/2010/08/creating-advanced-excel-2007-reports-on.html (need FQ ). Or its official help documentation: http://epplus.codeplex.com/wikipage? Title = FAQ & referringtitle = documentation
Finally, I would like to mention some shortcomings of this library-it only supports the XLSX format and does not support the Excel format of office2003, but it is not a problem now.
Better Excel operation library than npoi -- epplus