Protected Void Buttonexport_click ( Object Sender, eventargs E)
{
String Strfilename = " ../EXCEL/template.xls " ; // "D: \ template \ template.xls ";
String Strsavefilename = " ../EXCEL/ " + Datetime. Now. year. tostring () + Datetime. Now. Month. tostring () + Datetime. Now. Day. tostring () + Datetime. Now. Hour. tostring () + Datetime. Now. Minute. tostring () + Datetime. Now. Second. tostring () + Datetime. Now. millisecond. tostring () + " . Xls " ;
Excel. Application thisapplication = New Excel. applicationclass ();
Excel. Workbook thisworkbook;
Object Missing = System. reflection. Missing. value;
// Load an Excel template file
Thisworkbook = Thisapplication. workbooks. Open (OK (strfilename), missing );
// Response. Write ("<SCRIPT> alert ('! '); </SCRIPT> ");
Excel. worksheet thissheet = (Excel. worksheet) thisworkbook. Sheets [ 1 ];
String Account = Labelaccount. text;
Datatable dt = Oh. getlaborone (account). Tables [ 0 ];
Datatable dtamout = New Datatable ();
Dtamout. Columns. Add ( " Personnel ID " );
Dtamout. Columns. Add ( " Name " );
Dtamout. Columns. Add ( " Department " );
Dtamout. Columns. Add ( " Amount to be issued " );
Dtamout. Columns. Add ( " Tax Deduction " );
Dtamout. Columns. Add ( " This real release " );
Dtamout. Columns. Add ( " Project " );
Dtamout. Columns. Add ( " Remarks " );
For ( Int I = 0 ; I < DT. Rows. Count; I ++ )
{
String Username = DT. Rows [I] [ 1 ]. Tostring ();
String Realname = DT. Rows [I] [ 2 ]. Tostring ();
String Yingfae = DT. Rows [I] [ 4 ]. Tostring ();
String Remarks = DT. Rows [I] [ 5 ]. Tostring ();
String Part = Uh. getpart (username );
Datatable dtrate = Oh. getratetable (username, account );
String Amount = Dtrate. Rows [ 0 ] [ 3 ]. Tostring ();
Double Daikoushui = Convert. todouble (yingfae) - Convert. todouble (amount );
Thissheet. cells [ 1 , 1 ] = " Personnel ID " ;
Thissheet. cells [ 1 , 2 ] = " Name " ;
Thissheet. cells [ 1 , 3 ] = " Department " ;
Thissheet. cells [ 1 , 4 ] = " Amount to be issued " ;
Thissheet. cells [ 1 , 5 ] = " Tax Deduction " ;
Thissheet. cells [ 1 , 6 ] = " This real release " ;
Thissheet. cells [ 1 , 7 ] = " Project " ;
Thissheet. cells [ 1 , 8 ] = " Remarks " ;
Thissheet. cells [I + 2 , 1 ] = Username;
Thissheet. cells [I + 2 , 2 ] = Realname;
Thissheet. cells [I + 2 , 3 ] = Part;
Thissheet. cells [I + 2 , 4 ] = Yingfae;
Thissheet. cells [I + 2 , 5 ] = Daikoushui. tostring ();
Thissheet. cells [I + 2 , 6 ] = Amount;
Thissheet. cells [I + 2 , 7 ] = Remarks;
Thissheet. cells [I + 2 , 8 ] = "" ;
}
Thisapplication. Visible = False ;
Thissheet. saveas (OK (strsavefilename), missing );
// Open the generated Excel File
// Excel. Workbook newworkbook;
// Newworkbook = thisapplication. workbooks. Open (strsavefilename, missing, and missing );
// Excel. worksheet newsheet = (Excel. worksheet) newworkbook. Sheets [1];
// Thisapplication. Visible = true;
// System. Diagnostics. process. Start (strsavefilename );
// You can also use system. Diagnostics. process. Start (strsavefilename); to open a new file.
Response. Redirect (strsavefilename );
}
I haven't figured out how to enable it locally. I finally found Lao Zhu.
I was quite depressed when I saw that Zhu had done well. It was a simple method that I did not expect.