Author: Tony Qu
Introduction: How is NPOI? Please read this article
Many people know that NPOI is in Excel 97-2003.xls format. Now, after more than a year of hard work by the Team, NPOI 2.0 officially meets with you, so that NPOI will redefine itself as an Excel and Word reader. You are not mistaken. NPOI officially began to support docx in Word2007 or later versions, and also began to support xlsx in Excel 2007 or later versions ). Currently, NPOI's support for docx is still in beta stage and there are still many problems, but in the official version, we will try to ensure its stability.
What is the difference between Open Xml SDK and NPOI?
The Open Xml SDK is a read/write library of Microsoft Office 2007 or above, and the latest version is 2.5. It is reasonable to say that Microsoft should have a good advantage, but unfortunately, there is an unwritten assumption to use this stuff-that is, you are familiar with the Open Xml format and have a thorough understanding of it; otherwise, it cannot be used at all. However, I have to admit that the built-in productivity tool is quite useful. I also use this tool in NPOI development because it can help verify the correctness of the generated file, it is helpful for me to fix the NPOI bug. NPOI is not based on the Microsoft library. It is completely independent, even System. IO. packaging is useless to ensure that NPOI can run in. in the net 2.0 and Mono environments, NPOI implements a set of functions similar to System. IO. packaging is called OpenXml4Net and OpenXml4j in POI ). The role of this object is to manage the Part relations in the Open Xml format. Otherwise, an Open xml file cannot be maintained. Although we all know that the open xml file is essentially a zip file, it doesn't mean that you can maintain the open xml file package with the zip library. NPOI also provides excellent upper-layer encapsulation, which is transparent to users who need Open xml, that is, you do not need to understand what Open Xml is. However, if you use Open Xml sdk, you must understand everything about Open Xml. In addition, the Open Xml SDK does not support many advanced operations, such as formula calculation, because the Open Xml SDK believes that these operations should be managed by Excel itself and are part of the UI function, instead of using sdks, the product manager does not understand the technology. Therefore, such practical functions are not implemented in the Excel generate library ).
In fact, NPOI was not planning to support the Open Xml file format in the early days, because I saw Microsoft launched the Open Xml SDK and thought it was basically out of the market, unfortunately, Microsoft did not invest much in it and encapsulated it. After five years, it finally came out of Open Xml SDK 2.5, and the result was still quite frustrating. In addition, we can see that the EPPlus library is very popular. However, due to the license issue, we decided to reconsider the expansion of NPOI to regain this market.
What functions does NPOI 2.0 provide?
First, it naturally supports reading and writing docx and xlsx. Currently, only Excel 2010 and Word 2010 are supported. Although in theory, most of the functions of Excel 2013 are available, however, some foreign programmers report that the files generated in Excel 2013 may have some minor problems. For example, the comment box will become an arrow rather than a rectangle. It is good to open the same file in Excel 2010.
Second, it supports creating charts such as point charts in Excel 2007 ). Currently, the number of supported chart types is relatively small, and other chart types will be added in 2.1.
Third, it supports formula calculation during running. This is a legacy NPOI feature, but now it supports both Excel 2003 and 2007.
Fourth, yes.. NET 2.0 sp1 support for vs2008 or later versions), Microsoft's official Open Xml SDK and most Open source OOXML libraries are only supported. NET 3.0 or later versions, because they use. system. IO. packaging, so it cannot be supported. net 2.0. I don't want to boast that this is the world's first open-source OpenXml read/write library supporting. net 2.0.
Fifth, the intelligent Excel format detection is implemented through WorkbookFactory. This class is a classic factory mode. You need to input the file path. This class will help you create XSSFWorkbook or HSSFWorkbook, but the IWorkbook interface is returned.
Sixth, it also provides four Release versions:. net 2.0,. net 4.0, mono. net 2.0, and mono. net 4.0, which are convenient for users in different projects. Of course, this version will be provided on nuget. It is still a little early, because the official version is not available yet.
How fast is NPOI for old users getting started with 2.0
If you are an old NPOI user, I can assure you that you can get started with NPOI 2.0 within one day, because NPOI ensures that the Read and Write interfaces in the Excel 2003 and Excel 2007 formats are consistent, for example, if you used HSSFWorkbook, you only need to change it to IWorkbook. If you used HSSFRow, you only need to change it to IRow, and so on. Basically, if you do not use the Excel 2007 enhancement feature 2003, you do not need to directly operate XSSFWorkbook. In fact, NPOI introduced the interface concept at the beginning of 1.2.5, but its significance was far from that at the time. At that time, some users questioned why they wanted to introduce interfaces, because they simply used IWorkbook and HSSFWorkbook, but there is no difference in nature. This is also a problem we often need to consider when designing the architecture. Do we need to use interfaces ?).
XWPF is much more difficult to get started with NPOI users than XSSF, because no Word read/write component in NPOI 1. x, doc read/write component, is not released with the official release, because it is not stable .), Therefore, both old users and new users are completely new. At present, the NPOI team is planning to develop some basic XWPF tutorials to help NPOI users get started with Word read/write operations as soon as possible. Of course, the Word import and export requirements are usually much less than Excel, so most users may not use this module. In this case, users can ignore the XWPF namespace.
Will NPOI continue to be free? Will it be charged?
Although I have been declaring that "open source is not equal to free", NPOI core components will continue to be free and code will remain open source, so don't worry. But starting this year, NPOI will have a series of profitable attempts, including publishing books, providing value-added services, creating NPOI domestic offline communities, and making NPOI global tour speeches. After all, I want to support my family, so it is necessary to make a profit.
This article is from the "Tony Qu" blog, please be sure to keep this source http://tonyqus.blog.51cto.com/2676222/1338656