[英]Parsing C# generated OpenXML xlsx with js-xlsx
I generate .xlsx documents in my solution and send them to the user, when parsed with js-xlsx they have zero cells, this can be fixed by opening the generated .xlsx with Excel and saving them. 我在解决方案中生成.xlsx文档,并将其发送给用户,用js-xlsx解析时,它们具有零个单元格,可以通过使用Excel打开生成的.xlsx并保存来解决。
I would like to be able to parse my generated .xlsx documents directly with js-xlsx. 我希望能够直接使用js-xlsx解析生成的.xlsx文档。
Code for saving to .xlsx: 保存为.xlsx的代码:
var ms = new MemoryStream();
workbook.SaveAs(ms);
ms.Seek(0, SeekOrigin.Begin);
return ms;var ms = new MemoryStream();
Code for opening .xlsx with js-xlsx: 使用js-xlsx打开.xlsx的代码:
function readBook(file) {
var reader = new FileReader();
reader.onload = function (e) {
var data = e.target.result;
var workbook = XLSX.read(data, { type: 'binary' });
console.log(workbook);
};
reader.readAsBinaryString(file);
}
I found that c# OpenXML adds 'x:' in front of all the string xml tags, this can be fixed in js-xlsx by replacing the 'x:' tags. 我发现c#OpenXML在所有字符串xml标记之前添加了“ x:”,可以通过替换“ x:”标记在js-xlsx中进行修复。
simply put: 简单的说:
data = data.replace(new RegExp('x:', 'g'), '');
into function parse_ws_xml(data, opts, rels) and function parse_sst_xml(data, opts) 分为函数parse_ws_xml(data,opts,rels)和函数parse_sst_xml(data,opts)
Todo: make a fix that allows you to have strings containing 'x:' in your .xlsx file. 待办事项:进行修复,使您可以在.xlsx文件中包含包含“ x:”的字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.