首页 > 代码库 > Aspose.cells 导出Excel
Aspose.cells 导出Excel
//Exportprivate void btnExport_Click(object sender, RoutedEventArgs e){string strDataTime = System.DateTime.Now.ToString("yyyyMMdd_HHmmss");string strFileName = "buyf_Template" + strDataTime;SaveFileDialog save = new SaveFileDialog();save.DefaultExt = "xlsx";save.Filter = "Excel File|*.xlsx";save.FileName = strFileName;if (save.ShowDialog() == true){//获得数据源DataClasses1DataContext db = new DataClasses1DataContext();List<TBProduct> pros = new List<TBProduct>();pros = (from p in db.TBProduct select p).Take(20).ToList();string strReportPath = AppDomain.CurrentDomain.BaseDirectory + @"\Template\Buyf_Template.xlsx";//string strReportPath = System.Windows.Forms.Application.ExecutablePath + @"\Template\Buyf_Template.xlsx";Workbook book = new Workbook(strReportPath);Worksheet sheet = book.Worksheets[0];sheet.Cells[0, 0].PutValue("Item One");sheet.Cells[0, 1].PutValue("Item Two");sheet.Cells[0, 2].PutValue("Item Three");sheet.Cells[0, 3].PutValue("Item Four");for (int i = 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!");}}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。