First of all to talk about what happened today, in the spirit of an Android heart I was assigned to the PB group, Cao Ying Han Ah! Well, what we're going to record and share today is that Java uses POI import to export data from Excel. Below the POI package of http://poi.apache.org/download.html, interested friends can also go to see the API.
Let's share the two points that you should be aware of when doing basic operations on a POI:
1.POI for Xlsx/xls is required to create different Workbook instance Hssfworkbook is for XLS Xssfworkbook is for xlsx.
1: String fileaddress="e:/blog stats. xlsx"//Read Excel address
3: new File (fileaddress); Reading Excel Files
4: isnew FileInputStream (f); Create a file stream
5: if(Fileaddress.tolowercase (). EndsWith ("xlsx")) {
6: new Xssfworkbook (is); //If the Xssfworkbook object is created on the xlsx version
7: Elseif(Filename.tolowercase (). EndsWith ("xls")) {
8: new Hssfworkbook (is); //If the XLS version of the Hssfworkbook object is created
2. When importing data into Excel, you need to understand if there is a row object in sheet, if there is a getrow (), Gercell (), Setcellvalue (), if not, you need CreateRow (), Createcell (), Setcellvalue ().
2: int lastrow = sheet.getlastrownum () + 1;
3: if(rowindex_<lastrow) {
4: xssfrow row = Sheet.getrow (rowindex_); Get Row Objects
5: Row.getcell (0). Setcellvalue (bolgname2);
6: Row.getcell (1). Setcellvalue (linktime2);
7: Row.getcell (2). Setcellvalue (Linktitle2);
8: Row.getcell (3). Setcellvalue (LINKRESULT2);
9: Row.getcell (4). Setcellvalue (LINKRED2);
Ten: Row.getcell (5). Setcellvalue (LINKPINGLUN2);
One : Row.getcell (6). Setcellvalue (TUIJIANSTRING2);
: Row.getcell (7). Setcellvalue (FANDUISTRING2);
: xssfrow row = Sheet.createrow (rowindex_);
: Row.createcell (0). Setcellvalue (bolgname2);
: Row.createcell (1). Setcellvalue (linktime2);
: Row.createcell (2). Setcellvalue (Linktitle2);
: Row.createcell (3). Setcellvalue (LINKRESULT2);
: Row.createcell (4). Setcellvalue (LINKRED2);
: Row.createcell (5). Setcellvalue (LINKPINGLUN2);
: Row.createcell (6). Setcellvalue (TUIJIANSTRING2);
At : Row.createcell (7). Setcellvalue (FANDUISTRING2);
1: new FileOutputStream (fileaddress);
Finally today to blog statistics fixed a bug, found that the regular expression in the control of the string format is very strong but the water is deep need to study hard, think of him as the next learning goal, and then the next time to solve the problem, the brain burst out of him.
Java uses POI import to export data from Excel