国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > 建站經驗 > 正文

asp.net!導出excel的簡單方法

2019-11-02 15:14:28
字體:
來源:轉載
供稿:網友

 這篇文章主要介紹了asp.net導出excel的簡單方法實例,需要的朋友可以參考下

excel的操作,最常用的就是導出和導入,廢話不多說上代碼。 本例使用NPOI實現的,不喜勿噴哈。。。。  代碼如下:/// <summary>        /// 導出Excel        /// </summary>        /// <param name="stime"></param>        /// <param name="etime"></param>        /// <returns></returns>        public ActionResult Export(FormCollection frm)        {            DataTable dts = new DataTable();            dts = _shopMemeber.ExportMemberData(frm);            IWorkbook workbook = new XSSFWorkbook();            ISheet sheet = workbook.CreateSheet();            IRow headerRow = sheet.CreateRow(0);            foreach (DataColumn column in dts.Columns)                headerRow.CreateCell(column.Ordinal).SetCellValue(column.Caption);            int rowIndex = 1;            foreach (DataRow row in dts.Rows)            {                IRow dataRow = sheet.CreateRow(rowIndex);                foreach (DataColumn column in dts.Columns)                {                    dataRow.CreateCell(column.Ordinal).SetCellValue(row[column].ToString());                }                rowIndex++;            }            string filepath = Server.MapPath("/") + @"用戶列表.xlsx";            FileStream file = new FileStream(filepath, FileMode.Create);            workbook.Write(file);            ExcelHelper.DownLoad(@"/用戶列表.xlsx");            #region 不啟用             #endregion            return SuccessMsg("AdminMemberMemberIndex");        }//這個是下載到桌面的方法,沒實現自選路徑public static void DownLoad(string FileName) {             FileInfo fileInfo = new FileInfo(HttpContext.Current.Server.MapPath(FileName));             //以字符流的形式下載文件             FileStream fs = new FileStream(HttpContext.Current.Server.MapPath(FileName), FileMode.Open);            byte[] bytes = new byte[(int)fs.Length];              fs.Read(bytes, 0, bytes.Length);            fs.Close();            HttpContext.Current.Response.ContentType = "application/octet-stream";               //通知
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 建水县| 额尔古纳市| 泸定县| 措美县| 密云县| 葫芦岛市| 建昌县| 财经| 荆州市| 宜州市| 德州市| 驻马店市| 贺兰县| 文安县| 平安县| 嵩明县| 广汉市| 湖口县| 冀州市| 灵丘县| 来安县| 蒙阴县| 会宁县| 澄迈县| 务川| 新巴尔虎右旗| 封丘县| 南雄市| 墨玉县| 女性| 无极县| 环江| 天峻县| 双牌县| 崇义县| 德令哈市| 湟中县| 大同市| 慈溪市| 金山区| 霍林郭勒市|