我试图修复经典asp中大量损坏的.docx
文件。如何以编程方式修复损坏的docx文件(添加丢失的字节)
(这些文件在最后丢失字节 - 详见this question)。
当我在Sublime中查看文件(以十六进制视图显示它)时,可以通过将0000
添加到文件的末尾来修复损坏。
但我很努力的4个零添加到年底,编程。
我试图使用cByteArray类,它使用的是这样的:
With oByte
Call .AddBytes(LoadBytes(sFilePath))
Call .AddBytes(HOW DO I GET THE BYTE VALUE OF 0000 HERE?)
lngBytes = .BytesTotal
ByteArray = .ReturnBytes
End With
Call SaveBytesToBinaryFile(ByteArray, sNewFilePath)
我无法工作,如何让0000
值到.AddBytes()
方法。
我该怎么做?我有点出于自己的深度,并不确定我是否以正确的方式接近这一点。
在我的无知,这是我曾尝试:
Redimming ByteArray
留下额外的字节空的(因为我觉得0000
表示空值)。
这似乎并没有改变文件。新保存的文件与旧文件相同。
With oByte
Call .AddBytes(LoadBytes(sFilePath))
ByteArray = .ReturnBytes
End With
arrayLength = ubound(ByteArray)
redim ByteArray(arrayLength + 2)
Call SaveBytesToBinaryFile(ByteArray, sNewFilePath)
从十六进制转换0000
到字节并将其添加到已损坏的文件字节。
此外,这似乎并没有改变文件。
dim k, hexString, str, stream, byteArrToAdd
hexString = "000000"
For k = 1 To Len(hexString) Step 2
str = str & Chr("&h" & Mid(hexString, k, 2))
response.write "<hr />" & str & "<hr />"
Next
Set stream = CreateObject("ADODB.Stream")
With stream
.Open
.Type = 2 ' set type "text"
.WriteText str
.Position = 0
.Type = 1 ' change type to "binary"
byteArrToAdd = .Read
.Close
End With
set stream = nothing
With oByte
Call .AddBytes(LoadBytes(sFilePath))
Call .AddBytes(byteArrToAdd)
ByteArray = .ReturnBytes
End With
Call SaveBytesToBinaryFile(ByteArray, sNewFilePath)
获取损坏的文件的最后一个字节,并redimming的ByteArray之后将其添加到2个新值。
这似乎并没有改变文件在所有!
With oByte
Call .AddBytes(LoadBytes(sFilePath))
ByteArray = .ReturnBytes
End With
arrayLength = ubound(ByteArray)
finalByte = ByteArray(arrayLength)
redim ByteArray(arrayLength + 2)
ByteArray(arrayLength + 1) = finalByte
ByteArray(arrayLength + 2) = finalByte
Call SaveBytesToBinaryFile(ByteArray, sNewFilePath)
您应该能够使用附加这些'CHRB()',像'呼叫.AddBytes(CHRB(H00)CHRB(H00))'应该工作。 – Lankymart
我无法得到这个工作。 “ControlChars.NullChar”的同上 - 既不添加任何字节到文件。你认为它与此有关吗? http://www.vbforums.com/showthread.php?628175-CHR(-amp-H00)-vs-CHR-(-amp-H00)(遗憾的是,没有提供解决方案) –
我很抱歉,你的男人。 ..2017年11月仍然使用经典的asp:/ – 2Noob2Good