简体   繁体   English

将docx,doc转换为使用open xml sdk 2.0来打开xml,在转换doc时出错,可以与docx正常工作,其错误是文件已损坏数据

[英]converting docx,doc to open xml using open xml sdk 2.0 its working fine with docx when converting doc its error that file has corrupted data

if (fileExt == ".doc" || fileExt == ".docx") { using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(document,true)) { string docText = null; 如果(fileExt ==“ .doc” || fileExt ==“ .docx”){使用(WordprocessingDocument wordDoc = WordprocessingDocument.Open(document,true)){字符串docText = null; using (StreamReader sr = newStreamReader(wordDoc.MainDocumentPart.GetStream())) { docText = sr.ReadToEnd(); 使用(StreamReader sr = newStreamReader(wordDoc.MainDocumentPart.GetStream())){docText = sr.ReadToEnd(); lbtext.Text = docText; lbtext.Text = docText; } }
} }
} }

You're trying to open an old (2003?) format file using the SDK for the new format... 您正在尝试使用新格式的SDK打开旧的(2003?)格式文件...

The solution is to convert the file into the new format before trying to open it. 解决方案是在尝试打开文件之前将其转换为新格式。 "WordConv.exe" is your friend... “ WordConv.exe”是您的朋友...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM