- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
所以我在 js 和 xul 中有我的函数,它在 ods 或 xlsx 中创建导出文件。在 ods 中导出工作正常,但问题是当我尝试以 excel 文件格式导出时。计划是创建将由 treeToXLSX.xsl 生成的 xml 文件 content.xml。生成了 Content.xml,当我提取 export.xlsx 时,它就在那里,但 xlsx 是空的。这些是我的文件
树.JS
if(exportType == 'excel'){
xslFile = "treeToXLSX.xsl";
tempExportFile = "export.xlsx.tmp";
exportTemplate = "template.xlsx";
exportedFileName = "export.xlsx";
}else{
xslFile = "treeToODS.xsl";
tempExportFile = "export.ods.tmp";
exportTemplate = "template.ods";
exportedFileName = "export.ods";
}
var newdoc = this.prep(xslFile);
// save newdoc as /tmp/content.xml
var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
.createInstance(Components.interfaces.nsIFileOutputStream);
var file = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("TmpD", Components.interfaces.nsIFile);
file.append("content.xml");
var file2 = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("TmpD", Components.interfaces.nsIFile);
file2.append(tempExportFile);
file2.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0666);
file2.remove(false);
var serializer = new XMLSerializer();
// use 0x02 | 0x10 to open file for appending.
foStream.init(file, 0x02 | 0x08 | 0x20, -1, 0); // write,
// create,
// truncate
// In a c file operation, we have no need to set file mode with or
// operation, directly using "r" or "w" usually.
serializer.serializeToStream(newdoc, foStream, "UTF-8");
foStream.close();
var template = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("AChrom", Components.interfaces.nsIFile);
template.append("<path>");
template.append("<to_file>");
template.append(exportTemplate);
// copy export.ods template file into temp, BLOCKING OPERATION
template.copyTo(file2.parent, file2.leafName);
var zipWriter = Components.Constructor("@mozilla.org/zipwriter;1", "nsIZipWriter");
var zipW = new zipWriter();
zipW.open(file2, 0x04);
zipW.addEntryFile(file.leafName, Components.interfaces.nsIZipWriter.COMPRESSION_DEFAULT, file, false);
zipW.close();
var homedir = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("Home", Components.interfaces.nsIFile);
// open a save as dialog box
var fp = Components.classes["@mozilla.org/filepicker;1"]
.createInstance(Components.interfaces.nsIFilePicker);
fp.init(window, "Export as", Components.interfaces.nsIFilePicker.modeSave);
fp.appendFilters(Components.interfaces.nsIFilePicker.filterAll | Components.interfaces.nsIFilePicker.filterText);
fp.displayDirectory = homedir;
fp.defaultString = exportedFileName;
var rv = fp.show();
if (rv == Components.interfaces.nsIFilePicker.returnOK || rv == Components.interfaces.nsIFilePicker.returnReplace) {
file2.moveTo(fp.file.parent, fp.file.leafName);
} else {
file2.remove(false);
}
TREETOXLSX.XSL
<?xml version='1.0'?>
<?mso-application progid="Excel.Sheet"?>
<xsl:stylesheet
version="1.0"
xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="urn:my-scripts"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
<xsl:output method="xml" encoding="utf-8" indent="yes" />
<xsl:param name="title" />
<xsl:param name="skipfields" />
<xsl:param name="decimals" />
<xsl:param name="numerics" />
<xsl:template match="*">
<Workbook>
<Worksheet ss:Name="Test">
<Table x:FullColumns="1" x:FullRows="1">
<Row ss:Height="12.1032">
<xsl:for-each select="child::*[1]/@*">
<xsl:if test="not(contains($skipfields, concat('|', name(), '|')))">
<Cell>
<Data ss:Type="String">
<xsl:value-of select="translate(name(), '_', '')"/>
</Data>
</Cell>
</xsl:if>
</xsl:for-each>
</Row>
<xsl:for-each select="./*">
<Row>
<xsl:for-each select="@*">
<xsl:if test="not(contains($skipfields, concat('|', name(), '|')))">
<xsl:choose>
<xsl:when test="contains($decimals, concat('|', name(), '|'))">
<Cell>
<Data ss:Type="Number">
<xsl:value-of select="." />
</Data>
</Cell>
</xsl:when>
<xsl:when test="contains($numerics, concat('|', name(), '|'))">
<Cell>
<Data ss:Type="Number">
<xsl:value-of select="." />
</Data>
</Cell>
</xsl:when>
<xsl:otherwise>
<Cell>
<Data ss:Type="String">
<xsl:value-of select="." />
</Data>
</Cell>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:for-each>
</Row>
</xsl:for-each>
</Table>
</Worksheet>
内容.XML
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet">
<Worksheet xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" ss:Name="Test">
<Table xmlns:x="urn:schemas-microsoft-com:office:excel" x:FullColumns="1" x:FullRows="1">
<Row ss:Height="12.1032">
<Cell>
<Data ss:Type="String">ID</Data>
</Cell>
<Cell>
<Data ss:Type="String">Name</Data>
</Cell>
<Cell>
<Data ss:Type="String">Type</Data>
</Cell>
<Cell>
<Data ss:Type="String">Group</Data>
</Cell>
<Cell>
<Data ss:Type="String">Totaltickets</Data>
</Cell>
<Cell>
<Data ss:Type="String">Wontickets</Data>
</Cell>
<Cell>
<Data ss:Type="String">Moneyin</Data>
</Cell>
<Cell>
<Data ss:Type="String">Moneyout</Data>
</Cell>
<Cell>
<Data ss:Type="String">Percentage</Data>
</Cell>
<Cell>
<Data ss:Type="String">Average</Data>
</Cell>
<Cell>
<Data ss:Type="String">Moneyleft</Data>
</Cell>
</Row>
<Row>
<Cell>
<Data ss:Type="Number">999</Data>
</Cell>
<Cell>
<Data ss:Type="String">test</Data>
</Cell>
<Cell>
<Data ss:Type="String"/>
</Cell>
<Cell>
<Data ss:Type="String">a</Data>
</Cell>
<Cell>
<Data ss:Type="Number">0</Data>
</Cell>
<Cell>
<Data ss:Type="Number">0</Data>
</Cell>
<Cell>
<Data ss:Type="Number">0,00</Data>
</Cell>
<Cell>
<Data ss:Type="Number">0,00</Data>
</Cell>
<Cell>
<Data ss:Type="Number">0</Data>
</Cell>
<Cell>
<Data ss:Type="Number">0,00</Data>
</Cell>
<Cell>
<Data ss:Type="Number">0,00</Data>
</Cell>
</Row>
</Table>
奇怪的是导出到 ods 文件的效果很好,所以我真的被卡住了。我的目录中有所有需要的文件,treeToXLSX.xsl
生成 content.xml
和 template.xlsx
。
最佳答案
您的 TreeToXLSX.xsl
中缺少结束标记和 content.xml
文件,但这可能是您创建问题时的复制粘贴错误。
此外,在您的 XSL 文件中,尝试更改 <xsl:template match="*">
至 <xsl:template match="/Workbook">
匹配 XML 输入的根元素。
最后,您在这里创建的文件看起来像 Excel XML Spreadsheet格式,而不是 Office Open XML 格式。 XML 电子表格文件的文件扩展名应为“.xml”或“.xls”,而不是“.xslx”。
关于javascript - 导出到 xul 中的 excel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13029017/
是否可以调整此代码以导出foreach循环外的所有行: 这工作正常(内部循环): $vms = Get-VM | Where { $_.State –eq ‘Running’ } | Select-
我试图将我的 bundle.js 引入我的 Node 服务器,但显然 webpack 包在顶部的所有包代码之前缺少一个 module.exports =。 我可以手动将 module.exports
我有一个 android 项目,其中包含一个库项目。在这个库项目中,我包含了许多可绘制对象和动画。 问题是,当我将主项目导出为 .apk 时,它包括所有可绘制对象和动画,甚至是主项目中未使用的对象。
我的一个 mysql 用户以这种方式耗尽了他的生产数据库: 他将所有数据导出到转储文件,然后删除所有内容,然后将数据导入回数据库。他从 Innodb 大表空间中保存了一些 Gig(我不知道他为什么这样
我正在 pimcore 中创建一个新站点。有没有办法导出/导入 pimcore 站点的完整数据,以便我可以导出 xml/csv 格式的 pimcore 数据进行必要的更改,然后将其导入回来? 最佳答案
我有以下静态函数: static inline HandVal StdDeck_StdRules_EVAL_N( StdDeck_CardMask cards, int n
因为我更新了 angular cli 和 nestjs 版本,所以我收到了数百条警告,提示我无法找到我的自定义类型定义和接口(interface)。但是我的nestjs api仍然可以正常工作。 我正
Eclipse 的搜索结果 View 以其树状结构非常方便。有没有办法将这些结果导出为可读的文本格式或将它们保存到文件中以备后用? 我试过使用复制和粘贴,但生成的文本格式远不可读。 最佳答案 不,我认
我想在用户在 Chrome 中打开页面时使用 WebP否则它应该是 png。 我找到了这段代码: var isChrome = !!window.chrome && !!window.chrome.w
您好,我正在尝试根据“上次登录”导出 AD 用户列表 我已经使用基本 powershell 编写了脚本,但是如果有人可以使用“AzureAD 到 Powershell” 命令找到解决方案,我会很感兴趣
有没有办法启用 Stockchart 的导出?我知道这对于普通图表是可行的,但对于股票图表,当尝试启用导出模式时,我得到了未定义, 我尝试过:chart.export.enabled=true;和ch
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,因为
我正在尝试学习如何使用命令行将数据导入/导出到 Oracle。根据我的发现,看起来我应该使用 sqlldr.exe 文件来导入和导出,但我不确定除了 userid 之外还需要什么参数。谁能给我解释一下
您好,我正在尝试根据“上次登录”导出 AD 用户列表 我已经使用基本 powershell 编写了脚本,但是如果有人可以使用“AzureAD 到 Powershell” 命令找到解决方案,我会很感兴趣
我想生成一个 PDF,它将以表格格式显示查询集的输出,例如: query = ModelA.objects.filter(p_id=100) class ModelA(models.Model):
我有一个数据库代理,可以从 IBM Notes 数据生成 Word 文档。我正在使用 Java2Word API 来实现此目的,但不幸的是,该 API 几乎没有文档,而且我找不到任何有关表格格式(大小
我尝试将 Java 程序从 Eclipse 导出到 .jar 文件,但遇到了问题。它运行良好,但由于某种原因它没有找到它应该从中获取数据的文本文件。如果有人能帮忙解决这个问题,我将非常感激。 最佳答案
我正在尝试学习如何使用命令行将数据导入/导出到 Oracle。根据我的发现,看起来我应该使用 sqlldr.exe 文件来导入和导出,但我不确定除了 userid 之外还需要什么参数。谁能给我解释一下
使用LLVM / Clang编译到WebAssembly的默认代码生成将导出内存,并完全忽略表。 使用clang(--target=wasm32-unknown-unknown-wasm)定位Web组
我正在尝试在 HSQL 数据库中重新创建一个 oracle 数据库。 这是为了在本地开发人员系统上进行更好的单元测试。 我需要知道的是,是否有任何我可以在 oracle 服务器/客户端中使用的工具/命
我是一名优秀的程序员,十分优秀!