开发者

How to download and display excel spread sheet within the browser

Need to navigate to Excel spread sheet 开发者_如何学运维and display in the browser. how could I do that ?


I think you dont want to convert the Excel in DataTable if right why dont you use google docs to display your document here are some links

http://docs.google.com/viewer

http://code.google.com/apis/documents/overview.html

http://code.google.com/apis/spreadsheets/

Thanks


the 2 verbs 'navigate to' and 'display in' are not going to work here. even if the user wanted to and agreed to any dialog that was popped by the os, I assure you that the browser is not the registered applicaion for excel.

To get a browser to display an .xls inline you have to render it to the response and set the content-disposition header to inline.

someone else just posted a link to an article that can get you started, just change the content-disposition to 'inline'.


If you have a link to an Excel sheet on your page and the user clicks on it, it will open in Excel, Open Office, Excel viewer or whatever user has associated the file type to. But it will not open inside browser. As far as I know, there are no such plugin available, but even if there is, it depends on what the user has installed in their computer.

If you want to open the sheet in browser, you must convert it into HTML. Open Office has an option to save the sheet as HTML, and I think Excel has that option, too.


Here is simple way to do that..

    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Linq" %>
    <script runat="server" language="C#">    
      public void Page_Load()
      {
        var data = new[] {
          new { NavigateUrl = "http://getfirefox.com" },
          new { NavigateUrl = "http://myweb/myfiles/excel1.xls" }
        };

        var augmentedData =
          from datum in data
          select new
          {
            NavigateUrl = datum.NavigateUrl,
            OnClientClick = "return ViewDoc_onClick('" + datum.NavigateUrl + "');"
          };

        list.DataSource = augmentedData;
        list.DataBind();
      }
    </script>
    <!doctype html>
<!doctype html>
<html>
<head>
  <title>Client Click Test</title>
  <script type="text/javascript">
    var newWindow;
    function ViewDoc_onClick(url) {
      if (newWindow) {
        newWindow.location.href = url;
      }
      else {
        newWindow = window.open(url, 'ViewDoc', 'width=800, height=600');
      }
      newWindow.focus();
      return false;
    }
  </script>
</head>
<body>
  <form runat="server">
  <asp:Repeater ID="list" runat="server">
    <ItemTemplate>
      <asp:Button runat="server" OnClientClick='<%# Eval("OnClientClick") %>' Text='<%# Eval("NavigateUrl") %>' />
    </ItemTemplate>
  </asp:Repeater>
  </form>
</body>
</html>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜