怎么利用Aspose.Cells 獲取excel 數據表中sheet的名稱


說明:開發環境 vs2012 asp.net mvc4 c#

           利用Aspose.Cells 獲取Excel數據表的sheet的名稱,並把獲取的名稱賦值給easyUI 的combobox

1、運行效果

    

2、項目結構

 

Couse.xlsx數據表的sheet如下圖所示

3、HTML前端代碼

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="EasyuiCombotree.aspx.cs" Inherits="MvcAppTest.EasyuiCombotree" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Easyui Combotree 測試</title>
    <link href="Easyui/themes/default/easyui.css" rel="stylesheet" />
    <script src="Easyui/jquery-1.7.2.js"></script>
    <script src="Easyui/jquery.easyui.min.js"></script>
    <script src="Easyui/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript"> $(function () { $('#dd').combobox({ url: 'Home/getGSParam', valueField: 'id', textField: 'text', required: true, queryParams: { OFFID: 100 }, editable: false,//不可編輯,只能選擇
 disabled: false, value: '選擇sheet' }); }); </script>
</head>
<body>

    <div>
        <div><span>以下是獲取到的Excel數據表的sheet的名稱</span></div>
        <div>
            <input id="dd" name="sheetList" value="" />
        </div>
    </div>
</body>
</html>

4、Home控制器后台 代碼

using Aspose.Cells; public JsonResult getGSParam(string OFFID) { string filePath = Server.MapPath("~/loaclData/Excel/Couse.xlsx"); List<ComboModel> myList = new List<ComboModel>(); Workbook book = new Workbook(filePath); WorksheetCollection myColection = book.Worksheets; int k1 = myColection.Count; for (int i = 0; i < k1; i++) { ComboModel model = new ComboModel() { id = i, text = myColection[i].Name }; myList.Add(model); } return Json(myList, JsonRequestBehavior.DenyGet); } public class ComboModel { public System.Int32 id { get; set; } public System.String text { get; set; } }

5、引用文件下載地址

easyui 引用文件 下載地址

鏈接:https://pan.baidu.com/s/1KxL2QeVEbEVHU9UxV6LBWw
提取碼:cwbd

Aspose.Cells引用文件下載地址

鏈接:https://pan.baidu.com/s/1TTcrTIVO4nkC2TH27whFwQ
提取碼:2w1j

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM