BIFF5 - Excel - 工作簿流问题(文件损坏)
我使用 FireFox 扩展中的 javascript 成功写入 Excel 文件。我可以获得我想要的格式和内容,但是我遇到了障碍。
为了添加格式,我必须对工作簿全局流进行 EOF,并对工作表流进行 BOF。当我这样做时,Excel 说文件已损坏。
我目前正在按以下顺序将这些记录写入文件:
BOF Record (0x05 [Workbook])
WINDOW1 Record
1904 Record
FONT Record (x7)
XF Record (x17)
BOUNDSHEET Record
EOF Record
BOF Record (0x10 [Worksheet])
LABEL Record
EOF Record
但是,当我在 Excel 中打开文件时,它说它已损坏,当我在 OpenOffice 中打开它时,它会加载文档,当我使用 ExcelFile Workbook 查看器打开它时查看记录,一切看起来都很好。
这是我在文件开头编写的代码:
excelData[excelData.length] = pack("vvvvvv", 0x809, 0x08, 0x0500, 0x05, 0x096C, 0x07C9); // BOF Workbook
excelData[excelData.length] = pack("vvvvvvvvvvv", 0x003D, 0x0012, 0x0000, 0x0000, 0x25BC, 0x1572, 0x0038, 0x0000, 0x0000, 0x0001, 0x0258); // WINDOW1
excelData[excelData.length] = pack("vvv", 0x0022, 0x0002, 0x0000); // 1904
excelData[excelData.length] = pack("vv", 0x0031, 0x0F+7);
excelData[excelData.length] = pack("vvvvvCCCCC", 0x00C8, 0x0001, 0x0000, 0x0190, 0x0000, 0x0200, 0x00, 0x01, 0x00, 7); // calibri 10 normal - index 0
excelData[excelData.length] = "Calibri";
excelData[excelData.length] = pack("vv", 0x0031, 0x0F+7);
excelData[excelData.length] = pack("vvvvvCCCCC", 0x00C8, 0x0001, 0x0000, 0x02BC, 0x0000, 0x0200, 0x00, 0x01, 0x00, 7); // calibri 10 bold - index 1
excelData[excelData.length] = "Calibri";
excelData[excelData.length] = pack("vv", 0x0031, 0x0F+7);
excelData[excelData.length] = pack("vvvvvCCCCC", 0x00C8, 0x0001, 0x0000, 0x02BC, 0x0000, 0x0200, 0x00, 0x01, 0x00, 7); // calibri 10 bold - index 2
excelData[excelData.length] = "Calibri";
excelData[excelData.length] = pack("vv", 0x0031, 0x0F+7);
excelData[excelData.length] = pack("vvvvvCCCCC", 0x00C8, 0x0001, 0x0000, 0x02BC, 0x0000, 0x0200, 0x00, 0x01, 0x00, 7); // calibri 10 bold - index 3
excelData[excelData.length] = "Calibri";
excelData[excelData.length] = pack("vv", 0x0031, 0x0F+7);
excelData[excelData.length] = pack("vvvvvCCCCC", 0x00C8, 0x0001, 0x0000, 0x02BC, 0x0000, 0x0200, 0x00, 0x01, 0x00, 7); // calibri 10 bold - index 5
excelData[excelData.length] = "Calibri";
excelData[excelData.length] = pack("vv", 0x0031, 0x0F+7);
excelData[excelData.length] = pack("vvvvvCCCCC", 0x00C8, 0x0001, 0x0000, 0x02BC, 0x0000, 0x0200, 0x00, 0x01, 0x00, 7); // calibri 10 bold - index 6
excelData[excelData.length] = "Calibri";
excelData[excelData.length] = pack("vv", 0x0031, 0x0F+7);
excelData[excelData.length] = pack("vvvvvCCCCC", 0x00C8, 0x0001, 0x0000, 0x02BC, 0x0000, 0x0200, 0x00, 0x01, 0x00, 7); // calibri 10 bold - index 7
excelData[excelData.length] = "Calibri";
excelData[excelData.length] = pack("vvvvvvvvvv", 0x00E0, 0x0010, 0x0000, 0x0000, 0xFFF5, 0x0020, 0x20C0, 0x0000, 0x0000, 0x0000); //XF Messed up?
excelData[excelData.length] = pack("vvvvvvvvvv", 0x00E0, 0x0010, 0x0006, 0x0000, 0xFFF5, 0x0020, 0x20C0, 0x0000, 0x0000, 0x0000); //XF Messed up?
excelData[excelData.length] = pack("vvvvvvvvvv", 0x00E0, 0x0010, 0x0006, 0x0000, 0xFFF5, 0x0020, 0x20C0, 0x0000, 0x0000, 0x0000); //XF Messed up?
excelData[excelData.length] = pack("vvvvvvvvvv", 0x00E0, 0x0010, 0x0006, 0x0000, 0xFFF5, 0x0020, 0x20C0, 0x0000, 0x0000, 0x0000); //XF Messed up?
excelData[excelData.length] = pack("vvvvvvvvvv", 0x00E0, 0x0010, 0x0006, 0x0000, 0xFFF5, 0x0020, 0x20C0, 0x0000, 0x0000, 0x0000); //XF Messed up?
excelData[excelData.length] = pack("vvvvvvvvvv", 0x00E0, 0x0010, 0x0006, 0x0000, 0xFFF5, 0x0020, 0x20C0, 0x0000, 0x0000, 0x0000); //XF Messed up?
excelData[excelData.length] = pack("vvvvvvvvvv", 0x00E0, 0x0010, 0x0006, 0x0000, 0xFFF5, 0x0020, 0x20C0, 0x0000, 0x0000, 0x0000); //XF Messed up?
excelData[excelData.length] = pack("vvvvvvvvvv", 0x00E0, 0x0010, 0x0006, 0x0000, 0xFFF5, 0x0020, 0x20C0, 0x0000, 0x0000, 0x0000); //XF Messed up?
excelData[excelData.length] = pack("vvvvvvvvvv", 0x00E0, 0x0010, 0x0006, 0x0000, 0xFFF5, 0x0020, 0x20C0, 0x0000, 0x0000, 0x0000); //XF Messed up?
excelData[excelData.length] = pack("vvvvvvvvvv", 0x00E0, 0x0010, 0x0006, 0x0000, 0xFFF5, 0x0020, 0x20C0, 0x0000, 0x0000, 0x0000); //XF Messed up?
excelData[excelData.length] = pack("vvvvvvvvvv", 0x00E0, 0x0010, 0x0006, 0x0000, 0xFFF5, 0x0020, 0x20C0, 0x0000, 0x0000, 0x0000); //XF Messed up?
excelData[excelData.length] = pack("vvvvvvvvvv", 0x00E0, 0x0010, 0x0006, 0x0000, 0xFFF5, 0x0020, 0x20C0, 0x0000, 0x0000, 0x0000); //XF Messed up?
excelData[excelData.length] = pack("vvvvvvvvvv", 0x00E0, 0x0010, 0x0006, 0x0000, 0xFFF5, 0x0020, 0x20C0, 0x0000, 0x0000, 0x0000); //XF Messed up?
excelData[excelData.length] = pack("vvvvvvvvvv", 0x00E0, 0x0010, 0x0006, 0x0000, 0xFFF5, 0x0020, 0x20C0, 0x0000, 0x0000, 0x0000); //XF Messed up?
excelData[excelData.length] = pack("vvvvvvvvvv", 0x00E0, 0x0010, 0x0006, 0x0000, 0xFFF5, 0x0020, 0x20C0, 0x0000, 0x0000, 0x0000); //XF Messed up?
excelData[excelData.length] = pack("vvvvvvvvvv", 0x00E0, 0x0010, 0x0000, 0x0000, 0x0001, 0x0020, 0x20C0, 0x0000, 0x0000, 0x0000); //XF Messed up?
excelData[excelData.length] = pack("vvvvvvvvvv", 0x00E0, 0x0010, 0x0006, 0x0000, 0x0001, 0x0020, 0x20C0, 0x0000, 0x0000, 0x0000); //XF Messed up? // User Defined
var L = 0;
for (var i=0; i<excelData.length; i++) {
L = Number(L)+Number(excelData[i].length);
}
L = L+27;
var data = pack("VvC", Number(L), 0x0000, 12); // BOUNDSHEET
data = data+"data sheet 1";
excelData[excelData.length] = pack("vv", 0x0085, data.length);
excelData[excelData.length] = data;
excelData[excelData.length] = pack("vv", 0x0A, 0x00); // EOF
excelData[excelData.length] = pack("vvvvvv", 0x809, 0x08, 0x0500, 0x10, 0x096C, 0x07C9); // BOF Worksheet
我确实怀疑问题出在 BOUNDSHEET 记录中。然而我也没有运气解决这个问题。任何帮助将不胜感激!
-亚历克斯
I am successfully writing to an Excel file, using javascript from my FireFox extension. I can get the formatting, and contents that I want, however I have run into a roadblock.
In order to add the formatting, I have to EOF the Workbook Globals Stream, and BOF the worksheet stream. When I do that Excel says the file is corrupt.
I am currently writing to the file these records, in this order:
BOF Record (0x05 [Workbook])
WINDOW1 Record
1904 Record
FONT Record (x7)
XF Record (x17)
BOUNDSHEET Record
EOF Record
BOF Record (0x10 [Worksheet])
LABEL Record
EOF Record
However when I open the file in Excel it says it is corrupt, when I open it in OpenOffice it loads the document just fine, when I open it with ExcelFile Workbook viewer to see the records, all looks fine.
Here is the code that I am writing at the beginning of the file:
excelData[excelData.length] = pack("vvvvvv", 0x809, 0x08, 0x0500, 0x05, 0x096C, 0x07C9); // BOF Workbook
excelData[excelData.length] = pack("vvvvvvvvvvv", 0x003D, 0x0012, 0x0000, 0x0000, 0x25BC, 0x1572, 0x0038, 0x0000, 0x0000, 0x0001, 0x0258); // WINDOW1
excelData[excelData.length] = pack("vvv", 0x0022, 0x0002, 0x0000); // 1904
excelData[excelData.length] = pack("vv", 0x0031, 0x0F+7);
excelData[excelData.length] = pack("vvvvvCCCCC", 0x00C8, 0x0001, 0x0000, 0x0190, 0x0000, 0x0200, 0x00, 0x01, 0x00, 7); // calibri 10 normal - index 0
excelData[excelData.length] = "Calibri";
excelData[excelData.length] = pack("vv", 0x0031, 0x0F+7);
excelData[excelData.length] = pack("vvvvvCCCCC", 0x00C8, 0x0001, 0x0000, 0x02BC, 0x0000, 0x0200, 0x00, 0x01, 0x00, 7); // calibri 10 bold - index 1
excelData[excelData.length] = "Calibri";
excelData[excelData.length] = pack("vv", 0x0031, 0x0F+7);
excelData[excelData.length] = pack("vvvvvCCCCC", 0x00C8, 0x0001, 0x0000, 0x02BC, 0x0000, 0x0200, 0x00, 0x01, 0x00, 7); // calibri 10 bold - index 2
excelData[excelData.length] = "Calibri";
excelData[excelData.length] = pack("vv", 0x0031, 0x0F+7);
excelData[excelData.length] = pack("vvvvvCCCCC", 0x00C8, 0x0001, 0x0000, 0x02BC, 0x0000, 0x0200, 0x00, 0x01, 0x00, 7); // calibri 10 bold - index 3
excelData[excelData.length] = "Calibri";
excelData[excelData.length] = pack("vv", 0x0031, 0x0F+7);
excelData[excelData.length] = pack("vvvvvCCCCC", 0x00C8, 0x0001, 0x0000, 0x02BC, 0x0000, 0x0200, 0x00, 0x01, 0x00, 7); // calibri 10 bold - index 5
excelData[excelData.length] = "Calibri";
excelData[excelData.length] = pack("vv", 0x0031, 0x0F+7);
excelData[excelData.length] = pack("vvvvvCCCCC", 0x00C8, 0x0001, 0x0000, 0x02BC, 0x0000, 0x0200, 0x00, 0x01, 0x00, 7); // calibri 10 bold - index 6
excelData[excelData.length] = "Calibri";
excelData[excelData.length] = pack("vv", 0x0031, 0x0F+7);
excelData[excelData.length] = pack("vvvvvCCCCC", 0x00C8, 0x0001, 0x0000, 0x02BC, 0x0000, 0x0200, 0x00, 0x01, 0x00, 7); // calibri 10 bold - index 7
excelData[excelData.length] = "Calibri";
excelData[excelData.length] = pack("vvvvvvvvvv", 0x00E0, 0x0010, 0x0000, 0x0000, 0xFFF5, 0x0020, 0x20C0, 0x0000, 0x0000, 0x0000); //XF Messed up?
excelData[excelData.length] = pack("vvvvvvvvvv", 0x00E0, 0x0010, 0x0006, 0x0000, 0xFFF5, 0x0020, 0x20C0, 0x0000, 0x0000, 0x0000); //XF Messed up?
excelData[excelData.length] = pack("vvvvvvvvvv", 0x00E0, 0x0010, 0x0006, 0x0000, 0xFFF5, 0x0020, 0x20C0, 0x0000, 0x0000, 0x0000); //XF Messed up?
excelData[excelData.length] = pack("vvvvvvvvvv", 0x00E0, 0x0010, 0x0006, 0x0000, 0xFFF5, 0x0020, 0x20C0, 0x0000, 0x0000, 0x0000); //XF Messed up?
excelData[excelData.length] = pack("vvvvvvvvvv", 0x00E0, 0x0010, 0x0006, 0x0000, 0xFFF5, 0x0020, 0x20C0, 0x0000, 0x0000, 0x0000); //XF Messed up?
excelData[excelData.length] = pack("vvvvvvvvvv", 0x00E0, 0x0010, 0x0006, 0x0000, 0xFFF5, 0x0020, 0x20C0, 0x0000, 0x0000, 0x0000); //XF Messed up?
excelData[excelData.length] = pack("vvvvvvvvvv", 0x00E0, 0x0010, 0x0006, 0x0000, 0xFFF5, 0x0020, 0x20C0, 0x0000, 0x0000, 0x0000); //XF Messed up?
excelData[excelData.length] = pack("vvvvvvvvvv", 0x00E0, 0x0010, 0x0006, 0x0000, 0xFFF5, 0x0020, 0x20C0, 0x0000, 0x0000, 0x0000); //XF Messed up?
excelData[excelData.length] = pack("vvvvvvvvvv", 0x00E0, 0x0010, 0x0006, 0x0000, 0xFFF5, 0x0020, 0x20C0, 0x0000, 0x0000, 0x0000); //XF Messed up?
excelData[excelData.length] = pack("vvvvvvvvvv", 0x00E0, 0x0010, 0x0006, 0x0000, 0xFFF5, 0x0020, 0x20C0, 0x0000, 0x0000, 0x0000); //XF Messed up?
excelData[excelData.length] = pack("vvvvvvvvvv", 0x00E0, 0x0010, 0x0006, 0x0000, 0xFFF5, 0x0020, 0x20C0, 0x0000, 0x0000, 0x0000); //XF Messed up?
excelData[excelData.length] = pack("vvvvvvvvvv", 0x00E0, 0x0010, 0x0006, 0x0000, 0xFFF5, 0x0020, 0x20C0, 0x0000, 0x0000, 0x0000); //XF Messed up?
excelData[excelData.length] = pack("vvvvvvvvvv", 0x00E0, 0x0010, 0x0006, 0x0000, 0xFFF5, 0x0020, 0x20C0, 0x0000, 0x0000, 0x0000); //XF Messed up?
excelData[excelData.length] = pack("vvvvvvvvvv", 0x00E0, 0x0010, 0x0006, 0x0000, 0xFFF5, 0x0020, 0x20C0, 0x0000, 0x0000, 0x0000); //XF Messed up?
excelData[excelData.length] = pack("vvvvvvvvvv", 0x00E0, 0x0010, 0x0006, 0x0000, 0xFFF5, 0x0020, 0x20C0, 0x0000, 0x0000, 0x0000); //XF Messed up?
excelData[excelData.length] = pack("vvvvvvvvvv", 0x00E0, 0x0010, 0x0000, 0x0000, 0x0001, 0x0020, 0x20C0, 0x0000, 0x0000, 0x0000); //XF Messed up?
excelData[excelData.length] = pack("vvvvvvvvvv", 0x00E0, 0x0010, 0x0006, 0x0000, 0x0001, 0x0020, 0x20C0, 0x0000, 0x0000, 0x0000); //XF Messed up? // User Defined
var L = 0;
for (var i=0; i<excelData.length; i++) {
L = Number(L)+Number(excelData[i].length);
}
L = L+27;
var data = pack("VvC", Number(L), 0x0000, 12); // BOUNDSHEET
data = data+"data sheet 1";
excelData[excelData.length] = pack("vv", 0x0085, data.length);
excelData[excelData.length] = data;
excelData[excelData.length] = pack("vv", 0x0A, 0x00); // EOF
excelData[excelData.length] = pack("vvvvvv", 0x809, 0x08, 0x0500, 0x10, 0x096C, 0x07C9); // BOF Worksheet
I truly suspect the problem lies in the BOUNDSHEET record. However I am not having any luck figuring this one out either. Any help would be appreciated!
-Alex
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我是上面提到的 Spreadsheet::WriteExcel Perl 模块的作者。
如果您向我发送其中一个损坏的文件,我会为您调试并通知您问题是什么。
I am the author of the Spreadsheet::WriteExcel Perl module mentioned above.
If you send me one of the corrupt files I'll debug it for you and let you know what the issue is.
我建议使用 John McNamara 的 Perl Excel Writer 复制 Excel 内容。
然后比较他的 sw 和你的 sw 的二进制输出。您也可以尝试联系约翰寻求帮助。
我相信 perl 库被认为是开源 Excel 文件创建的“标准”。
许多其他语言的 Excel 编写器只是约翰作品的移植。
另外,您能详细介绍一下用于写入 Excel 文件的 FF 扩展吗?听起来很棒。
I suggest duplicating your Excel content using the Perl Excel Writer by John McNamara.
Then compare the binary output of his sw and yours. You could also try to contact John for help.
I believe that the perl lib is considered the "standard" for open source Excel file creation.
Many Excel writers in other languages are simply ports of John's work.
Also, can you say more about your FF extension for writing Excel files? It sounds great.