关闭

net处理Excel

标签: buttondatasetserverstringpropertiesfile
328人阅读 评论(0) 收藏 举报

aspx:
<form id="form1" runat="server">
    <div>
        <input id="File1" type="file" name="File1" runat=server /><br />
        <br />
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /><br />
        <br />
        <asp:GridView ID="GridView1" runat="server">
        </asp:GridView>
        &nbsp;</div>
    </form> 

using System.Data.OleDb;
protected void Button1_Click(object sender, EventArgs e)
    {
        string source = File1.Value;
        string ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +source+";Extended Properties=Excel 8.0";
        string query = "select * from [Sheet1$]";

        OleDbCommand cmd = new OleDbCommand(query, new OleDbConnection(ConnStr));
        OleDbDataAdapter adp= new OleDbDataAdapter(cmd);
        DataSet ds= new DataSet();
        adp.Fill(ds,"[Sheet1$]");

        GridView1.DataSource = ds;
        GridView1.DataMember = "[Sheet1$]";
        GridView1.DataBind();
    }

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:30670次
    • 积分:395
    • 等级:
    • 排名:千里之外
    • 原创:11篇
    • 转载:9篇
    • 译文:0篇
    • 评论:3条
    文章分类
    最新评论