BIFF5 - Excel - 工作簿流问题(损坏的文件)

时间:2010-09-15 01:24:02

标签: javascript excel firefox-addon export-to-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记录。但是,我也没有任何运气来解决这个问题。任何帮助将不胜感激!

-Alex

2 个答案:

答案 0 :(得分:2)

我是上面提到的Spreadsheet :: WriteExcel Perl模块的作者。

如果您send me其中一个损坏的文件,我会为您调试它,并让您知道问题所在。

答案 1 :(得分:0)

我建议使用John McNamara的Perl Excel Writer复制您的Excel内容。 然后比较他的sw和你的二进制输出。您也可以尝试联系John寻求帮助。

我相信perl lib被认为是开源Excel文件创建的“标准”。 许多其他语言的Excel编写者只是John工作的端口。

此外,您能否详细说明用于编写Excel文件的FF扩展程序?听起来不错。