Preface
This article mainly reads the Excel document and reads the contents by traversing the rows and columns. Where the content type of the cell needs to be read separately. Example
public static void Main (string[] args) throws Exception
{
//input stream
InputStream is = new FileInputStream ("f:\\ Poi\\ffff.xls ");
File System
Poifsfilesystem fs = new Poifsfilesystem (is);
Define Workbook
Hssfworkbook wb = new Hssfworkbook (fs);
Gets the first sheet page
hssfsheet hssfsheet = wb.getsheetat (0);
if (Hssfsheet = = null) {
return;
}
Traverse rows row
for (int rowNum = 0; Rownum<=hssfsheet.getlastrownum (); rownum++) {
//Get each row
hssfrow row = Hssfsheet.getrow (rowNum);
if (row = = null) {
continue;
}
Traverse column cell
for (int cellnum = 0; Cellnum<=row.getlastcellnum (); cellnum++) {
//Get each column
Hssfcell cell = Row.getcell (cellnum);
if (cell = = null) {
continue;
}
System.out.print ("" +getvalue (cell));
}
System.out.println ();
}
}
/**
* Different values range for different types
* @param cell
* @return *
/private static String GetValue (Hssfcell cell) {
if (Cell.getcelltype () ==hssfcell.cell_type_boolean) {
return string.valueof (Cell.getbooleancellvalue ());
} else if (Cell.getcelltype () ==hssfcell.cell_type_numeric) {
return string.valueof (Cell.getnumericcellvalue ());
}
return string.valueof (Cell.getstringcellvalue ());
}
Summary: Here the method of reading the value is not very perfect, read the value of the number, the integer will read out the decimal point.