#Region Export Private Void Cmdexport_ServerClick (Object Sender, System.Eventargs E) {Try {string DownloadPath = Server.mAppath ("../ DataFolder / FileExport"); // The folder path of the copy. // The copy of the file name. string TempFileName = DateTime.Now.ToString ( "yyyyMMdd") DateTime.Now.Hour DateTime.Now.Minute DateTime.Now.Second ".XLS"; this.txtTempFileName.Text = TempFileName; object missing = System. Reflection.Missing.Value; object missing2 = System.Reflection.Missing.Value; Excel.Application myExcel = new Excel.Application (); Excel.Workbook myBook = (Excel.Workbook) myExcel.Workbooks.Add (missing); Excel. Worksheet CURSHEET = (Excel.Worksheet) Mybook.sheets [1]; // Sets Excel Style Range R1 = (Range) MyExcel.cells [1, 2]; Range R2 = (Range) MyExcel.cells [3,4]; // Range r10 = (Range) MyExcel.cells [9,10]; //r10.autooutLine (); //r10.fillleft ();
R1.Font.Bold = true; r1.font.color = information.RGB (0,255,0); r2.Font.Bold = true;
String DownloadfilePath = DownloadPath "//" TempFileName;
DataSet DS = this.getDataSet (); int RC = ds.tables [0] .Rows.count; // Draw Border Range RBorders = (Range) Cursheet.Get_Range (MyExcel.cells [7,1], MyExcel.cells [ 7 RC 1, 10]); RBORDERS.BORDERS.LINESTYLE = 1; Cursheet.Get_Range (MyExcel.cells [7,1], MyExcel.cells [7 RC 1, 1]). Borders [xlbordersIndex.xledgeleft ] .Weight = xlborderweight.xlt = xlborderweight.xlt; // Set the left cable plus coarse Cursheet.get_Range (MyExcel.cells [7,1], myexcel.cells [7,10]). Borders [xlbordersindex.xledgeTGetop] .weight = xlborderweight.xlt = xlborderweight.xlt ; // Settings Setting up the upper edge plus thick cursheet.get_range (MyExcel.cells [7 RC 1, 1], myexcel.cells [7 RC 1, 10]). Borders [xlbordersindex.xledgebottom] .weight = xlborderweight .XLTHICK; // Set the lower edge plus coarse cursheet.get_range (MyExcel.cells [7,10], MyExcel.cells [7 RC 1, 10]). Borders [xlbordersindex.xledgeright] .weight = xlborderweight.xlt; // Set the right line plus thick // Excel's head information MyExcel.cells [1,2] = this.lblexcelhead.text; myexcel.cells [2, 2] = "new added:" DateTime.now.toString ); Myexcel.cells [3, 4] = "vendor code list - by products."; Myexcel.cells [4, 4] = "************* ************************** "; myexcel.cells [5,9] =" Date from: " this.txtcreated.Text; MyExcel .Cells [6,9] = "DATE TO:" this.txtdatenow.text;
MyExcel.cells [7,5] = "Parts Supplier";
// Set the Excel table list MYEXCEL.CELLS [8, 1] = "item"; myexcel.cells [8, 2] = "orgcode"; myexcel.cells [8, 3] = "vendorcode"; myexcel.cells [ 8, 4] = "vendorname"; myexcel.cells [8,5] = "a"; myexcel.cells [8, 6] = "b"; myexcel.cells [8, 7] = "c"; myExcel. Cells [8, 8] = "paymenttype"; myexcel.cells [8,9] = "termscode"; myexcel.cells [8, 10] = "createtime"; // Sets the header font style Cursheet.get_Range (MyExcel). Cells [7,1], myexcel.cells [8, 10]). Font.bold = true; int J = 1; // J is a summary of Item number of variable INT i = 9; While (I-8 <= Ds.Tables [0] .Rows.count) {MyExcel.cells [i, 1] = j.totring (); myexcel.cells [i, 2] = ds.tables [0] .rows [i-9] [ "Orgcode"]. TOSTRING (). Trim (); myexcel.cells [i, 3] = ds.tables [0] .Rows [i-9] ["vendorcode"]. Tostring (). Trim (); MyExcel .Cells [i, 4] = ds.tables [0] .ROWS [I-9] ["vendorname"]. Tostring (). Trim (); myexcel.cells [i, 5] = "; myexcel.cells [i, 6] = ""; myexcel.cells [i, 7] = ""; myexcel.cells [i, 8] = ds.tables [0] .ROWS [I-9] ["paytype"]. Tostring () .Trim (); myexcel.cells [i, 9] = ds.tables [0]. Rows [i-9] ["Termscode" ] .Tostring (). Trim (); myexcel.cells [i, 10] = convert.todatetime (ds.tables [0] .rows [i-9] ["createtime"]. Tostring ()). ToshortdateString () .Trim (); if (ds.tables [0] .rows [i-9] ["createtime"]. TOSTRING ()). Month == Convert.TODATETIME (this.txtDatenow.text) .MONTH ) {For (int QQ = 1; QQ <= 10; QQ ) {RANGE R = (Range) myexcel.cells [i, qq]; r.Font.Color = information.RGB (0,255,0); r = null ;
}} // Set color, otherwise the date is displayed as "######" format. Range rcol10 = (Range) MyExcel.cells [i, 10]; rcol10.color = information.RGB (0,0,0); rcol10 = null; // From 1 Circulation J ; i ;} mybook.saved = True; Mybook.saveas (Downloadfilepath, Missing2, ",", ", False, False, Excel.xlsaveasaccessMode.xlnochange, 1, False, missing, missing;
//mybook.printpreview (0); //mybook.printout (missing, missing, missing); mybook.close (false, null, null); MyExcel.quit (); system .Runtime.InteropServices.Marshal.ReleaseComobject (MyBook); System.Runtime.InteropServices.Marshal.ReleaseComobject (MyExcel); mybook = null; myExcel = null; gc.collect ();
//Response.Redirect(DownloadFilePath);// download file try {BomUploadController BUC = new BomUploadController (); BUC.KillProcess ( "Excel");} // handle catch (BomUploadController.FileException ex) {string error message [] Errcase = ex.Errorstring.split ("!". Tochararray ()); string script = "