怎么利用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控制器后台 代码

扫描二维码关注公众号,回复: 4938070 查看本文章
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

猜你喜欢

转载自www.cnblogs.com/net064/p/10276107.html