在 Open Office 组织中需要将 html 表格查看为 Excel 表格格式的其他设置是什么?
我已经从我的 Web 应用程序生成了一个 html 表,并将该表保存为 .xls 格式(总而言之,我从我的 Web 应用程序生成了一个 .xls 工作表)。
还有哪些设置我必须以表格形式显示。
I have generated a html table from my web application and save the table into .xls format(in a single word i am generating a .xls sheet from my web application ).
What other setting I have to show it in table form.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您生成的不是 XLS 文件,而是名称以 .xls 结尾的格式错误的 HTML 文件。
事实上,您甚至没有这样做,因为网络上没有文件(有些流可能会或可能不会出现在文件中)。
不同版本的 Open Office 具有不同的设置,处理错误内容的方式也会有所不同。你正在做的一台机器上的版本是说“呃,这不是 XLS,哦!这是带有表格的 HTML,我知道该怎么做”,而另一台机器上的版本却是“呃,这不是” t XLS,这是一堆文本,到处都是奇怪的小于和大于字符,我该怎么办”。
您想要做的是生成 Open Office 和其他电子表格可以处理的实际流。 XLS 是可能的,但相当困难。改用 CSV。
如果你的表格是:
那么它应该变成:
换句话说,换行符表示行,逗号表示单元格,没有 HTML 编码,所有内容都加上引号,实际内容中的引号加倍。 (你不需要总是在你的内容上引用,但它永远不会错,所以这比当你确实需要它们时进行计算更简单)。
现在,将您的内容类型设置为“text/csv”。
您现在正在输出可保存为 CSV 文件的 CSV 流。您的电子表格软件将更好地了解如何处理此问题(它可能仍然会在打开时询问字符编码,但预览将向您显示一个数据电子表格,而不是到处都是的一堆 HTML 源代码。
You are not producing an XLS file, you are producing a mal-formed HTML file with a name that ends in .xls.
Indeed, you aren't even doing that since there aren't files on the web (there are streams that may or may not end up in files).
Different versions of Open Office, with different settings, will differ in terms of how they deal with stuff that is wrong. The version on one of the machines you are doing is saying "eh, this isn't XLS, oh! it's HTML with a table, I know what to do", while the other is getting as far as "eh, this isn't XLS, it's a bunch of text with strange less-than and greater-than characters all over the place, what do I do".
What you want to do is to produce an actual stream that Open Office and other spreadsheets can deal with. XLS is possible, but pretty hard. Go for CSV instead.
If your table was going to be:
Then it sould become:
In otherwords newlines to indicate rows, commas to indicate cells, no HTML encoding, quotes around everything and quotes in your actual content doubled-up. (You don't need to always have quotes on your content, but it's never wrong so that's simpler than working out when you do need them).
Now, make your content type "text/csv".
You are now outputting a CSV stream that can be saved as a CSV file. Your spreadsheet software will have a much better idea about what to do with this (it may still ask about character ecodings on opening, but the preview will show you a spreadsheet of data, not a bunch of HTML source all over the place.
它并不是真正另存为 .xls 文件——它似乎是另存为 HTML,但带有 .xls 扩展名。您如何生成 .xls?在服务器端,您可以提供一个按钮来直接生成.xls(根据您的服务器平台有不同的方法 - 使用perl有直接写入.xls的Spreadsheet::WriteExcel模块,使用Java有JExcel(< href="http://jexcelapi.sourceforge.net/" rel="nofollow noreferrer">http://jexcelapi.sourceforge.net/ 和 POI (http://poi.apache.org/)),其他平台也会有他们的方法。
It's not really saving as a .xls file -- it appears to be saving as the HTML, but with a .xls extension. How are you generating the .xls? On the server-side, you can provide a button to generate .xls directly (different methods depending on your server platform -- using perl there is the Spreadsheet::WriteExcel module that writes .xls directly, using Java there is JExcel (http://jexcelapi.sourceforge.net/ and POI (http://poi.apache.org/)), other platforms will have their methods.
好吧,Subodh,如果您想生成 .xls 或 .csv 文件,您不能只更改文件的扩展名并在该程序中正确打开它。
2 此时您拥有的选项都涉及使用服务器上的数据创建文件,然后将其发送给用户进行下载。
.csv
CSV 文件更容易从服务器端生成。以非常基本的方式,您可以将它们视为常规文本文件,用逗号(不一定只是逗号)分隔可以由电子表格程序读取的各个单元格。对于 PHP,有一篇文章这里解释了如何生成 CSV 文件。
.xls
xls 文件不像 CSV 文件那样简单生成。在服务器端,您将需要一个解决方案来生成这些。对于 PHP,此处有一个资源。
与 CSV 相比,使用 xls 具有明显的优势,您可以指定格式并可以控制数据的视觉表示。
编辑 :
仔细查看您发布的图片后,我可以看到您想要做什么。如果您只是想让该文件在电子表格程序中正确打开,则不要将其另存为 CSV 或 xls
hello.html
另存为 HTML 文件将正确打开(作为正确的格式)表)在任何电子表格程序中。
Okay Subodh, If you want to generate .xls or .csv files, You can't just change the extension of the file and have it open up correctly in that program.
2 Options you have at this point, both involve creating the file with the data on the server and then sending it to the user to download it.
.csv
CSV files are easier to generate from the server side. In a very basic way you can think of them as regular text files with commas(not necessarily only commas) separating individual cells that can be read by spreadsheet programs. For PHP there is an article Here that explains how to generate CSV files.
.xls
xls files are not as simple as simple to generate as CSV files. On the server-side you will need a solution to generate these. For PHP there is a resource Here.
Using xls over CSV has obvious advantage that you can specify formatting and can control visual representation of your data.
Edit :
Upon closely looking at the image you posted, I can see what you are trying to do. If you just want to get that file to open correctly in a spreadsheet program, then don't save it either as CSV or xls
hello.html
Saved as an HTML file will open up correctly(as a proper table) in any spreadsheet program.
要缩小问题范围:
1) 您是否在两台计算机上打开相同 .xls 文件?
- 机器 1 上的 OpenOffice 版本是什么?
- 机器 2 上的 OpenOffice 版本是什么?
2) 您如何创建 .xls 文件?
- 您只是使用响应对象来更改内容类型,还是使用某些专有软件?
- 你能提供一个代码示例吗?
3)你尝试过纯HTML格式吗?
To narrow down the problem:
1) Are you opening the same .xls file on both machines?
- what version of OpenOffice is on Machine 1?
- what version of OpenOffice is on Machine 2?
2) How are you creating your .xls file?
- are you just using the response object to change the content-type, or some proprietary software?
- can you include a code sample?
3) Have you tried a pure HTML format?