We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to lock the fields?

I want to lock the fields !
Like MS OFFICE as the shortcut key Ctrl+F11!

Please tell me the way to achieve it use java!
https://forum.aspose.com/c/words/8Aspose.words for java!

Hi Gong,

Thanks for your inquiry. Please use the isLocked method of FieldChar class to lock and unlock fields. A complete field in a Microsoft Word document is a complex structure consisting of a field start character, field code, field separator character, field result and field end character. Some fields only have field start, field code and field end. Please use following code snippet for your kind reference.

Document doc = new Document(MYDir + "in.docx");

FieldChar fieldStart = (FieldChar)doc.getChild(NodeType.FIELD_START, 0, true);
String[] fieldNames = new String[] { "LockField" };
Object[] fieldValues = new Object[] { "LockField value test" };
doc.getMailMerge().execute(fieldNames, fieldValues);
doc.save(MYDir + "AsposeOut-Java.docx");
Document doc = new Document(MYDir + "1.doc");
for (FieldChar fieldStart : (Iterable<FieldChar>)doc.getChildNodes(NodeType.FIELD_START, true))
doc.save(MYDir + "AsposeOut-Java.docx");

Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.

Thank you very much!

fieldStart.isLocked(true); Yes, it’s can make doc.updateFields(); don’t update the fields, but, then, open the word for MS OFFICE2003, pass F9 on the fields, it will update!

Back to my first question !

open the word for MS OFFICE2003, pass Ctrl+F11 on the fields to lock it, then pass F9 on the fields ,you can see, it never update now.

I don’t want it to update! when I pass F9!

Hi Gong,

Thanks for sharing the details. I have managed to reproduce the same issue at my side. The FieldChar.isLocked method do not work for Doc file format. I have logged this issue as WORDSNET-7346 in our issue tracking system. I have linked this forum thread to the same issue and you will be notified via this forum thread once this issue is resolved.

As a workaround, first save document to Docx file format and than save it again to Doc file format as shown in following code snippet.

Document doc = new Document(MYDir + "Test41.doc");
for (FieldChar fieldStart : (Iterable)doc.getChildNodes(NodeType.FIELD_START, true))
ByteArrayOutputStream dstStream = new ByteArrayOutputStream();
doc.save(dstStream, SaveFormat.DOCX);
InputStream inputStream = new ByteArrayInputStream(dstStream.toByteArray());
doc = new Document(inputStream);
doc.save(MYDir + "AsposeOut-Java.doc");

We apologize for your inconvenience.

The issues you have found earlier (filed as WORDSNET-7346) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.