Excel到HTML表格 [英] Excel to HTML table
问题描述
我是网络编程的新手,我正在开发的第一个项目是一个网站,它允许用户从Excel文件(每日更新)中查看信息。在Youtube教程和此库的帮助下,我开始将Excel文件转换为JSON。 https:// github .com / SheetJS / js-xlsx 。
我有要转换为对象的信息,但我不知道如何使用它来显示网站中的表格。任何建议?
这是我目前的代码:
/ *设置XMLHttpRequest * / var url =Teste.xlsx; var oReq = new XMLHttpRequest(); oReq.open(GET,url,true); oReq.responseType =arraybuffer; oReq.onload = function(e){var arraybuffer = oReq.response; / *将数据转换为二进制字符串* / var data = new Uint8Array(arraybuffer); var arr = new Array(); for(var i = 0; i!= data.length; ++ i)arr [i] = String.fromCharCode(data [i]); var bstr = arr.join(); / *调用XLSX * / var workbook = XLSX.read(bstr,{type:binary}); / *使用工作簿在这里工作* / var first_sheet_name = workbook.SheetNames [0]; // var address_of_cell ='A1'; / *获取工作表* / var worksheet = workbook.Sheets [first_sheet_name]; XLSX.utils.sheet_to_json(工作表); }
< script src =>< code> https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js\"></script><!doctype html>< html>< head> <标题>试验< /标题> < / script>< / script>< / head>< body>< / body>< / html> 解决方案
Excel文件可以导出为html文件,或者您可以通过多种方式 EMBED 将excel文件导入html文件。
-
您可以使用办公室在线创建excel文件后,转至文件菜单,然后选择共享即可。使用生成的HTML进行嵌入。
如果您不局限于excel,您可以使用带有Google表格文档,并在表格中选择发布到网页选项;嵌入式 Google表格会更新以反映更新。 - 如果您真的很匆忙,可以使用 Tableizer 等工具将文件转换为HTML表格,但是我不会推荐这个作为学习工具。 (这是供将来参考)
希望这可以帮助您
I'm new to web programming and the first project that i'm working on is a web site that allows the user to see information from an Excel file (which is updated daily). I started from converting the Excel file to JSON with the help of a Youtube tutorial and this library https://github.com/SheetJS/js-xlsx.
I have the information that i want converted to objects but I don't know how to use it to show a table in a website. Any suggestions?
This is my current code:
/* set up XMLHttpRequest */
var url = "Teste.xlsx";
var oReq = new XMLHttpRequest();
oReq.open("GET", url, true);
oReq.responseType = "arraybuffer";
oReq.onload = function(e) {
var arraybuffer = oReq.response;
/* convert data to binary string */
var data = new Uint8Array(arraybuffer);
var arr = new Array();
for (var i = 0; i != data.length; ++i) arr[i] = String.fromCharCode(data[i]);
var bstr = arr.join("");
/* Call XLSX */
var workbook = XLSX.read(bstr, {
type: "binary"
});
/* DO SOMETHING WITH workbook HERE */
var first_sheet_name = workbook.SheetNames[0];
//var address_of_cell = 'A1';
/* Get worksheet */
var worksheet = workbook.Sheets[first_sheet_name];
XLSX.utils.sheet_to_json(worksheet);
}
oReq.send();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!doctype html>
<html>
<head>
<title>Test</title>
<script src="xlsx.full.min.js"></script>
</head>
<body>
</body>
</html>
Think you're over-complicating things a bit.
Excel files can be exported as html files and or you can EMBED the excel file into a html file in a number of ways.
You could create a live excel file using office online Once the excel file is created , go to to the File menu, and choose Share. Embed using generated HTML.
If you are not confined to excel, you could alternatively use an iframe with a "Google Sheets" document created with the data and choose the "Publish to the web" option in the sheet; an embedded google sheet will update to reflect updates.
- If you are really in a hurry you can convert your file into a HTML table using a tool like Tableizer but I wouldn't recommended this as a learning tool. (this is for future reference)
Hope this helps
这篇关于Excel到HTML表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!