我正在尝试读取 Excel 并将其绑定到网页中,这是我的初始代码。当我在浏览器中运行它时,它所做的只是显示代码而不是执行它。这是保存为chtml的代码:
@{
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Excel Read Test</title>
</head>
<body>
string ExcelFile = Server.MapPath("App_Data/Pending_Requests.xls");
string connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + ExcelFile + ";Extended Properties=Excel 8.0;";
using (OleDbConnection conn = new OleDbConnection(connString))
{
using (OleDbCommand cmd = new OleDbCommand())
{
cmd.Connection = conn;
cmd.CommandText = "SELECT * FROM [EAST]";
conn.Open();
OleDbDataReader dr = cmd.ExecuteReader();
GridView1.DataSource = dr;
GridView1.DataBind();
conn.Close();
}
}
</body>
如何执行此代码?