Html 如何在html页面中显示excel表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9678127/
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
how to display excel sheet in html page
提问by coolcake
I want to display EXCEL sheet embedded in IE with plain HTML. I have gone through other questions on stackoverflow but could not find any useful one.
我想用纯 HTML 显示嵌入在 IE 中的 EXCEL 表。我已经解决了有关 stackoverflow 的其他问题,但找不到任何有用的问题。
Here is my html file
这是我的 html 文件
<html>
<body>
<object width = 900 height = 500 id = "excel" data="Issues Identified.xlsx" classid = "clsid:0002E55a-0000-0000-C000-000000000046" VIEWASTEXT >
<param name="DisplayTitleBar" value=true />
<param name="DataType" value="CSVURL"/>
<param name="AutoFit" value="0"/>
<param name="DisplayColHeaders" value="1"/>
<param name="DisplayGridlines" value="1"/>
<param name="DisplayHorizontalScrollBar" value="1"/>
<param name="DisplayRowHeaders" value="1"/>
<param name="DisplayTitleBar" value="1"/>
<param name="DisplayToolbar" value="1"/>
<param name="DisplayVerticalScrollBar" value="1"/>
<param name="EnableAutoCalculate" value="0"/>
<param name="EnableEvents" value="0"/>
<param name="MoveAfterReturn" value="1"/>
<param name="MoveAfterReturnDirection" value="0"/>
<param name="RightToLeft" value="0"/>
</object>
</body>
</html>
Unfortunately I do not have control on the excel files that are generated. If I would have control on the excel files I could have have saved them as web pages and included in the browser. Now I doubt if by any way through above code I can embed excel sheet directly in the web browser. There are many links on web but found not find one which directly loads a excel sheet in to the browser. The ones that are there are using javascript to generate graphs and all instead of displaying an excel sheet which is already present.
不幸的是,我无法控制生成的 excel 文件。如果我可以控制 excel 文件,我可以将它们保存为网页并包含在浏览器中。现在我怀疑是否可以通过上面的代码直接在 Web 浏览器中嵌入 excel 表。网络上有很多链接,但没有找到一个可以直接将 Excel 表格加载到浏览器中的链接。那里的那些使用javascript来生成图形,而不是显示已经存在的excel表。
When I try to load the excel sheet through above code. I get the following screen
当我尝试通过上面的代码加载 excel 表时。我得到以下屏幕
When I use IFRAME the excel sheet is not shown as embedded file but prompting to download or open. I want it to open embedded in the internet explorer.
当我使用 IFRAME 时,Excel 工作表不会显示为嵌入文件,而是提示下载或打开。我希望它嵌入在 Internet Explorer 中打开。
Any help much appreciated.
非常感谢任何帮助。
Thanks
谢谢
回答by iotapaw
Depending on if you want it to automatically update or not, you can just save the excel spreadsheet as a PDF then embed the PDF as an object -
根据您是否希望它自动更新,您可以将 Excel 电子表格保存为 PDF,然后将 PDF 作为对象嵌入 -
It appears you don't have a PDF plugin for this browser, but you can click here to download the PDF file.
您似乎没有适用于该浏览器的 PDF 插件,但您可以 单击此处下载 PDF 文件。
It's the best way I have found for uploading.
这是我找到的最好的上传方式。
回答by erfan
Upload your file to Skydrive and then right click and select "Embed". They will provide iframe snippet which you can paste in your html. This works flawlessly.
将您的文件上传到 Skydrive,然后右键单击并选择“嵌入”。他们将提供 iframe 片段,您可以将其粘贴到您的 html 中。这完美无缺。
Source: Office.com
资料来源:Office.com
回答by kingjeffrey
You can upload it into Google Docs, and embed the Google Spreadsheet as detailed here: http://support.google.com/docs/bin/answer.py?hl=en&answer=55244
您可以将其上传到 Google 文档中,并按照此处的详细说明嵌入 Google 电子表格:http: //support.google.com/docs/bin/answer.py?hl=en& answer=55244
回答by Tony Dallimore
Like you, I cannot get MS Office Web Components to work. I would not consider Google Docs since Google seems to think they own anything that passes through their hands. I have tried MS Publish Objects but the quality of the generated html/css is truely awful.
像您一样,我无法让 MS Office Web Components 工作。我不会考虑 Google Docs,因为 Google 似乎认为他们拥有任何经过他们手中的东西。我尝试过 MS Publish Objects,但生成的 html/css 的质量真的很糟糕。
The secret of converting an Excel worksheet to html that will display correctly on a smartphone is to create clean, lean html/css.
将 Excel 工作表转换为可在智能手机上正确显示的 html 的秘诀是创建干净、简洁的 html/css。
The structure of the HTML is:
HTML的结构是:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
HEAD
</head>
<body>
BODY
</body>
</html>
There are useful html elements that can replace "HEAD" but it is not clear to me how you would generate them from an Excel worksheet. They would need to be added separately.
有一些有用的 html 元素可以替换“HEAD”,但我不清楚如何从 Excel 工作表生成它们。它们需要单独添加。
The obvious output for a worksheet or a range is an html table so the following assumes BODY will be replaced by an html table.
工作表或范围的明显输出是 html 表,因此以下假设 BODY 将被 html 表替换。
The structure of an html table is:
一个html表的结构是:
<table TABLE-ATTRIBUTES>
<tr TABLE-ROW-ATTRIBUTES>
<td TABLE-CELL-ATTRIBUTES>CELL-VALUE</td>
More <td>...</td> elements as necessary
</tr>
More <tr>...</tr> as necessary
</table>
Include as few TABLE-ATTRIBUTES, TABLE-ROW-ATTRIBUTES and TABLE-CELL-ATTRIBUTES as possible. Do not set column widths in pixels. Use css attributes rather than html attributes.
包括尽可能少的 TABLE-ATTRIBUTES、TABLE-ROW-ATTRIBUTES 和 TABLE-CELL-ATTRIBUTES。不要以像素为单位设置列宽。使用 css 属性而不是 html 属性。
A table attribute worth considering is style = "border-collapse: collapse;"
. The default is separate
with a gap around each cell. With collapse
the cells touch as they do with Excel.
一个值得考虑的表属性是style = "border-collapse: collapse;"
. 默认情况下separate
,每个单元格周围都有间隙。随着collapse
细胞触摸,因为他们用Excel做。
Three table attribute worth considering are style="background-color:aliceblue;"
, style="color:#0000FF;"
and style="text-align:right;"
. With the first, you can specify the background colour to be any of the fifty or so named html colours. With the second, you can specify the font colour to be any of 256*256*256 colours. With the third you can right-align numeric values.
值得考虑的三个表属性是style="background-color:aliceblue;"
,style="color:#0000FF;"
和style="text-align:right;"
。对于第一个,您可以将背景颜色指定为五十种左右命名的 html 颜色中的任何一种。使用第二个,您可以将字体颜色指定为 256*256*256 色中的任何一种。使用第三个,您可以右对齐数值。
The above covers only a fraction of the formatting information that could be converted from Excel to html/css. I am developing an add-in that will convert as much Excel formatting as possible but I hope the above helps anyone with simple requirements.
以上仅涵盖了可以从 Excel 转换为 html/css 的一小部分格式信息。我正在开发一个加载项,它将尽可能多地转换 Excel 格式,但我希望以上内容可以帮助任何有简单要求的人。
回答by Tom
Office 365 and OneDrive offer an embed feature. You can then include via IFrame.
Office 365 和 OneDrive 提供嵌入功能。然后您可以通过 IFrame 包含。
I found that setting the iframe height and width to 100% works best. That way on ipad or any device for that matter it fits the screen.
我发现将 iframe 的高度和宽度设置为 100% 效果最好。这样在 ipad 或任何设备上它都适合屏幕。
<body style="margin:0px;padding:0px;overflow:hidden">
<iframe src="embed url" frameborder="0" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;height:100%;width:100%;position:absolute;top:0px;left:0px;right:0px;bottom:0px" height="100%" width="100%"></iframe>
</body>
回答by David Jones - iPushPull
You can use iPushPullto push live data direct from an Excel session to the web where you can display it in an IFRAME (or using a WordPress plugin, if applicable). The data in the frame will update whenever the data on the sheet updates.
您可以使用iPushPull将实时数据直接从 Excel 会话推送到 Web,您可以在其中将其显示在 IFRAME(或使用 WordPress 插件,如果适用)。每当工作表上的数据更新时,框架中的数据就会更新。
The iPush(...) in-cell functionpushes data from Excel to the web.
该iPush(...)在细胞功能推动从Excel数据到网上。
This support pagedescribes how to embed your Excel data in your website.
此支持页面描述了如何在您的网站中嵌入 Excel 数据。
Disclaimer - I work for iPushPull.
免责声明 - 我为 iPushPull 工作。
回答by Szundi
Maybe you might try the web to send the file with proper Content-Type header and with the header like this:
也许您可以尝试通过 Web 发送带有正确 Content-Type 标头和如下标头的文件:
Content-Disposition: inline; filename="xxx.xxx"
Here is a discussion about these headers: How to force files to open in browser instead of download (pdf)?
以下是关于这些标题的讨论:如何强制文件在浏览器中打开而不是下载 (pdf)?
Or just search on google for content-disposition.
或者只是在谷歌上搜索内容配置。
回答by abid khan
If you are making a link <a href='file.htm'>link name</a>
or place an iframe tag, it will show the excel data on web but you can't make changes to it.
如果您正在制作链接<a href='file.htm'>link name</a>
或放置 iframe 标签,它将在网络上显示 Excel 数据,但您无法对其进行更改。
Every time you make changes in the Excel sheet you have to save again with the same name so it will replace file, and will show the result. The <a>
tag file name extension should be .htm
每次在 Excel 工作表中进行更改时,您都必须使用相同的名称再次保存,以便它将替换文件并显示结果。该<a>
标记文件的扩展名应该是.htm
回答by Wolfgang Kuehn
Note that Office Web Components are dead, see does-office-xp-web-components-compatable-with-windows-7. OWC was discontinued from XP onward for security reasons.
请注意,Office Web Components 已死,请参阅dos-office-xp-web-components-compatable-with-windows-7。出于安全原因,OWC 从 XP 开始停止使用。
Since then, and only recently, Microsoft pushes Excel Web App as alternative (a poor alternative IMHO)
从那时起,直到最近,Microsoft 才将 Excel Web App 作为替代方案(恕我直言,这是一个糟糕的替代方案)
As a side note: Microsoft also deprecated the other way round, i.e. embedding the webbrowser control into an excel sheet, see adding-web-browser-control-to-excel-2013. As an alternative Microsoft offers Office Apps (a very limited alternative with respect to interfacing Excel and IE)
附带说明:Microsoft 也弃用了相反的方法,即将 webbrowser 控件嵌入到 Excel 工作表中,请参阅added-web-browser-control-to-excel-2013。作为替代方案,Microsoft 提供了 Office Apps(在连接 Excel 和 IE 方面非常有限的替代方案)