每次在 Excel 2007 中打开 Excel 2003 二进制格式时,MD5 哈希值都会发生变化(6 字节随机变化)

发布于 2024-12-21 12:27:18 字数 2011 浏览 0 评论 0原文

我遇到一个生产问题,即 Excel 2003 二进制文件的服务器版本(由 Syncfusion .NET 库生成)与本地文件之间的两个 MD5 哈希值不匹配。 当我上传仅通过 Windows 资源管理器双击打开的本地 Excel 文件时,服务器发现 MD5 哈希值不相同,并且不允许文件上传。 仅使用 Excel 2007 打开 Excel 2003 文件(有些报告与 Excel 2003 相同) 会导致文件开头的几个字节发生变化(我猜是在文件开头的 Excel 元数据中)

要确认我使用了 CMD 控制台的文件比较程序:

fc.exe /b ExcelFile2003binary_Opened.xls ExcelFile2003binary.xls

这是从偏移量 0000046C 开始的两个文件之间的差异:

0000046C: D0 E0
0000046D: 61 51
0000046E: 5D 5E
0000046F: B6 FE
00000470: 76 0E
00000471: BB BC

中间列显示打开文件的 6 个字节: D0615DB676BB,每次打开文件时这些都会改变。由于未打开 ExcelFile2003binary.xls,最后一列没有更改。

基于 [MS -OSHARED]Office 通用数据类型和对象结构规范文档 受影响的字节位于偏移量 0000046C(2 个字节)和 0000046E(4 个字节)处,每次打开文件时都会发生变化,这显然会改变 MD5 哈希值。

LinkElement-3 示例 这是 linkElement 的示例,说明了指向包含链接的文档外部的 Web 资源的超链接。

Offset      Size     Structure                     Value
------------------------------------------------------------
0000046A    006C     VtHyperlink - linkElement-3
0000046A    0008     TypedPropertyValue - dwHash   
0000046A    0002     WORD - wType                  0x0003
0000046C    0002     WORD - padding                0x0000
0000046E    0004     DWORD - value                 0x00320064

如果我理解得很好,“填充”和“价值”总是会改变。 我从另一个帖子中听说 Excel 2007 根本不会更改 Excel 2007 二进制格式。

请帮忙。这是我需要解决的一个紧迫问题。我可以在 Excel 文档上设置一些内容(使用 Syncfusion 或 Excel API)来防止这种行为吗?

谢谢, 拉德

编辑:

Dim xlsUri As Uri
xlsUri = New Uri("c:\temp\ExcelFile2003binary.xls")

If (IO.File.Exists(xlsUri.LocalPath)) Then
  Dim xlsNode As TreeNode = wip.getWipNode(tvwMain.Nodes, "Excel")
  If (xlsNode Is Nothing) Then
    'Opening excel file link Uri embeded in Tag won't change the file????
    'Users can choose any way to open it (Custom app or Windows Explorer shell)
    folderNode.Nodes.Add("excel", "Excel", 9, 9).Tag = xlsUri.LocalPath
  End If
End If

I have a production problem where two MD5 hashes don't match between a server version of an Excel 2003 binary file (generated by Syncfusion .NET library) and a local one.
When I upload a local Excel file that was only opened by double clicking via Windows Explorer the server finds that MD5 hashes are not the same and won't let file upload.
Just opening Excel 2003 file with Excel 2007 (and some reported the same with Excel 2003)
will cause a few bytes to change at the beginning of the file (I guess in Excel metadata at the beginning of the file)

To confirm that I used the file compare program from CMD console:

fc.exe /b ExcelFile2003binary_Opened.xls ExcelFile2003binary.xls

here is the difference between two files starting at offset 0000046C:

0000046C: D0 E0
0000046D: 61 51
0000046E: 5D 5E
0000046F: B6 FE
00000470: 76 0E
00000471: BB BC

Middle column shows 6 bytes of the opened file: D0615DB676BB and these will change each time the file is opened. The last column doesn't change since ExcelFile2003binary.xls is not opened.

Based on [MS -OSHARED]Office Common Data Types and Objects Structure Specification document
the affected bytes are at offset 0000046C (2 bytes) and at 0000046E (4 bytes) that change upon every opening of the file which obviously changes MD5 hash.

LinkElement-3 Example
This is an example of a linkElement that illustrates a hyperlink to a web resource outside of the document that contains the link.

Offset      Size     Structure                     Value
------------------------------------------------------------
0000046A    006C     VtHyperlink - linkElement-3
0000046A    0008     TypedPropertyValue - dwHash   
0000046A    0002     WORD - wType                  0x0003
0000046C    0002     WORD - padding                0x0000
0000046E    0004     DWORD - value                 0x00320064

If I understand it well "padding" and "value" change always.
I heard from another thread that Excel 2007 doesn't change Excel 2007 binary format at all.

Please help. It is an urgent issue I need to fix. Is there something I can set on Excel document (using Syncfusion or Excel API) that will prevent this behaviour?

Thanks,
Rad

Edit:


Dim xlsUri As Uri
xlsUri = New Uri("c:\temp\ExcelFile2003binary.xls")

If (IO.File.Exists(xlsUri.LocalPath)) Then
  Dim xlsNode As TreeNode = wip.getWipNode(tvwMain.Nodes, "Excel")
  If (xlsNode Is Nothing) Then
    'Opening excel file link Uri embeded in Tag won't change the file????
    'Users can choose any way to open it (Custom app or Windows Explorer shell)
    folderNode.Nodes.Add("excel", "Excel", 9, 9).Tag = xlsUri.LocalPath
  End If
End If

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灰色世界里的红玫瑰 2024-12-28 12:27:18

我发现这与元数据有关,但这只发生在 excel 2003 文件上(对于 word 文件等没有问题)。

我找到了解决这个问题的方法。

  1. 打开excel 2003(.xls)文件
  2. 点击左上角的office按钮
  3. 选择准备->检查文档。检查
  4. 删除所有文档属性和个人信息。

然后,在保存并关闭文件后,当您只是简单地打开和关闭文件时,MD5 哈希值不会更改。

I found this has something to do with the metadata, but this only happens on excel 2003 files(no problem for word files, etc.).

And I found a way to solve this.

  1. Open the excel 2003 (.xls) file
  2. Click the office button on upper left corner
  3. Choose Prepare -> Inspect Document. Inspect
  4. Remove all the Document Properties and Personal Information.

Then after you save and close the file, the MD5 hash won't change when you just simply open and close the file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文