- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
我有一个包含表格 View 的简单 HTML 页面(由外部应用程序生成)。我试图从页面上刮下表格并将它们放入 Excel 工作簿中。我已经设法通过使用可用的方法将整个 HTML 内容放入工作簿中 here .
相关问题的代码:
var tableToExcel = (function() {
var uri = 'data:application/vnd.ms-excel;base64,'
, template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
, base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
, format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }
return function(table, name) {
if (!table.nodeType) table = document.getElementById(table)
var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
window.location.href = uri + base64(format(template, ctx))
}
})()
但是该方法不支持多个电子表格。我需要的是每个 HTML 表格都在同一个 Excel 工作簿中自己的 SpreadSheet 中。是这样的:
我曾尝试使用两个电子表格创建示例 Excel 文档,然后通过查看 .html 格式的导出文件对其进行逆向工程。不幸的是,我不明白如何重新创建工作簿和工作表之间的连接。
据我所知,format()
函数实现了工作表数据和 Excel 模板的“神奇”组合。这个函数对我来说看起来很神秘,所以我不知道如何修改它。
作为最终游戏,我需要的是能够调用类似的东西。tableToExcel(document.getElementsByTagName('table'), '工作簿名称');
如果这完全可能,您有什么想法吗?如果可以,如何实现它?
最佳答案
查看此博文:http://www.kubilayerdogan.net/?p=218
$(document).ready(function() {
$("#btnExport").click(function(e) {
//getting values of current time for generating the file name
var dt = new Date();
var day = dt.getDate();
var month = dt.getMonth() + 1;
var year = dt.getFullYear();
var hour = dt.getHours();
var mins = dt.getMinutes();
var postfix = day + "." + month + "." + year + "_" + hour + "." + mins;
//creating a temporary HTML link element (they support setting file names)
var a = document.createElement('a');
//getting data from our div that contains the HTML table
var data_type = 'data:application/vnd.ms-excel';
var table_div = document.getElementById('dvData');
var table_html = table_div.outerHTML.replace(/ /g, '%20');
a.href = data_type + ', ' + table_html;
//setting the file name
a.download = 'exported_table_' + postfix + '.xls';
//triggering the function
a.click();
//just in case, prevent default behaviour
e.preventDefault();
});
});
您可以在 jsfiddle 中看到它的运行情况:http://jsfiddle.net/kublaios/8ZQN4/1/
关于javascript - 在单独的工作表中将 HTML 表格导出到 Excel (.xls),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18234448/
我正在使用 Python 2.76 向 .aspx 网页提交查询并通过 BeautifulSoup 获取结果,并希望将它们存储到 Excel 电子表格中。 import mechanize impor
我正在学习使用 Hadoop 执行大数据相关操作。 我需要对拆分为 8 个 xls 文件的数据集集合执行一些查询。每个 xls 文件都有多个工作表,查询只涉及其中一个工作表。 数据集可以在这里下载:h
我有一个 excel 文件,但文件大小太大,您有什么建议可以让我们以相同的格式减小文件大小吗? 最佳答案 有一些常见技巧可以减小 Excel 文档的大小,同时保持 Excel 格式。这取决于文件的具体
我有多个目录,每个目录包含任意数量的 .xls 文件。我想获取任何给定目录中的文件并将它们合并到一个 .xls 文件中,使用文件名作为选项卡名称。例如,如果有文件 NAME.xls、AGE.xls、L
使用下面的 Python 测试代码,我试图将 Excel (*.xls) 文件中唯一的工作表复制到一个包含一个工作表的新 Excel 文件中。 输入电子表格如下所示: from copy import
我有一个 xls 文件,其中包含 15 张数据,我想将所有数据复制到另一个 xls 文件中。我有很多这样的文件,所以我想使用宏 vba 编码对其进行自定义。我想在第一张纸上设计按钮,它会运行宏代码并将
我正在尝试从 xls 中读取数据,该数据运行良好 java.io.File f1=new java.io.File("E:/SELENIUM DATA/First_P1/DATA_SHEET.x
我有一个文件 .XLS 扩展名,但保存为 XMl 电子表格 2003 ,想要读取该文件并使用 java 代码将其转换为 .XLS 扩展名,我的代码如下 - 公共(public)类 ExcelImpor
我已经创建了 Servlet,它下载 POI XLS 文件,在第一个 get/post 请求时,新文件是使用sheet0下载的。当我执行第二个请求时,正在下载两张新文件,sheet0 是上一个请求,s
我有大量格式为:YYYYDDMM_rest_of_filename.xls 的 excel 文件 我如何使用 ruby 在 YYYYMMDD_rest_of_filename.xls 的可能数量较
我将 xlsx 文件保存在 firefox 中,浏览器将其识别为 97-2003 工作簿 (.xls) 当我打开 xls 文件时,它会生成弹出窗口 我也在不同的机器上尝试过这个,它在 firefox
伙计们。我在 DB 有日期作为字符串“d/m/Y”。 当我将此日期输入 Excel 时,它会显示正常日期,例如 2000 年 3 月 10 日,但是当我单击单元格时,它会显示值 '03/10/2000
我正在研究 INFORMIX 4GL 程序。该程序生成输出文本文件。这是输出的示例: Lot No|Purchaser name|Billing|Payment|Deposit|Balance|
代码如下: <%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%> <%
我的应用程序正在从 MYSQL 动态获取数据并显示。问题是我什至必须选择“导出到 Xls”文件。这些文件应该是 A4 大小,所以我应该自定义 Xls 文件中内容的字体大小以适应 A4 大小。如果可能的
我必须运行一些 SQL 查询并将结果放入电子表格中。由于我处于 Spring/Java 环境中,因此我打算使用 JDBC 运行查询、迭代 ResultSet,并使用 Jakarta POI 创建一个简
我有一个包含多张工作表的 Excel 电子表格。格式如下: Date A B C D E F
我正在使用 jquery 数据表插件来显示数据。我添加了文件另存为 excel、csv 和 pdf 的选项。 虽然它允许我将表格内容保存为文件。但在 excel 和 csv 情况下,它都会将文件保存为
我正在尝试弄清楚如何读取 XLS 文档的内容并且我能够很好地获取字节,但我不知道从这里到哪里去。尝试 [[NSString alloc] initWithBytes:data.bytes length
在我的应用程序中,我需要以预定义格式导出到 xls 文件。 所以我刚刚集成了 php_excel2007。我正在使用一个具有预定义格式的模板。 问题 这里的单元格数据可能会动态变化。如果数据远大于单元
我是一名优秀的程序员,十分优秀!