挑战 - 在vb.net中打开受密码保护的文件时显示只读按钮 [英] Challenge - Readonly button is shown while opening password protected file in vb.net
问题描述
我在Word 2007中使用文字自动化。
我有一个正常的.docx文件,我想密码保护,后者显示相同的用户。
当我用密码打开生成的.docx时,word会询问您是否要查看只读。有一个按钮可以打开只读。密码保护文件的全部目的都将丢失。
有人能告诉我以下代码是否适合生成受密码保护的文件。保存文件或打开文件以向用户显示时,我不确定是否必须进行一些设置。
Hi,
I am using word automation in Word 2007.
I have a normal .docx file which I want to password protect and latter on show the same to user.
When I open the generated .docx with password, word asks if you want to see the read only or not. There is a button to open as read only. The whole purpose of password protecting the file is lost.
Can someone tell me if the below code is right to generate the password protected file. Not sure if I have to do some setting while saving the file or opening the file to show it to user.
Dim value As Object = System.Reflection.Missing.Value
Dim app As Microsoft.Office.Interop.Word.Application = New Microsoft.Office.Interop.Word.Application()
Dim doc As Document
Dim missing As Object = System.Reflection.Missing.Value
Dim readOnly1 As Object = False
Dim visible As Object = True
Dim _Password As Object = "abc"
Dim fileToOpen As Object = text
doc = app.Documents.Open(fileToOpen, missing, readOnly1, missing, missing, missing, missing, missing, missing, missing, missing, visible, visible, missing, missing, missing)
doc.Activate()
doc.SaveAs(fileToOpen, missing, readOnly1, missing, missing, _Password, False, missing, missing, missing, missing, visible, visible, missing, missing, missing)
doc.Close(False, False, False)
推荐答案
检查文档真的很难吗?
Is it really so hard to check the documentation?
expression .SaveAs(FileName, FileFormat, LockComments, Password, AddToRecentFiles, WritePassword, ReadOnlyRecommended, EmbedTrueTypeFonts, SaveNativePictureFormat, SaveFormsData, SaveAsAOCELetter, Encoding, InsertLineBreaks, AllowSubstitutions, LineEnding, AddBiDiMarks)
看看这里: SaveAs Method [ ^ ]
在相关页面的底部,您将找到使用密码保存文档的最佳做法。
Have a look here: SaveAs Method[^]
On the bottom of related page, you'll find best practices to save document with password.
这篇关于挑战 - 在vb.net中打开受密码保护的文件时显示只读按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!