//ExportPrivate voidBtnexport_click (Objectsender, RoutedEventArgs e) {stringStrdatatime = System.DateTime.Now.ToString ("Yyyymmdd_hhmmss");stringstrFileName ="buyf_template"+Strdatatime; SaveFileDialog Save=NewSaveFileDialog (); save. DefaultExt="xlsx"; save. Filter="Excel file|*.xlsx"; save. FileName=strFileName;if(Save. ShowDialog () = =true){//get the data sourceDataclasses1datacontext db =NewDataclasses1datacontext (); List<TBProduct> Pros =NewList<tbproduct>();p Ros= ( fromPinchDb. TbproductSelectP). Take ( -). ToList ();stringStrreportpath = AppDomain.CurrentDomain.BaseDirectory +@"\template\buyf_template.xlsx";//string strreportpath = System.Windows.Forms.Application.ExecutablePath + @ "\template\buyf_template.xlsx";Workbook Book=NewWorkbook (Strreportpath); Worksheet sheet= Book. worksheets[0];sheet. cells[0,0]. Putvalue ("Item One"); sheet. cells[0,1]. Putvalue ("Item A"); sheet. cells[0,2]. Putvalue ("Item Three"); sheet. cells[0,3]. Putvalue ("Item Four"); for(inti =0; I < Pros. Count; i++) {Tbproduct Pro=Pros[i];sheet. Cells[i+1,0]. Putvalue (pro. No); sheet. Cells[i+1,1]. Putvalue (pro. Name); sheet. Cells[i+1,2]. Putvalue (pro. carnumber); sheet. Cells[i+1,3]. Putvalue (pro. SRP);} Book. Save (save. FileName); MessageBox.Show ("Export successful!");}}