2016-02-25 4 views
8

में संरक्षित द्विआधारी वर्ड माइक्रोसॉफ्ट वर्ड में मैं Readpassword रूप openxml.doc (*। Docx) फ़ाइल दी साख 'एबीसी' बनाया है और WritePassword के रूप में 'xyz' है के रूप में resaved हो ।दिखा त्रुटि पासवर्ड से सुरक्षित OPENXML वर्ड दस्तावेज़ एक पासवर्ड Office 2010

अब मैं binary.doc को openxml.doc कन्वर्ट करने के लिए है (WdSaveFormat = 0) दस्तावेज़ सफलतापूर्वक Binary.doc के रूप में कोड

// Convert OpenXml.doc into binary.doc  
Convert(@"C:\Test\OpenXml.doc", @"C:\Test\binary.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 oNewPassword = "xyz"; 
    object oOldPassword = "abc"; 
    object test = null; 

    try 
    { 
     // Load a document into our instance of word.exe 
     // suppose password "abc" 
     Word._Document oDoc = oWord.Documents.Open(ref oInput, ref oMissing, 
           ref readOnly, ref oMissing, oOldPassword, 
           ref oMissing, ref oMissing, oNewPassword, 
           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, 
        ref oOldPassword, ref oMissing, 
        oNewPassword, ref oMissing, ref oMissing, 
        ref oMissing, ref oMissing, ref oMissing, 
        ref oMissing, ref oMissing, ref oMissing, 
        ref oMissing, ref oMissing); 
     Console.WriteLine(test); 
     // Always close Word.exe. 
     oWord.Quit(ref oMissing, ref oMissing, ref oMissing); 
    } 
    catch (Exception) 
    { 
     throw; 
    } 
} 

लेकिन नीचे का उपयोग कर बनाई गई है जब कोशिश दस्तावेज़ स्वयं या कोड से खोलने के लिए यह Readpassword ('एबीसी') को स्वीकार करता है के रूप में नीचे

enter image description here

से पता चला है, लेकिन यह स्वीकार करते हैं और पता चला नहीं करता है जब WritePassword ('xyz') देने की कोशिश स्क्रीनशॉट

नीचे पासवर्ड गलत error.Please जांच

enter image description here

enter image description here

उत्तर

4
कोड के साथ

आपके द्वारा दी गई मैं भी पढ़ा/सही ढंग से स्थापित करने के लिए पासवर्ड लिख पा रहा हूँ। ऐसा लगता है कि पद बचाने के स्वरूप बदलने और पढ़ने को बनाए रखने/एक ही समय में पासवर्ड (यह एक बग या साधारण एक असमर्थित परिदृश्य हो सकता है) को बचाने के लिए सक्षम नहीं है।

हालांकि, वहाँ एक बहुत ही सरल समाधान नहीं है: बस पासवर्ड के बिना अस्थायी रूप से दस्तावेज़ सहेजने और उसके बाद पासवर्ड फिर से सेट:

public static void Convert(string input, string output, Word.WdSaveFormat format) 
{ 
    // Create an instance of Word.exe> 
    var oWord = new Word.Application(); 

    // open the protected document 
    var oDoc = oWord.Documents.Open(input, PasswordDocument: "abc", WritePasswordDocument: "xyz"); 

    // save the document without password first 
    oDoc.SaveAs(FileName: output, Password: "", WritePassword: ""); 

    // close and reopen 
    oDoc.Close(); 
    oDoc = oWord.Documents.Open(output); 

    // set the password 
    oDoc.SaveAs(FileName: output, FileFormat: format, Password: "abc", WritePassword: "xyz"); 

    oWord.Quit(); 
} 
+0

तो यह एक बग है! नाइस वैकल्पिक हल! –

संबंधित मुद्दे