如何浏览&使用asp.net在Web浏览器中显示Excel工作表?

时间:2014-10-10 10:35:14

标签: asp.net excel

我想浏览excel输入文件&在网络浏览器上显示它它必须可以在网络浏览器上编辑, 我正在使用C#asp.net进行编码。任何帮助都是gr8。事先提前。

2 个答案:

答案 0 :(得分:0)

我认为您拥有的选项是HTML表格或Google Spreadsheets / Microsoft Excel Online。

欲了解更多信息:

http://www.labnol.org/software/embed-tables-spreadsheet-data-in-websites/7435/

答案 1 :(得分:0)

在网络表单中:


背后的代码:

    protected void UploadFile(object sender, EventArgs e)
    {
        string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
        FileUpload1.PostedFile.SaveAs(Server.MapPath("~/Uploads/") + fileName);
        Response.Redirect(Request.Url.AbsoluteUri);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string[] filePaths = Directory.GetFiles(Server.MapPath("~/Uploads/"));
            List<ListItem> files = new List<ListItem>();
            foreach (string filePath in filePaths)
            {
                files.Add(new ListItem(Path.GetFileName(filePath), filePath));
                Fileddl.Items.Add(new ListItem(Path.GetFileName(filePath), Path.GetFileName(filePath)));
            }                              
        }
    }
    protected void OpenFile(object sender, EventArgs e)
    {
        
        string filePath = Fileddl.SelectedItem.Value;
        Myframe.Visible = true;
        Myframe.Attributes.Add("src", "https://view.officeapps.live.com/op/embed.aspx?src=https://www.yoursite.com/Uploads/" + Path.GetFileName(filePath));
    }
    protected void DownloadFile(object sender, EventArgs e)
    {
        string filePath = Fileddl.SelectedItem.Value;
        Response.ContentType = ContentType;
        Response.AppendHeader("Content-Disposition", "attachment; filename=https://www.yoursite.com/Uploads/" + Path.GetFileName(filePath));
        Response.WriteFile(filePath);
        Response.End();
    }
    
    protected void DeleteFile(object sender, EventArgs e)
    {
        string filePath = Fileddl.SelectedItem.Value;
        File.Delete(filePath);
        Response.Redirect(Request.Url.AbsoluteUri);
    }