display .xls file data in a browser as a web content

血红的双手。 提交于 2019-12-12 02:27:59

问题


I am trying to display display .xls file data in a browser(prefer ie,ff,chrome and safari) as a web content.

The thing is i have an .xls file in my computer where i'll all the data manipulations in the xls file and want the data in it to b displayed in a browser for others to see just as a content in a webpage.

I am planning this with a javascript, could anyone help me with this? i almost tried all the possible ways and all the posts in many sites about this kind of procedure but nothing suited my idea. I wld really appriciate if anyone cld get me out of this problem.


回答1:


You're almost certainly going to have to do this transformation server-side. Client-side javascript is going to be tricky if not impossible, because an XLS file is not HTML, and so cannot have <script> tags in it to tell the browser what to do. You could possibly embed the XLS in an iframe, and have the JS operate on it, but iframes can be a pain to work with, and are deprecated in HTML 5 (to my understanding). Even if this could work cleanly it still doesn't sound like client-side processing of the raw document is a good idea.

So first step is to investigate what server-side technologies (e.g. PHP, JSP, ASP) you have available. Second step is to find a library for one of these technologies that is capable of opening and reading XLS files (not a simply task). Then the third step is to write the required code to open your XLS file, extract the required information and output it as HTML. (It may help to think of this third step as transforming an XLS input into an HTML output, which is exactly what you're trying to do).




回答2:


The only way i know of, would be to set the file as the document source of an iframe tag, but this element is going to be removed from HTML as of version 5. In any way, your browser will have to support displaying those documents in your browser window.




回答3:


Here is a code snippet how to import Excel to DataTable in your Excel ASP.NET application with use of this excellent Excel C# component:

private void Page_Load(object sender, System.EventArgs e) { var ef = new ExcelFile(); ef.LoadXls(Server.MapPath("../ExcelData.xls"));

// Initialize DataTable (skip this if you have DataTable definition) var dt = new DataTable(); dt.Columns.Add("name", typeof(string)); dt.Columns.Add("birth", typeof(DateTime));

var ws = ef.Worksheets[0];

// Extract data to DataTable ws.ExtractToDataTable(dt, ws.Rows.Count, ExtractDataOptions.StopAtFirstEmptyRow, ws.Rows[0], ws.Columns[0]);

DataGrid1.DataSource = dt.DefaultView; DataGrid1.DataBind(); }




回答4:


Is'nt it an option to simply save the xls as an HTML-document out of Excel?



来源:https://stackoverflow.com/questions/4144062/display-xls-file-data-in-a-browser-as-a-web-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!