Get the data in Excel and put it into datatable
If (this. fuupload. hasfile)
{
// Create an hssfworkbook using an existing Excel File Based on the path, that is, the entire Excel File
Hssfworkbook workbook = new hssfworkbook (this. fuupload. filecontent );
// Obtain the first sheet in Excel
Hssfsheet sheet = Workbook. getsheetat (0 );
Datatable table = new datatable ();
// Obtain the first line of the sheet.
Hssfrow headerrow = sheet. getrow (0 );
// The number of the last square in a row, that is, the total number of Columns
Int cellcount = headerrow. lastcellnum;
For (INT I = headerrow. firstcellnum; I <cellcount; I ++)
{
Datacolumn column = new datacolumn (headerrow. getcell (I). stringcellvalue );
Table. Columns. Add (column );
}
// The label of the last column, that is, the total number of rows
Int rowcount = sheet. lastrownum;
For (INT I = (sheet. firstrownum + 1); I <sheet. lastrownum; I ++)
{
Hssfrow ROW = sheet. getrow (I );
Datarow = table. newrow ();
For (Int J = row. firstcellnum; j <cellcount; j ++)
{
If (row. getcell (j )! = NULL)
Datarow [J] = row. getcell (j). tostring ();
}
Table. Rows. Add (datarow );
}
Workbook = NULL;
Sheet = NULL;
This. gvexcel. datasource = table;
This. gvexcel. databind ();
}