开发者

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

开发者 https://www.devze.com 2023-01-24 14:37 出处:网络
I am trying to display display .xls file data in a browser(prefer ie,ff,chrome and safari) as a web content.

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 co开发者_如何转开发mputer 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.


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).


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


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.


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(); }

0

精彩评论

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