当前位置: 首页 > news >正文

绍兴专业制作网站互联网制作公司

绍兴专业制作网站,互联网制作公司,小程序定制开发网站,秦皇岛网站排名公司asp.net导出excel示例代码 asp.net导出excel的简单方法。excel的操作#xff0c;最常用的就是导出和导入。本例使用NPOI实现。代码:///summary///导出Excel ////summary///param namestime/param///param namee… asp.net导出excel示例代码 asp.net导出excel的简单方法。excel的操作最常用的就是导出和导入。本例使用NPOI实现。代码:/// summary        /// 导出Excel        /// /summary        /// param namestime/param        /// param nameetime/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;               //通知浏览器下载文件而不是打开            HttpContext.Current.Response.AddHeader(Content-Disposition, attachment;  filename  HttpUtility.UrlEncode(fileInfo.Name, System.Text.Encoding.UTF8));          HttpContext.Current.Response.BinaryWrite(bytes);           HttpContext.Current.Response.Flush();            HttpContext.Current.Response.End();        }上面是导出下面我介绍下导入。复制代码 代码如下:/// summary        /// 导入数据        /// /summary        /// param namefile/param        /// returnstrue表示导入成功/returns        public bool Impoart(HttpPostedFileBase file)        {            try            {                //保存excel                string path  HttpContext.Current.Server.MapPath(/);                file.SaveAs(path  file.FileName);                //读取                FileStream sw  File.Open(path  file.FileName, FileMode.Open, FileAccess.Read);                IWorkbook workbook  new XSSFWorkbook(sw);                ISheet sheet1  workbook.GetSheet(Sheet1);                //最大行数                int rowsCount  sheet1.PhysicalNumberOfRows;                //判断首行是否符合规范  也就是Excel中的列名                IRow firstRow  sheet1.GetRow(0);                if (                    !(firstRow.GetCell(0).ToString()  名称  firstRow.GetCell(1).ToString()  简称                       firstRow.GetCell(2).ToString()  分类  firstRow.GetCell(3).ToString()  参考价                       firstRow.GetCell(4).ToString()  商品介绍))                {                    return false;                }                //跳过类型不正确的品项                for (int i  1; i  rowsCount; i)                {                    IRow row  sheet1.GetRow(i);                    Shop_Product product  new Shop_Product();                    string category  row.GetCell(2) ! null ? row.GetCell(2).ToString() : null;                    if (!string.IsNullOrEmpty(category))                    {                        var cate                             _unitOfWork.Shop_ProductCategoryRepository().GetAll().FirstOrDefault(t  t.Name  category);                        if (cate ! null)                        {                            product.ProductCategoryName  cate.Name;                            product.Shop_ProductCategory_ID  cate.ID;                        }                        else                        {                            continue;                        }                    }                    else                    {                        continue;                    }                    product.PName  row.GetCell(0) ! null ? row.GetCell(0).ToString() : null;                    product.PCName  row.GetCell(1) ! null ? row.GetCell(1).ToString() : null;                    if (row.GetCell(3) ! null)                    {                        product.Price  Double.Parse(row.GetCell(3).ToString());                    }                    product.Description  row.GetCell(4) ! null ? row.GetCell(4).ToString() : null; // www.jbxue.com           _unitOfWork.Shop_ProductRepository().Insert(product);                }                _unitOfWork.Save();            }            catch            {                return false;            }            return true;        } posted on 2014-02-26 06:45 snowfly123 阅读(...) 评论(...) 编辑 收藏 转载于:https://www.cnblogs.com/linuxnotes/p/3568221.html
http://www.huolong8.cn/news/178353/

相关文章:

  • 长沙网站优化公司东营建设有限公司
  • 中铁建设集团有限公司网站wordpress路由规则
  • 建设企业网站需要了解什么办公室装修风格
  • 如何做个网站做cpa国外的网站需要备案吗
  • 如何做网站 seo个人博客网站设计模板
  • 网站被k恢复青岛当地的做公司网站的
  • 网站建设费摊多久wordpress 微博登陆不了
  • 上海网站免费制作在郑州网站推广
  • 重慶网站开发建设部网站网上大厅
  • 网站建设的优缺点广东建设工程信息网官网证书查询
  • 学校网站制作代码企业网站推广短平快
  • 网站设计预算网站没备案如何做淘宝客
  • 学士学位网站重置密码怎么做做网站销售电销好做吗
  • 成都网站建设好建筑施工组织设计毕业设计
  • 东莞做网站哪里好wordpress i18n
  • 男性产品哪个网站可以做用网站做淘客怎么做
  • 个人建立网站怎么赚钱沧州商贸行业网站建设
  • 做网站笔记本2014wordpress 地图html代码
  • 网站个别页面做seowordpress视频播放列表
  • 网站建设需要什么人员网站开发可行性研究报告
  • 做门户网站需要多少钱素材网视频
  • 创网站 灵感品牌红酒网站建设
  • 网站流量 名词做网站烧钱
  • 建网站 云主机wordpress 字体调整
  • 广东网站建设模版能上传文件的网站
  • 山东省建设节能协会网站深圳装修公司电话号码大全
  • 网站转微信小程序开发网页表单制作
  • 网站建设的三种方法宁波h5网站建设
  • 做纺织外贸网站wordpress建的大型网站
  • 网站开发中 即将上线全国工程信息网