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

Free Support Forum - aspose.com

Lock specific paragraph with HTML to Docx

Hi!

I’m developing a program that will convert resume from HTML to Docx, is it possible for me to lock certain field in the Word? For example I would like to lock the name field, but other field like location and age still can be edit.

Thanks

@milo.khoo,

Thanks for your inquiry. EditableRangeStart class represents a start of an editable range in a Word document. EditableRangeEnd class represents an end of an editable range in a Word document.

A complete editable range in a Word document consists of a EditableRangeStart and a matching EditableRangeEnd with the same Id. EditableRangeStart and EditableRangeEnd are just markers inside a document that specify where the editable range starts and ends.

Following code example shows how to make the document as read only except the second paragraph. Hope this helps you.

Document doc = new Document(MyDir + "in.docx");
doc.Protect(ProtectionType.ReadOnly);


DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToParagraph(1, 0);
builder.StartEditableRange();
builder.MoveToParagraph(1, -1);
builder.EndEditableRange();

doc.Save(MyDir + "Out.docx");

Hi thanks for your reply, is it possible to do the protect in the HTML, then after convert it’ll automatically lock the content?

If it’s not possible, may I know how does MoveToParagraph work? How do I know which Paragraph to move to? Can I search the paragram to move to with my label? (eg. Age, Location, Name, and etc.)

@milo.khoo,

Thanks for your inquiry. Unfortunately, you can not lock the HTML contents. However, after importing the HTML into Aspose.Words’ DOM, you can find the text in the document and lock it. We suggest you please read following articles:
Aspose.Words Document Object Model
Find and Repalce

After finding the text, please use Please use DocumentBuilder.StartEditableRange and DocumentBuilder.EndEditableRange methods according to your requirements.

If you still face problem, please ZIP and share your input and expected output documents here for our reference. We will then provide you more information about your query.