Exemple #1
0
        private void exportExcelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string fileName = "GymManager.xlsx";
            string customExcelSavingPath = Application.StartupPath + @"\Assets\" + fileName;

            ExcelUtil.GenerateExcel(ExcelUtil.ConvertToDataTable(dao.GetListGymer()), customExcelSavingPath);
            MessageBox.Show("OK ! Dã lưu file trong thư mục Assets \r\n path:" + customExcelSavingPath);
        }
Exemple #2
0
        public FileResult OutToExcel()
        {
            string        sheetname = ConfigurationManager.AppSettings["Sheet"];
            List <Expert> list      = seeiDb.Experts.ToList();
            string        filename  = DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls";//获取当前时间

            DataTable dt = ExcelUtil.ConvertToDataTable(list);

            string[]     headers = { "序号", "专家编号", "姓名",   "性别",   "单位性质", "单位信息", "技术职称", "从事领域", "邮箱", "办公电话", "手机号码",
                                     "通信地址",   "入库状态", "相关主页", "业务类别", "备注",   "添加时间" };
            string[]     cellKes = { "sId",       "eId",      "eName",       "gender",     "unitProperty", "UnitDetailsOne", "academicTitles", "field", "email", "officePhone", "cellPphone",
                                     "postalAddress", "beStatus", "personalUrl", "Categories", "remark",       "addTime" };
            MemoryStream ms = ExcelUtil.Export(dt, sheetname, headers, cellKes);

            #region 将excel文件保存到服务器指定路径
            //string xlsname = ConfigurationManager.AppSettings["Excel"];
            // byte[] data = ms.ToArray();//Encoding.UTF8.GetBytes();
            // string filePath = Server.MapPath("~/Content/xiaoyicun/" + xlsname + ".xls");
            // FileManager.WriteBuffToFile(data, filePath);
            #endregion

            ms.Seek(0, SeekOrigin.Begin);
            return(File(ms, "application/vnd .ms-excel", Url.Encode(filename)));
        }