An Improved Excel class can be used to read Excel files or export content to excel files. It is easier to operate multiple sheet files.
You do not need to install any Excel files.
1. Read.
Read
Public Void Read ( String Filename)
{
Applibrary. readexcel. Workbook workbook = Null ;
Workbook = Applibrary. readexcel. Workbook. getworkbook (filename );
Int K = 0 ;
System. Text. stringbuilder sb = New System. Text. stringbuilder ();
Foreach (Applibrary. readexcel. Sheet In Workbook. Sheets)
{
K ++ ;
SB. append ( " Current is " + K + " Sheet <br/> " );
SB. append ( " <Table class = 'scroll 'cellpadding = 0 cellspacing = 0> " );
For ( Int Irow = 0 ; Irow < Sheet. Rows; irow ++ )
{
SB. append ( " <Tr> " );
SB. append ( " <TD> " );
SB. append ( " Current is " + (Irow + 1 ) + " Line " );
SB. append ( " </TD> " );
For ( Int Icol = 0 ; Icol < Sheet. columns; icol ++ )
{
Applibrary. readexcel. Cell cell = Sheet. getcell (icol, irow );
Object Val = Cell. value;
String Cellvalue = (Val ! = Null ) ? Val. tostring (): "" ;
SB. append ( " <TD> " );
SB. append (cellvalue );
SB. append ( " </TD> " );
}
SB. append ( " </Tr> " );
}
SB. append ( " </Table> <br/> " );
}
Response. Write (sb. tostring ());
}
Read Excel:
After reading:
Export:
Export
Public Void Toexcel ()
{
Applibrary. writeexcel. xlsdocument Doc = New Applibrary. writeexcel. xlsdocument ();
Doc. filename = " Report.xls " ;
String Sheetname = String . Empty;
// Number of records
Int Mcount = 55 ;
// Quantity of each sheet
Int Inv = 10 ;
// Calculate the current number of sheets
Int K = Convert. toint32 (math. Round (convert. todouble (mcount / INV ))) + 1 ;
For ( Int I = 0 ; I < K; I ++ )
{
Sheetname = " Current is sheet " + I. tostring ();
Applibrary. writeexcel. worksheet Sheet = Doc. Workbook. worksheets. Add (sheetname );
Applibrary. writeexcel. Cells = Sheet. cells;
// Header of the first line
Cells. Add ( 1 , 1 , " Serial number " );
Cells. Add ( 1 , 2 , " Admission Ticket No. " );
Cells. Add ( 1 , 3 , " Examinee name " );
Cells. Add ( 1 , 4 , " Gender " );
Cells. Add ( 1 , 5 , " Major " );
Int F = 1 ;
For ( Int M = I * Inv; m < Mcount && M < (I + 1 ) * Inv; m ++ )
{
F ++ ;
Cells. Add (F, 1 , F - 1 );
Cells. Add (F, 2 , F );
Cells. Add (F, 3 , " Woody. Wu " );
Cells. Add (F, 4 , " Male " );
Cells. Add (F, 5 , " Economics " );
}
}
Doc. Send ();
Response. Flush ();
Response. End ();
}
DEMO code
Library source code