说明:开发环境 vs2012 asp.net mvc4 c#

利用Aspose.Cells 获取Excel数据表的sheet的名称,并把获取的名称赋值给easyUI 的combobox

1、运行效果

怎么利用Aspose.Cells 获取excel 数据表中sheet的名称-LMLPHP

2、项目结构

怎么利用Aspose.Cells 获取excel 数据表中sheet的名称-LMLPHP

Couse.xlsx数据表的sheet如下图所示

怎么利用Aspose.Cells 获取excel 数据表中sheet的名称-LMLPHP

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 = ; 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

04-28 01:05