是否有可能從一個Excel文件的jqGrid導入數據在ASP.NET MVC 4是否可以將數據從Excel導入jQGrid?
我看看這個例子here但它不正是談論從Excel文件導入數據。我試圖解決它,但數據不顯示在jqGrid上。我所得到的只是一張只有標題的空表。任何幫助將是巨大的:)
我查看代碼:jqGrid的:
<table id="jQGridDemo"></table>
<div id="jQGridDemoPager"></div>
<script type="text/javascript">
jQuery("#jQGridDemo").jqGrid({
url: 'TopPlayedInVenueList',
datatype: "json",
colNames: ['Id', 'First Name', 'Last Name', 'Last 4 SSN', 'Department',
'Age'],
colModel: [
{ name: '_id', index: '_id', width: 20, stype: 'text' },
{ name: 'FirstName', index: 'FirstName', width: 150 },
{ name: 'LastName', index: 'LastName', width: 150 },
{ name: 'LastSSN', index: 'LastSSN', width: 100 },
{ name: 'Department', index: 'Department', width: 80, align: "right" },
{ name: 'Age', index: 'Salary', width: 80, align: "right" }
],
rowNum: 10,
sortname: 'id',
viewrecords: true,
sortorder: "desc",
caption: "List Employee Details"
});
</script>
我的控制器代碼:
public JsonResult TopPlayedInVenueList()
{
try
{
if (Request.IsAuthenticated == true)
{
string Path = @"C:\\1.xls";
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source= '" + Path + "';Extended Properties=" + (char)34 + "Excel 8.0;IMEX=1;" + (char)34 + "");
OleDbDataAdapter da = new OleDbDataAdapter("select * from [All$A2:Z]", con);
//OleDbDataAdapter da = new OleDbDataAdapter("select * from [All$]", con);
con.Close();
System.Data.DataTable data = new System.Data.DataTable();
da.Fill(data);
List<TopPlayedInVenue> daa = new List<TopPlayedInVenue>();
foreach (DataRow p in data.Rows)
{
TopPlayedInVenue top = new TopPlayedInVenue()
{
TrackName = p.Field<string>("Track Name"),
ArtistName = p.Field<string>("Artist Name")
};
daa.Add(top);
}
var newlist = daa.OrderBy(i => i.TrackName).ToList();
return Json(daa);
感謝提前:)
如果你調試你的代碼,你看到了什麼?我首先看到的是在調用Fill()方法之前關閉連接,但不確定這是否會成爲問題。 – Romias
此外,嘗試做一個更簡單的選擇...不使用範圍...只是爲了看看這可能是問題。 – Romias
@Romias - 感謝您的輸入,我已經清除了代碼:) - 也做了一個簡單的選擇只是爲了檢查,但沒有奏效。 – pv619