javascript 将excel文件转换为html和javascript
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19600778/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
convert excel file to html and javascript
提问by BigGirl1017
i have one excel calculator file which contains several sheets and formulas searching across sheets.
我有一个 excel 计算器文件,其中包含多个工作表和跨工作表搜索的公式。
i want to convert this calculator in html page, and using javascript to do the calculation. I've built up mySQL database to store these data for lookups...using php forms should get user inputs
我想在 html 页面中转换这个计算器,并使用 javascript 进行计算。我已经建立了 mySQL 数据库来存储这些数据以供查找……使用 php 表单应该获取用户输入
I am concerned with the logic and layout in excel is not so straightforward as in javascript using functions.
我关心的是 excel 中的逻辑和布局不像在 javascript 中使用函数那么简单。
Is there a way to do this that ensures the accuracy?
有没有办法做到这一点,以确保准确性?
采纳答案by pax162
I did something like this once. Basically you have to get two things right. The html and the Javascript to compute the formulas :D. To generate the html from the excel I recommend saving the Excel sheet as a web page and study the generated html. You can use it as it is, modify it, or you feel brave enough, try to build a generator yourself. It will be hard to build a generator, it took me about 1.5 months to get all the quirks right.
我曾经做过这样的事情。基本上你必须做对两件事。用于计算公式的 html 和 Javascript :D。要从 excel 生成 html,我建议将 Excel 工作表另存为网页并研究生成的 html。你可以照原样使用它,修改它,或者你觉得足够勇敢,尝试自己构建一个生成器。建造一个发电机会很困难,我花了大约 1.5 个月的时间才把所有的怪癖都弄对了。
The formulas are pretty tough as well. In your case, probably you need to translate a couple of formulas, which can be done by hand. Just assign an unique id to each td in the html (it can be the cellId from excel, like R30), and translate the formulas to JS. To mimic the excel cells, you can place input[type=text] tags in the editable tds.
公式也很严格。在您的情况下,您可能需要翻译几个可以手动完成的公式。只需为html中的每个td分配一个唯一的id(它可以是excel中的cellId,如R30),并将公式转换为JS。要模仿 Excel 单元格,您可以在可编辑的 tds 中放置 input[type=text] 标签。
To make a generic formula translator, that works with all formulas is a lot harder. I used ANTLR with an excel grammar. ANTLR then generates a lexer/parser and with the extracted AST we can finally get Javascript formulas. Took another 3 weeks to get everything right.
要制作一个适用于所有公式的通用公式转换器要困难得多。我将 ANTLR 与 excel 语法一起使用。ANTLR 然后生成一个词法分析器/解析器,通过提取的 AST,我们最终可以得到 Javascript 公式。又花了 3 周时间才把一切都做好。
回答by Rafael Luiz
You can not run an xls file on a website, unless you have a program like Excel, which can be run as a CGI program. (IOW
你不能在网站上运行 xls 文件,除非你有像 Excel 这样的程序,它可以作为 CGI 程序运行。(爱荷华州