[英]Can't export to excel
I have created a random table and I've been trying to export it as an excel, csv, pdf, and to be able to copy and print the table. 我创建了一个随机表,并且一直在尝试将其导出为excel,csv,pdf,并能够复制和打印该表。 I'm able to do every single thing except export to excel and I'm not sure what's the file that I forgot to add.
除了导出到excel之外,我能够做每件事,而且我不确定我忘记添加的文件是什么。 Here's my code:
这是我的代码:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script src="jquery.js" type="text/javascript"></script> <script src="jquery.dataTables.js" type="text/javascript"></script> <script src="dataTables.buttons.js" type="text/javascript"></script> <script src="buttons.flash.min.js" type="text/javascript"></script> <script src="buttons.html5.min.js" type="text/javascript"></script> <script src="buttons.print.min.js" type="text/javascript"></script> <script src="flashExport.swf" type="text/javascript"></script> <script src="dataTables.buttons.js" type="text/javascript"></script> <script type="text/javascript" src="https://cdn.datatables.net/tabletools/2.2.2/swf/copy_csv_xls_pdf.swf"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script> <script type="text/javascript" src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/pdfmake.min.js"></script> <script type="text/javascript" src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/vfs_fonts.js"></script> </head> <body> <table id="demoTable"> <thead> <tr> <th> Name</th> <th> Program</th> <th> Age</th> <th> Homecity</th> </tr> </thead> <tbody> <tr> <td> A</td> <td> Computer Engineering</td> <td> 20 Years old</td> <td> Mississauga</td> </tr> <tr> <td> B</td> <td> Computer Engineering</td> <td> 19 Years old</td> <td> Vancouver</td> </tr> <tr> <td> C</td> <td> Computer Engineering</td> <td> 19 Years old</td> <td> Vancouver</td> </tr> <tr> <td> D</td> <td> Computer Engineering</td> <td> 19 years old</td> <td> Ottawa</td> </tr> </tbody> </table> </body> <script type="text/javascript"> $(function() { $("#demoTable").DataTable({ dom: 'Bfrtip', buttons: ['csv', 'excel', 'pdf', 'copy', 'print'] }); }) </script>
Thank you in advance for helping me. 预先感谢您对我的帮助。
It's possible that the jQuery script tag outside of the <html>
is causing issues with other resources loading. <html>
之外的jQuery脚本标签可能导致其他资源加载出现问题。 You also want to make sure the <script>
containing the DataTable()
initialization/configuration is inside the <body>
tag or loaded as separate file within the <body>
or <head>
. 您还想确保包含
DataTable()
初始化/配置的<script>
位于<body>
标记内,或作为单独的文件加载到<body>
或<head>
。 I'd make sure by inspecting source on your instance that you can see each and every file being successfully loaded from your local file system/server. 通过检查实例上的源,我可以确保可以看到每个文件都已从本地文件系统/服务器成功加载。
Also, I'd re-evaluate the <script>
resources with file type .swf
, the working example is only using .js
resources. 另外,我将重新评估文件类型为
.swf
的<script>
资源,工作示例仅使用.js
资源。 If you need to include .swf
files you would likely need to embed them. 如果需要包括
.swf
文件,则可能需要嵌入它们。 See this question . 看到这个问题 。
I've created a working example here including exporting to excel. 我在这里创建了一个工作示例,包括导出到excel。
Hopefully that helps! 希望有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.