受密码保护的OpenXml Word文档在Office 2010中作为受密码保护的二进制Word重新保存 [英] Password protected OpenXml Word document resaved as a password protected binary Word in office 2010

查看:171
本文介绍了受密码保护的OpenXml Word文档在Office 2010中作为受密码保护的二进制Word重新保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


密码保护的OpenXml Word文档(在wdFormatDocument = 12中创建的ie.document)被重新保存为密码保护的二进制Word文档(wdFormatDocument = 0)给出错误"密码错误.Word无法打开文件。"



在下面的代码"74.doc"中。在将此doc转换回wdFormatDocument = 0时使用wdFormatDocument = 12创建它会给出错误。

Debug代码并发现当传递 
readonly =" true" 
报告成功开启。当 
readonly =" false"  其
在此行显示错误  ;
oWord.Documents.Open(



  class Docx 
{
public static void Start()
{
//将Input.docx转换为Output.doc
转换(@"C:\ Test\74.doc",@" C:\ Test \ _ 74_0.doc",WdSaveFormat.wdFormatDocument);

}

//将Word .docx转换为Word 2003 .doc
public static void转换(字符串输入,字符串输出,WdSaveFormat格式)
{
//创建一个Word.exe实例
Word._Application oWord = new Word.Application();

//使这个单词实例不可见(仍然可以在taskmgr中看到它)。
oWord.Visible = false;

// Interop需要对象。
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
{
//将文档加载到我们的word.exe实例中
Word._Document oDoc = oWord.Documents.Open(ref oInput,ref oMissing ,REF只读的,REF oMissing,oReadPassword,REF oMissing,参考oMissing,oWritePassword,REF oMissing,REF oMissing,REF oMissing,REF ISVISIBLE,REF oMissing,REF oMissing,REF oMissing,REF oMissing);

//将此文档设为活动文档。
oDoc.Activate();

//以Word 2003格式保存此文档。
oDoc.SaveAs(参照oOutput,REF oFormat,参考oMissing,oReadPassword,参考oMissing,oWritePassword,REF oMissing,REF oMissing,REF oMissing,REF oMissing,REF oMissing,REF oMissing,REF oMissing,REF oMissing,REF oMissing ,ref oMissing);

//始终关闭Word.exe。
oWord.Quit(ref oMissing,ref oMissing,ref oMissing);
}
catch(例外)
{
throw;
}
}
}



解决方案


密码保护的OpenXml Word文档(ie.document在wdFormatDocument中创建) = 12)被重新保存为密码保护的二进制Word文档(wdFormatDocument = 0)给出错误"密码不正确.Word无法打开文档。"



在下面代码"74.doc"在将此doc转换回wdFormatDocument = 0时使用wdFormatDocument = 12创建它会给出错误。调试代码并在网上搜索,但无法找到导致这种情况发生的确切根本原因。



  class Docx 
{
public static void Start()
{
//将Input.docx转换为Output。 doc
Convert(@"C:\ Test \\\ n.d.d",@" C:\ Test \ _ 74_0.doc",WdSaveFormat.wdFormatDocument);

}

//将Word .docx转换为Word 2003 .doc
public static void转换(字符串输入,字符串输出,WdSaveFormat格式)
{
//创建一个Word.exe实例
Word._Application oWord = new Word.Application();

//使这个单词实例不可见(仍然可以在taskmgr中看到它)。
oWord.Visible = false;

// Interop需要对象。
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
{
//将文档加载到我们的word.exe实例中
Word._Document oDoc = oWord.Documents.Open(ref oInput,ref oMissing ,REF只读的,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);

//将此文档设为活动文档。
oDoc.Activate();

//以Word 2003格式保存此文档。
oDoc.SaveAs(参照oOutput,REF oFormat,参考oMissing,oReadPassword,参考oMissing,oWritePassword,REF oMissing,REF oMissing,REF oMissing,REF oMissing,REF oMissing,REF oMissing,REF oMissing,REF oMissing,REF oMissing ,ref oMissing);

//始终关闭Word.exe。
oWord.Quit(ref oMissing,ref oMissing,ref oMissing);
}
catch(例外)
{
throw;
}
}
}






Password protected OpenXml Word document(ie.document created in wdFormatDocument=12) that gets resaved as a password protected binary Word document(wdFormatDocument=0) gives error "The password is incorrect.Word cannot open the document."

In below code "74.doc" is created using wdFormatDocument=12 when converting this doc back to wdFormatDocument=0 it is giving error. Debug the code and found that when pass readonly="true" the report is opening sucessfully.when readonly="false" its showing error on this line oWord.Documents.Open(

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;
            }
        }
    }

解决方案

Password protected OpenXml Word document(ie.document created in wdFormatDocument=12) that gets resaved as a password protected binary Word document(wdFormatDocument=0) gives error "The password is incorrect.Word cannot open the document."

In below code "74.doc" is created using wdFormatDocument=12 when converting this doc back to wdFormatDocument=0 it is giving error. Debug the code and search on net but could not find out the exact root cause why this happens.

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, ref oMissing, 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;
            }
        }
    }



这篇关于受密码保护的OpenXml Word文档在Office 2010中作为受密码保护的二进制Word重新保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆