<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當前位置: 首頁 - 科技 - 知識百科 - 正文

        使用Aspose.Cells實現(xiàn)導入導出

        來源:懂視網(wǎng) 責編:小OO 時間:2020-11-27 22:34:41
        文檔

        使用Aspose.Cells實現(xiàn)導入導出

        本文實例為大家分享了Aspose.Cells實現(xiàn)導入導出的具體代碼,供大家參考,具體內(nèi)容如下:這是自己整理的導入導出類,里面有注釋。using System;using System.Collections.Generic;using System.Data;using System.IO;using System.Linq;using System.Text;using System.Threading.Tasks;using Aspose.Cells;////// 生成Excel ////// 模板Excel的路徑+文件名 /// Excel文件的字節(jié)對象 public byte[] CreateExcel(string url) { FileStream fs = null。
        推薦度:
        導讀本文實例為大家分享了Aspose.Cells實現(xiàn)導入導出的具體代碼,供大家參考,具體內(nèi)容如下:這是自己整理的導入導出類,里面有注釋。using System;using System.Collections.Generic;using System.Data;using System.IO;using System.Linq;using System.Text;using System.Threading.Tasks;using Aspose.Cells;////// 生成Excel ////// 模板Excel的路徑+文件名 /// Excel文件的字節(jié)對象 public byte[] CreateExcel(string url) { FileStream fs = null。

        本文實例為大家分享了Aspose.Cells實現(xiàn)導入導出的具體代碼,供大家參考,具體內(nèi)容如下

        這是自己整理的導入導出類,里面有注釋。

        using System;
        using System.Collections.Generic;
        using System.Data;
        using System.IO;
        using System.Linq;
        using System.Text;
        using System.Threading.Tasks;
        using Aspose.Cells;
        namespace Lzd.Mvc.EasyUi.Common.ExcelUtil
        {
         /// 
         /// excel操作基類
         /// 
         /// 
         public class BaseExcelUtil
         {
         private Workbook m_Wb = null;
         
         
         
         /// 
         /// 生成Excel
         /// 
         /// 模板Excel的路徑+文件名
         /// Excel文件的字節(jié)對象
         public byte[] CreateExcel(string url)
         {
         FileStream fs = null;
         try
         {
         //讀取模板Excel文件的中內(nèi)容
         fs = new FileStream(url, FileMode.Open, FileAccess.Read, FileShare.Read);
         
         m_Wb = new Workbook();
         
         m_Wb.Open(fs);
         
         setValue(m_Wb);
         
         //轉(zhuǎn)換為字節(jié)對象并返回
         return m_Wb.SaveToStream().ToArray();
         
         }
         catch (Exception ex)
         {
         throw ex;
         }
         finally
         {
         fs.Close();
         }
         }
         
         
         /// 
         /// 設(shè)定Excel中的數(shù)據(jù) 
         /// 數(shù)據(jù)源為datable類型
         /// 
         /// 工作簿
         public virtual void setValue(Workbook wb)
         {
         throw new Exception("The method or operation is not implemented.");
         }
         
         
         
         
         /// 
         /// 讀取Excel
         /// 
         /// Excel的路徑+文件名
         /// Excel文件的字節(jié)對象
         public DataTable GetExcel(string url)
         {
         FileStream fs = null;
         try
         {
         //讀取Excel文件的中內(nèi)容
         fs = new FileStream(url, FileMode.Open, FileAccess.Read, FileShare.Read);
         
         m_Wb = new Workbook();
         
         m_Wb.Open(fs);
         
         //設(shè)定Excel中的數(shù)據(jù)
         return getValue(m_Wb);
         
         }
         finally
         {
         fs.Close();
         }
         }
         
         /// 
         /// 取得Excel中的數(shù)據(jù)
         /// 
         /// 工作簿
         public virtual DataTable getValue(Workbook wb)
         {
         throw new Exception("The method or operation is not implemented.");
         }
         /// 
         /// 設(shè)置字符串值
         /// 
         /// 
         /// 
         public void putValue(Cell c, object value)
         {
         try
         {
         if (value == null || object.Equals(value, DBNull.Value) || value.ToString().Trim().Length == 0)
         {
         
         }
         else
         {
         c.PutValue(value.ToString());
         }
         }
         catch (Exception)
         {
         c.PutValue("--");
         }
         }
         /// 
         /// 設(shè)置數(shù)值值
         /// 
         /// 
         /// 
         public void putValueDouble(Cell c, object value)
         {
         try
         {
         if (value == null || object.Equals(value, DBNull.Value) || value.ToString().Trim().Length == 0)
         {
         
         }
         else
         {
         c.PutValue(Decimal.Parse(value.ToString()));
         }
         }
         catch (Exception)
         {
         c.PutValue(value.ToString());
         }
         }
         /// 
         /// 設(shè)置日期值
         /// 
         /// 
         /// 
         public void putDateValue(Cell c, object value)
         {
         try
         {
         if (value == null || object.Equals(value, DBNull.Value) || value.ToString().Trim().Length == 0)
         {
         
         }
         else
         {
         c.PutValue(DateTime.Parse(value.ToString()));
         }
         }
         catch (Exception)
         {
         c.PutValue(value.ToString());
         }
         }
         
         
         }
         
        }

        ////實現(xiàn)基類 

        using System;
        using System.Collections.Generic;
        using System.Data;
        using System.Linq;
        using System.Reflection;
        using System.Text;
        using System.Threading.Tasks;
        using Aspose.Cells;
        namespace Lzd.Mvc.EasyUi.Common.ExcelUtil
        {
         /// 
         /// Excel幫助類
         /// 
         public class ExcelUtil :BaseExcelUtil
         {
         private DataTable dt;
         private string title;
         
         public ExcelUtil() {
         
         
         }
         
         /// 
         /// 從第幾行開始讀取
         /// 
         public int FirstRow { get; set; }
         /// 
         /// 從第幾列開始讀取
         /// 
         public int FirstColumns { get; set; }
         
         /// 
         /// excel標題
         /// 
         public string Title
         {
         get { return title; }
         set { title = value; }
         }
         private string fileName;
         
         /// 
         /// 文件名
         /// 
         public string FileName
         {
         get { return fileName; }
         set { fileName = value; }
         }
         
         public DataTable Dt
         {
         get { return dt; }
         set { dt = value; }
         }
         
         public bool Flag
         {
         set;
         get;
         }
         ///
         ///
         ///導出設(shè)定值
         public override void setValue(Workbook wb)
         {
         
         int index = 0;
         Worksheet ws = null;
         int rcount = dt.Rows.Count, columns = dt.Columns.Count;
         if (dt != null && dt.Rows.Count > 0)
         {
         index = wb.Worksheets.AddCopy(0);
         ws = wb.Worksheets[index];
         ws.Name = FileName.Replace(".xls", "");
         
         try
         {
         putValue(ws.Cells[0, 0], this.title);
         int i = 1;
         
         for (int j = 0; j < columns; j++)
         {
         
         putValue(ws.Cells[1, j], dt.Columns[j].ColumnName);
         }
         
         for (int j = 0; j < rcount; j++)
         {
         i++;
         for (int h = 0; h < columns; h++)
         {
         
         putValue(ws.Cells[i, h], dt.Rows[j][h].ToString());
         }
         
         }
         
         wb.Worksheets.RemoveAt(0);
         }
         catch (Exception ex)
         {
         throw ex;
         }
         }
         }
         
         /// 
         /// 導入excel
         /// 
         /// 讀取的文件名
         /// 從第幾行開始讀取
         /// 從第幾列開始讀取
         /// 
         /// 
         
         public override DataTable getValue(Workbook wb)
         {
         
         Worksheet sheet = wb.Worksheets[0];
         Cells cells = sheet.Cells;
         
         return cells.ExportDataTableAsString(FirstRow, FirstColumns, cells.MaxDataRow + 1, cells.MaxDataColumn + 1, true);
         }
         
         
         
         
         
         }
         
        }

        /////導出調(diào)用方法

        public ActionResult ToExcel() {
         List list = new List();
         for (int i = 0; i < 100; i++)
         {
         UserInfo info = new UserInfo();
         info.Age = i.ToString();
         info.ID = i;
         info.Name = "姓名" + i;
         list.Add(info);
         }
         ///將list類型轉(zhuǎn)換為datatable
         DataTable dt= DataTableHelper.IListToDataTable(list);
         //實例化幫助類
         ExcelUtil exc = new ExcelUtil();
         exc.Dt = dt;
         exc.FileName = "導出測試.xls";
         exc.Title = "導出測試";
         //需要寫入的模板
         string url = Server.MapPath("/Content/Down/template.xls");
         byte[] data = exc.CreateExcel(url);
         //瀏覽器下載文件
         Response.AppendHeader("Content-Disposition", "attachment; filename=" + exc.FileName);//HttpUtility.UrlEncode(r.FileName, Encoding.UTF8));
         Response.ContentType = "application/ms-excel";
         Response.AddHeader("Content-Length", data.Length.ToString());
         Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
         Response.BinaryWrite(data);
         System.Web.HttpContext.Current.ApplicationInstance.CompleteRequest();
         return Content("ss");
         }
        

        ///導入調(diào)用方法

        public ActionResult ImportExcel()
         {
         string url = Server.MapPath("/Content/Down/Import.xls");
         ExcelUtil exc = new ExcelUtil();
         exc.FirstRow = 1;
         exc.FirstColumns = 0;
         DataTable dt= exc.GetExcel(url);
         
         
         
         return Content("ss");
         }

        聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        使用Aspose.Cells實現(xiàn)導入導出

        本文實例為大家分享了Aspose.Cells實現(xiàn)導入導出的具體代碼,供大家參考,具體內(nèi)容如下:這是自己整理的導入導出類,里面有注釋。using System;using System.Collections.Generic;using System.Data;using System.IO;using System.Linq;using System.Text;using System.Threading.Tasks;using Aspose.Cells;////// 生成Excel ////// 模板Excel的路徑+文件名 /// Excel文件的字節(jié)對象 public byte[] CreateExcel(string url) { FileStream fs = null。
        推薦度:
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 0588影视手机免费看片| 一区二区三区视频免费| 亚洲成a人片在线观看中文app| 亚洲高清日韩精品第一区| 亚洲国产精品乱码在线观看97| 久久精品成人免费看| 在线观看人成视频免费| 亚洲国产综合久久天堂| 久久国产亚洲精品麻豆| 国产成人精品日本亚洲专区6| 亚洲大码熟女在线观看| 久久综合九色综合97免费下载 | 男男gay做爽爽免费视频| 亚洲国产精品一区二区久久hs | 亚洲无吗在线视频| 日韩一区二区在线免费观看| 亚洲色成人网站WWW永久| 中文日韩亚洲欧美制服| 国产婷婷成人久久Av免费高清 | 中文字幕乱码亚洲无线三区| 国产精品久免费的黄网站| 久久久久亚洲Av片无码v| 美女黄色免费网站| 两性刺激生活片免费视频| 久久久久国产成人精品亚洲午夜 | 亚洲天堂男人天堂| 国产免费人成视频在线播放播| 国产电影午夜成年免费视频| 亚洲成Av人片乱码色午夜| 99久久99热精品免费观看国产| 日韩一卡2卡3卡4卡新区亚洲| 亚洲av日韩aⅴ无码色老头| 国产h视频在线观看网站免费| 国产精品亚洲一区二区麻豆| 国产一级一片免费播放i| 精品亚洲国产成人av| 免费观看大片毛片| 久久精品国产亚洲av瑜伽| 色噜噜亚洲精品中文字幕| 无码国产精品一区二区免费虚拟VR| 在线看亚洲十八禁网站|