This article compares several common frameworks, hoping to provide you with some references when you encounter export requirements. Common export formats include Word, Excel, and PDFs, which are described in the following three formats.
Word
Word is typically used to export analytic summary class reports that include pictures, tables, and so on.
1.JACOB
Jacob's principle is to use the DLL dynamic link library, through the Jndi way to implement the call to the COM program. It requires that the host must be a Windows platform, and when a large number of requests operate simultaneously, there is a certain chance that the deadlock of office resources is made. All kinds of situations are unacceptable to us, so the application is not wide.
2.java2word
Java2word is the component that invokes the MS Office document through the Java API. You can implement various operations such as opening documents, creating documents, inserting pictures, creating tables, and more. But again, it must be available on the Windows platform. So it does not take into account the scope.
3.POI
POI can export Excel, and you can export word. I'm sure a lot of people didn't think of it, but POI's support for word is very limited and you can't set styles. If the exported report format is more complex, this scenario is helpless.
4.FreeMarker
Freemarker is a template tool, and Word is a document. It's actually very simple. Word allows you to convert from office to standard XML format, and the content in Word is an XML tag.
So we can use Office to make Word template, save as XML, the part of which needs to be dynamically generated into variables, and then generated by Freemarker (note that the generated file suffix name to change to. doc or. docx). And what to do with the pictures in Word. The pictures in Word are stored, so just convert the picture to, and then put it on the corresponding variable.
The biggest disadvantage of this approach is that word into XML format, the structure is relatively complex, the production of templates more cumbersome. But in combination, this is the best word export scenario.
Excel
Excel is typically used to export reports of data types. For example, a period of time in the DDoS attack traffic summary. Excel export is more common, online cases are also more, most of them use JXL or poi these two tools.
1.JXL
JXL support for Chinese is very good, and easy to operate. Supports pictures and charts, but support is limited, and pictures only support PNG format. Large amount of data Excel is less efficient when exported.
2.POI
Poi should be the most common scenario in Excel export. It's very comprehensive for Excel and supports the use of formulas, macros. Support for formatting is good, you can define cells in any format. At the same time in the large amount of data Excel generation, the efficiency is very high.
Pdf
The 1.jasper Reportjasper is a more common way to generate PDFs. It's designed to be a template for Mister, and then embed the data into the template. Its disadvantage is that template generation is complex, there are many rules, need to use the IDE's visual tools for editing, getting started and use is difficult.
2.itext
Itext is a very useful PDF open source software. Supports the use of pictures, HTML pages, and direct production of PDFs in a variety of ways, such as Java code. The Itext API is rich and supports a good format for PDFs. Itext has a significant disadvantage, the format of the HTML requirements are particularly stringent, and can not identify a lot of HTML tag and attribute, do not recognize the CSS, you need to use API functions to set the style. If you want to use HTML to generate Pdf,itext's flaws, the recognition is maddening. Painting a style on HTML is much simpler than drawing a PDF style with an API line. How to do it. If you have an accessible page address, you can try using the following method. http://www.2017j.cn/
3.itext+phantomjs
PHANTOMJS is a WebKit-based server-side Java API. PHANTOMJS can be used for page automation, network monitoring, web screen screenshots, and no interface testing. We can screen the URL to generate a PDF by using it, and then turn the picture into a PDF. The disadvantage of this approach is that all the text in the generated PDF is not selected and there is no way to copy the contents.
4.itext+flying Sauser
Flying Sauser is an Open-source software based on Itext. It solves the itext of weak pain points for HTML support. And all of the generated PDF content can be selected for replication. The disadvantage is that it still requires strict HTML formatting.
The file must begin with a
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en"
"Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
All the labels must be closed. Special characters need to use <! [cdata[]]> enclosed. But it's still an excellent solution compared to the previous scenarios.