A colleague asked me to parse 0.6 million pieces of data to an Excel table, remove the specified data, and write the data in a decisive manner. After half of the data, he didn't need it anymore.
Jar package
Commons-codec-1.5.jarcommons-logging-1.1.jardom4j-1.6.1.jarjunit-3.8.1.jarlog4j-1.2.13.jarpoi-3.9-20121203.jarpoi-examples-3.9-20121203.jarpoi-excelant-3.9-20121203.jarpoi-ooxml-3.9-20121203.jarpoi-scratchpad-3.9-20121203.jarstax-api-1.0.1.jarxmlbeans-2.3.0.jar
Package Com. jokey; Import Java. Io. fileinputstream; Import Java. Io. filenotfoundexception; Import Java. Io. fileoutputstream; Import Java. Io. ioexception; Import Org. Apache. Poi. poifs. filesystem. poifsfilesystem; Import Org. Apache. Poi. xssf. usermodel. xssfcell; Import Org. Apache. Poi. xssf. usermodel. xssfrow; Import Org. Apache. Poi. xssf. usermodel. xssfsheet; Import Org. Apache. Poi. xssf. usermodel. xssfworkbook; Public Class Excelreaderandwriter { Private Poifsfilesystem FS; Private Xssfworkbook WB; Private Xssfsheet sheet; Private Xssfrow row; Private Xssfcell cell; Public Static Void Main (string [] ARGs ){ Try { // Test the title of an Excel worksheet Excelreaderandwriter excelreader = New Excelreaderandwriter (); excelreader. Reader (); // Excelreader. Writer (); } Catch (Filenotfoundexception e) {system. Out. println ( "The specified path file is not found! " ); E. printstacktrace ();} Catch (Ioexception e ){ // Todo auto-generated Catch Block E. printstacktrace ();}} Private Void Reader () Throws Ioexception {fileinputstream is = New Fileinputstream ("F: \ 3.xls X" ); WB = New Xssfworkbook (is); Sheet = WB. getsheetat (0 ); Sheet = WB. getsheetat (0 ); // Retrieve the total number of rows Int Totalrownum = Sheet. getlastrownum (); // Here I <= For ( Int I = 0; I <= totalrownum; I ++ ) {Row =Sheet. getrow (I ); For ( Int J = 0; j <row. getlastcellnum (); j ++ ) {System. Out. Print (row. getcell (j);} system. Out. println ( "" );}} Private Void Writer () Throws Ioexception {fileoutputstream OS = New Fileoutputstream ("F: \ 5.xlsx" ); // Create a worksheet WB = New Xssfworkbook (); Sheet = WB. createsheet (); row = Sheet. createrow (0 ); Cell = Row. createcell (0 ); Cell. setcellvalue ( "Tested" ); Try { // Write WB. Write (OS );} Catch (Ioexception e ){ // Todo auto-generated Catch Block E. printstacktrace ();}}}