星空网 > 软件开发 > ASP.net

使用Aspose插件对Excel操作

使用使用Aspose插件对Excel文档进行导入导出操作

Excel导入:

前台使用file标签获取,submit方式提交。

<form id="form1" enctype="multipart/form-data" method="post" > <table class="table-condensed"><tr>          <td class="text-right">导入表格:</td>          <td class="text-left"><input type="file" name="file1" class="btn btn-default btn-lg" /></td></tr><tr>          <td class="text-left">            <input type="submit" id="btnImport" name="btnImport" value="导入" class="btn btn-default" />          </td>        </tr></table></form>

后台接收:

HttpPostedFileBase fileBase = Request.Files["file1"];//这里获取名称与前台标签name保持一致if (fileBase != null)      {        string filename = Path.GetFileName(fileBase.FileName);        string extension = Path.GetExtension(filename);        string path = "/Upload/Test/" + DateTime.Now.ToString("yyyyMMdd") + "/";        Directory.CreateDirectory(Path.GetDirectoryName(Request.MapPath(path)));        string newFilename = DateTime.Now.ToString("yyyyMMddHHmmssfff");        string fullFileName = path + newFilename + extension;        fileBase.SaveAs(Request.MapPath(fullFileName));try        {Stopwatch sw = new Stopwatch();//记录导入操作用时多长          sw.Start();//这里可放入BLL方法处理string result = new ProductBLL().ImportExcel(Request.MapPath(path), newFilename, extension);//BLL方法 ProductBLLpublic string ImportExcel(string path, string filename, string extension)
        {
            Workbook workbook = new Workbook(path + filename + extension);
            Worksheet worksheet = workbook.Worksheets[0];
            Cells cells = worksheet.Cells;
            for (int i = 1; i < cells.Rows.Count; i++)
            {
                try
                {
                    string brand = cells[i, 0].StringValue.Trim();//获取列值
                    string years = cells[i, 1].StringValue.Trim();
                }
                catch (Exception e)
                {
                    continue;
                }

            }
            return "OK";
        }sw.Stop(); long runTime = sw.ElapsedMilliseconds / 1000;}catch (Exception e) { Log.Write("导入", "导入错误", "错误信息:" + e.Message); } }

Excel导出:
string path = "/Upload/Test/" + DateTime.Now.ToString("yyyyMMdd") + "/";      Directory.CreateDirectory(Path.GetDirectoryName(Server.MapPath(path)));      string newFilename = DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".xls";      string fullFileName = Server.MapPath(path + newFilename);public void ExportInfo(List<Test> list, string fullFileName)    {Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook();      Aspose.Cells.Worksheet cellSheet = workbook.Worksheets[0];      cellSheet.PageSetup.LeftMargin = 0.3;      cellSheet.PageSetup.RightMargin = 0.3;      cellSheet.PageSetup.TopMargin = 1;      cellSheet.PageSetup.BottomMargin = 0.5;      cellSheet.PageSetup.FooterMargin = 0.5;      cellSheet.PageSetup.HeaderMargin = 0.5;      cellSheet.PageSetup.Orientation = PageOrientationType.Landscape;      cellSheet.PageSetup.CenterHorizontally = true;      cellSheet.PageSetup.CenterVertically = true;cellSheet.Cells[0, 0].PutValue("货号");      cellSheet.Cells[0, 1].PutValue("颜色");      cellSheet.Cells[0, 2].PutValue("尺码");int i = 1;      foreach (var item in list)      {cellSheet.Cells[i, 0].PutValue(item.productno);        cellSheet.Cells[i, 1].PutValue(item.size);        cellSheet.Cells[i, 2].PutValue(item.color);i++;      }cellSheet.AutoFitColumns();      fullFileName = Path.GetFullPath(fullFileName);      workbook.Save(fullFileName);}  

由于抽取部分代码出来,排版和引用方面未做详细注释-----------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
2223222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
3333333333333333333233333333333333333333333333333333333333333333333333333333333333333333333333333333

 啦啦啦啦啦啦啦啦啦啦啦啦 啦啦啦啦啦啦啦啦啦啦啦啦 啦啦啦啦啦啦啦啦啦啦啦啦 啦啦啦啦啦啦啦啦啦啦啦啦 啦啦啦啦啦啦啦啦啦啦啦啦

 啦啦啦啦啦啦啦啦啦啦啦啦 啦啦啦啦啦啦啦啦啦啦啦啦 啦啦啦啦啦啦啦啦啦啦啦啦 啦啦啦啦啦啦啦啦啦啦啦啦 啦啦啦啦啦啦啦啦啦啦啦啦

 啦啦啦啦啦啦啦啦啦啦啦啦 啦啦啦啦啦啦啦啦啦啦啦啦 啦啦啦啦啦啦啦啦啦啦啦啦 啦啦啦啦啦啦啦啦啦啦啦啦 啦啦啦啦啦啦啦啦啦啦啦啦

 啦啦啦啦啦啦啦啦啦啦啦啦 啦啦啦啦啦啦啦啦啦啦啦啦 啦啦啦啦啦啦啦啦啦啦啦啦 啦啦啦啦啦啦啦啦啦啦啦啦 啦啦啦啦啦啦啦啦啦啦啦啦

 啦啦啦啦啦啦啦啦啦啦啦啦 啦啦啦啦啦啦啦啦啦啦啦啦 啦啦啦啦啦啦啦啦啦啦啦啦 啦啦啦啦啦啦啦啦啦啦啦啦 啦啦啦啦啦啦啦啦啦啦啦啦

 

 




原标题:使用Aspose插件对Excel操作

关键词:ASP

ASP
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

海运悉尼海运费:https://www.goluckyvip.com/tag/92185.html
海运到多伦多海运:https://www.goluckyvip.com/tag/92186.html
海运到菲律宾:https://www.goluckyvip.com/tag/92187.html
圣地亚哥海运:https://www.goluckyvip.com/tag/92188.html
肯尼亚双清海运:https://www.goluckyvip.com/tag/92189.html
海运到新西兰海运:https://www.goluckyvip.com/tag/92190.html
船底顶攻略(船底顶最详细攻略):https://www.vstour.cn/a/411239.html
川藏线自驾游要怎么走才比较划算呢?:https://www.vstour.cn/a/411240.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流