Html 如何创建 Excel 文件的下载链接?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8752698/
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 create a download-link to an Excel file?
提问by Lloydworth
I have an Excel Spreadsheet (.xls) which i want the users to be able to download it from my webpage. Maybe a 'download' button on the page and when users click on it, the file will be downloaded.
我有一个 Excel 电子表格 (.xls),我希望用户能够从我的网页下载它。也许页面上有一个“下载”按钮,当用户点击它时,文件将被下载。
May i know how can this be done? Code snippets and references will be appreciated.
我可以知道怎么做吗?代码片段和参考将不胜感激。
回答by Naveed
You can use simple html links:
您可以使用简单的 html 链接:
link:
链接:
<a href='/path/to/excel/file.xls' target="_blank">Download</a>
button:
按钮:
<form>
<input type="button" value="Download" onClick="window.location.href='/path/to/excel/file.xls'">
</form>
回答by Christofer Eliasson
How about just referring to the file through an anchor?
仅通过锚点引用文件怎么样?
<a href="path-to-file.xls">Download</a>
回答by divya gangadhar
I think this should be fine too:
我认为这也应该没问题:
<a href="path-to-file" download="abc.xls">Download</a>
download: name of file to be downloaded as.
下载:要下载的文件名。