Защищенный паролем документ OpenXml Word (т. Е. Документ, созданный в wdFormatDocument = 12), который переписывается в качестве двоичного документа Word, защищенного паролем (wdFormatDocument = 0), дает ошибку «Пароль неверно. Word не может открыть документ. "Защищенный паролем OpenXml Документ Word, сохраненный как двоичный пароль, защищенный паролем Word
В приведенном ниже коде «74.doc» создается с использованием wdFormatDocument = 12 при преобразовании этого документа обратно в wdFormatDocument = 0, он дает ошибку. Отлаживайте код и выполняйте поиск по сети, но не можете найти точную причину, почему это происходит.
Ошибка вызвана этой линии:
oDoc = oWord.Documents.Open(ref oInput, ref oMissing, ref readOnly, ref oMissing, oReadPassword, ref oMissing, ref oMissing, oWritePassword , ref oMissing, ref oMissing, ref oMissing, ref isVisible, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
Это код
class Docx
{
public static void Start()
{
// Convert Input.docx into Output.doc
Convert(@"C:\Test\74.doc", @"C:\Test\74_0.doc", WdSaveFormat.wdFormatDocument);
}
// Convert a Word .docx to Word 2003 .doc
public static void Convert(string input, string output, WdSaveFormat format)
{
// Create an instance of Word.exe
Word._Application oWord = new Word.Application();
// Make this instance of word invisible (Can still see it in the taskmgr).
oWord.Visible = false;
// Interop requires objects.
object oMissing = System.Reflection.Missing.Value;
object isVisible = true;
object readOnly = false;
object oInput = input;
object oOutput = output;
object oFormat = format;
object oWritePassword = "abc";
object oReadPassword = "xyz";
try
{
// Load a document into our instance of word.exe
Word._Document oDoc = oWord.Documents.Open(ref oInput, ref oMissing, ref readOnly, ref oMissing, oReadPassword, ref oMissing, ref oMissing, oWritePassword, ref oMissing, ref oMissing, ref oMissing, ref isVisible, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
// Make this document the active document.
oDoc.Activate();
// Save this document in Word 2003 format.
oDoc.SaveAs(ref oOutput, ref oFormat, ref oMissing, oReadPassword, ref oMissing, oWritePassword, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
// Always close Word.exe.
oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
}
catch (Exception)
{
throw;
}
}
}
Update: если только для чтения, как верно указано в аргументах, документ открывается успешно. Но установка на false вызывает ошибку.
Просьба также указать код, который вызывает ошибку, указывая, какая строка вызывает ее. –
@Cindy: на этом lin eits get erroWord._Document oDoc = oWord.Documents.Open (ref oInput, ref oMissing, ref readOnly, ref oMissing, oReadPassword, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref isVisible, ref oMissing, ref oMissing, ref oMissing, ref oMissing); – John
@Cindy, когда передается readonly как истина, документ открывается успешно.Но установить значение false его отображаемой ошибки – John