我正在操作服务器端的 WW WW 2010 文档, 文档中有些内容控件已检查以下 Locking 属性
- Content control cannot be deleted
- Contents cannot be edited
有人能建议设置这些锁定选项, 使用 OpenXML SDK 来伪造或删除这些选项吗?
我正在操作服务器端的 WW WW 2010 文档, 文档中有些内容控件已检查以下 Locking 属性
有人能建议设置这些锁定选项, 使用 OpenXML SDK 来伪造或删除这些选项吗?
The openxml SDK provides the Lock
class and the LockingValues
enumeration
for programmatically setting the options:
So, to set those two options to "false" (LockingValues.Unlocked
),
search for all SdtElement
elements in the document and set the Val
property to
LockingValues.Unlocked
.
下面的代码举了一个例子:
static void UnlockAllSdtContentElements()
{
using (WordprocessingDocument wordDoc =
WordprocessingDocument.Open(@"c: empmyword.docx", true))
{
IEnumerable<SdtElement> elements =
wordDoc.MainDocumentPart.Document.Descendants<SdtElement>();
foreach (SdtElement elem in elements)
{
if (elem.SdtProperties != null)
{
Lock l = elem.SdtProperties.ChildElements.First<Lock>();
if (l == null)
{
continue;
}
if (l.Val == LockingValues.SdtContentLocked)
{
Console.Out.WriteLine("Unlock content element...");
l.Val = LockingValues.Unlocked;
}
}
}
}
}
static void Main(string[] args)
{
UnlockAllSdtContentElements();
}
仅对那些复制此代码的人, 请记住, 如果没有与内容控制相关的锁, 那么就不会有与它相关的锁属性, 所以当代码执行以下指令时, 它会返回一个例外, 因为找不到元素 :
Lock l = elem.SdtProperties.ChildElements.First<Lock>();
解决这个问题的方法是使用 FirstOrDefault
而不是 First
。
I have a question regarding a WORD 2007 form used to gather information from users. I had it working in WORD 2003 then pulled it over into WORD 2007 and got it working but couldn t leave well enough ...
I m currently working on tables in a Word template with Interop. In my template I have a table which I want to copy (Copying will make it easier for me to fill in the data rather than inserting rows ...
I need to print 20,000 Word documents. Naturally this is a logistical nightmare. For example: if the power goes out, I need some software that will be able to resume where the printing failed. Also, ...
I have an issue on a client machine that seems to be interferring with a word addin that ive built. When any word document opens on the client machine, a second blank document opens also. Ive seen ...
I have a Word 2003 document saved as a XML in WordProcessingML format. It contains few placeholders which will be dynamically replaced by an appropriate content. But, the problem is that Word ...
Looking to develop server-side application that will process documents. The source documents are mostly MS-Word 2003, 2007, i.e. the MS version of Docx. Want the server application to be able to run ...
For years, we have been printing Word 2003 documents that have been saved to a OLE object column using an access report. We are using Access 2003. For some reason when we copy a Word 2003 document ...
I m using Microsoft Office 2003 and creating a bunch of template documents to standardize some tasks. I asked this on Superuser.com and got no response so I m thinking it s too program-y and hoping I ...