简体   繁体   中英

display .xls file data in a browser 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 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.

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

我知道的唯一方法是将文件设置为iframe标记的文档源,但是从5版开始,该元素将从HTML中删除。无论如何,您的浏览器将必须支持显示这些文档。在浏览器窗口中。

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

将Excel文件简单地另存为HTML文档不是一种选择吗?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM