Console throws exception:Java.lang.IllegalStateException:Cannot get a text value from a numeric cellThe above error occurred when parsing an Excel file with POI in Java, indicating that the value of the text type cannot be obtained from a cell of a numeric type.When a POI operates Excel, the data cell has different types, and when we try to read a string from a number type cell and write to the database , c
Address: http://zhanqi.net/blog/287/
Test Environment Servlet/struts2 + poi 3.7
Supports exporting the excel2003/2007 format, and the exported file name supports Chinese characters without garbled characters.
For more details, see the code and method annotations. For more information, see the poi download operation guide.
/**
* JSP/servlet + poi export Excel
*
*@
Poi is an API provided by Apache for processing files such as Excel.
1. Download the JAR File
Http://poi.apache.org/download.html#POI-3.7
The current stable version is 3.7.
Development and download in window:Poi-bin-3.7-20101029.zip
2. decompress the package.
3. Create a project under eclipse.
Import the following JAR files to the project.
Jar files in the root directory
Jar files under the lib directory
Java poi export excel and poiexcel
Jar of poi: http://poi.apache.org/
There will be a lot of jar after the download, but if it is just a simple excel report, you can import a poi-version-date. jar.
Export Code:
Private void outputExcel (String queryDate, String [] headers, List
Well, append a mysql function to get the year and month.
date_format(formatdate,'%Y-%
Getting started with POI
POI Quick Start
Seven steps required for POI development:
1. Create a WorkBook object
Workbook wb = new HSSFWorkbook (); // It is used to operate excel 2003
2. Create a worksheet Sheet object
Sheet sheet = wb. createSheet ();
3. Create a row object
Row nRow = sheet. createRow (number of rows );
4. Create a Cell Object
Cell nCell = nRow.
When I read EXCEL from poi, I encountered the following common case:
When you enter 1000 in a cell, poi needs to use getnumericcellvalue () to obtain the value, even though you set the cell to text in Excel.
If you insist on using getstringcellvalue (), the following error is returned:
Cannot get a text value from a numeric cell...
When you use getnumericcellvalue () to obtain the value, you will find that
Yesterday, when I used poi to parse the Excel file, I found that if the Excel file is encrypted, that is, the Excel file is set to protected worksheet (tool --> Protection Work Sheet) the poi of apahce cannot parse the encrypted Excel file. However, if only one sheet in the encrypted Excel file (that is, the sheet protected by the Excel file is set to protected) can be parsed ~~~
In addition,
); } /*** Find the number of rows to insert and create a new POI Row Object *@paramsheet *@paramRowIndex *@return */ Privatexssfrow CreateRow (xssfsheet sheet, Integer rowIndex) {xssfrow row=NULL; if(Sheet.getrow (rowIndex)! =NULL) { intLastrowno =Sheet.getlastrownum (); Sheet.shiftrows (RowIndex, Lastrowno,1); } row=Sheet.createrow (RowIndex); returnRow; } /*** Create a row in which to enter the cell *@param
Problem occurs 1:Use POI to export Excel under Spring MVC Framework, set export file name: Response.setheader ("Content-disposition", "Attachment;filename=" +sourceid+ "_" + datestring+ ". xls");When this method is used to catch a package test, it shows that the bug URL is not valid.Workaround: String filenmae = Urlencoder.encode for "attachment;filename=" +sourceid+ "_" +datestring+ ". xls" ("attachment; Filename= "+sourceid+" _ "+datestring+". xls "
jar:http://poi.apache.org/of POI There will be a lot of jars after the download, but if it's just a simple Excel report, import a poi-version number-the date. Jar is ready. Export code: Privatevoidoutputexcel (stringquerydate,string[]headers, List Uh, add a MySQL function to get the date Date_format (formatdate, '%y-%m ') Finally, the point is that when the request is exported, the AJAX request cannot be us
Use POI to create a simple Myxls.xls fileThe usual package is org.apache.poi.hssf.usermodel.*;Example:Import java.io.*;Import org.apache.poi.hssf.usermodel.*;public class Zoomsheet {Public Zoomsheet () {}public static void Main (String args[])Throws IOException {Hssfworkbook wb = new Hssfworkbook ();Hssfsheet Sheet1 = wb.createsheet ("new sheet");FileOutputStream fileout = new FileOutputStream ("Workbook.xls");Wb.write (fileout);Fileout.close ();}}Cla
Java uses POI to import data from a database into Excel
Effect:
Use the first POI package into the project path, note that only need to import POI package can be downloaded after three jar package
Core code:
Connection database: Dbconnection.java
Copy Code code as follows:
Package org.xg.db;
Import java.sql.Connection;
Import Java.sql.Driver
The Apache poi is a free, Open-source Java API Written in Java that provides the ability to read and write to Microsoft Office format files.
The official download address for the Apache POI Source and library (jar package) is: http://poi.apache.org/download.html
I also provided a download address: http://download.csdn.net/detail/gaojinshan/7487253
It is the latest version (
Process Description:
The POI object includes a partial base color, which is used in the form
Hssfcellstyle Styleheader = Wb.createcellstyle ()//Create a cell's style
//Background color setting
style.setfillbackgroundcolor ( HSSFColor.GREEN.index);
Among them, HSSFColor.GREEN.index is the color that poi comes with.
Our idea is to modify POI's own color, configure its RGB to the color we want
Monitor reports export Excel summary based on POI
Poi manipulating Excel objects
HSSF: Manipulating Excel (. xls) format
XSSF: Manipulating Excel 2007 OOXML (. xlsx) format to manipulate Excel memory usage above HSSF
SXSSF: Support from POI3.8 Beta3, based on XSSF, low memory footprint.
1. Principle of realization
Based on the Excel configuration template for report export, to achieve the export of Excel
This function description, click on the Download button on the front page, start to download the required data, as follows:Google Chrome works as follows:Open Excel as follows:The Firefox browser works as follows:First to import the POI jar package, my project uses MAVEN management, so add is relatively simple, the following codeFind the project's Pom.xml file to join in Dependency> groupId>Org.apache.poigroupId> Artifactid>PoiArtifactid> ver
Java Solution for POI export Excel memory OverflowIn our use of Java development process, we often want to export the data obtained by the query, which is generally stored in Excel, so we export the data to use the Java POI Library, which is mainly for the various Windows Platform data format operation, here, We are working on Excel.The process of generating Excel is like this, first of all, we query the da
1. First download the Poi-3.6-20091214.jar, as follows:http://download.csdn.net/detail/evangel_z/38950512.student.javaImport Java.util.Date;public class Student{private int id;private String name;private int age;Private Date birth;Public Student (){}public Student (int ID, String name, Int. age, Date birth){This.id = ID;THIS.name = name;This.age = age;This.birth = birth;}public int getId (){return ID;}public void setId (int id){This.id = ID;}Public St
When you use a POI to update Excel, if cell a sets a formula, and when the other cells it depends on are populated with values, a in the exported Excel is still a formula instead of an auto-calculated value.Paste_image.pngThe score subtotal is not updated to the calculated results.WorkaroundThis interface is provided in the POI to org.apache.poi.ss.usermodel.FormulaEvaluator enable updates to the formula. W
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.