Hi,
We are now evaluating Aspose.Words to use it in our product.
During the evaluating we are building a demo application to demonstrate Aspose.Words potential internally.
The demo application should work with Word templates (read and write) and we have the following questions:
How to create a StructuredDocumentTag that allows the user to enter only numbers (and how to control if the user can use the dot (.) sign)?
How to set the “watermark” (placeholder) of a StructuredDocumentTags?
How to create a repeating section content control?
Thanks,
Omri
Hi Omri,
Thanks for your inquiry. Please refer to the following articles: Inserting Content Controls into a Word Document How to Add a Watermark to a Word Document
Also, please attach your expected document containing the document elements (SDTs) you mentioned in points 1), 2) and 3) here for our reference. We will investigate the structure of these document elements as to how you want your final output be generated like. You can create expected document using Microsoft Word. We will then provide you code to achieve the same using Aspose.Words.
Hi
Thanks for the response.
Question 1:
I don’t know how to do it in Word content controls.
I want to create a content control that will allow only numbers (like legacy number field).
Is it possible? If so how?
Question 2 and 3 are described in the attached document.
Thanks,
Omri
Regarding Q1, we are in coordination with product team to get answer pertaining to this query. Soon you will be updated with the required information.
Regarding Q2, please use the following code:
Document doc = new Document();
StructuredDocumentTag sdtRichText = new StructuredDocumentTag(doc, SdtType.RichText, MarkupLevel.Block);
sdtRichText.RemoveAllChildren();
sdtRichText.IsShowingPlaceholderText = false;
Paragraph para = new Paragraph(doc);
Run run = new Run(doc);
run.Text = "This is a custom watermark (via design mode) – how to do it via aspose?";
para.Runs.Add(run);
sdtRichText.ChildNodes.Add(para);
doc.FirstSection.Body.AppendChild(sdtRichText);
doc.Save(MyDir + @"15.6.0.docx");
Regarding Q3 it seems, Aspose.Words currently does not support repeating section content control, we have logged this problem in our issue tracking system as WORDSNET-12146. Our product team will further look into the details of this problem and we will keep you updated on the status of this issue. We apologize for your inconvenience.
Hi Awais,
Q1 - thanks, I’ll wait for your answer.
Q2 – the example code doesn’t produce the same result.
You can see in the attacked documents the differences: when creating a field in word and changing its content in design mode it creates a “watermark” for this field – that means that if you add text and then delete it the watermark appears.
When creating the field via aspose (as you suggested) it’s like entering “normal” text to the field – if the user enters text and then delete it (empty the field) the text is not displayed (and the “real” watermark is displayed).
To reproduce the problem:
A regular word document:
Open a new Word document
Create new rich text field
Enter design mode and edit the watermark text (from “Click here to enter text.” to “this is the new watermark”
Save the document
Edit the field (enter some text)
Empty the field (delete all the text)
The watermark – “this is the new watermark” appears (desired behavior)
An aspose created document:
Document doc = new Document();
StructuredDocumentTag sdtRichText = new StructuredDocumentTag(doc, SdtType.RichText, MarkupLevel.Block);
sdtRichText.RemoveAllChildren();
sdtRichText.IsShowingPlaceholderText = false;
Paragraph para = new Paragraph(doc);
Run run = new Run(doc);
run.Text = "this is the new watermark";
para.Runs.Add(run);
sdtRichText.ChildNodes.Add(para);
doc.FirstSection.Body.AppendChild(sdtRichText);
sdtRichText.LockContentControl = true;
sdtRichText.IsShowingPlaceholderText = true;
doc.Save(@"test.docx");
Open the created Word document (text.docx)
Edit the field (enter some text)
Empty the field (delete all the text)
The watermark – “Click here to enter text.” appears (not desired behavior)
I’ve attached the 2 documents.
Q3 – this ability is very important to us. Can you estimate when you will release an update with this ability?
Thanks,
Omri
Thanks for your inquiry. Please use the following code to fix this issue:
Document doc = new Document();
StructuredDocumentTag sdtRichText = new StructuredDocumentTag(doc, SdtType.RichText, MarkupLevel.Block);
sdtRichText.RemoveAllChildren();
sdtRichText.IsShowingPlaceholderText = false;
BuildingBlock buildingBlock = sdtRichText.Placeholder;
buildingBlock.FirstSection.Body.FirstParagraph.Runs[0].Text = "this is the new watermark";
Paragraph para = new Paragraph(doc);
Run run = new Run(doc);
run.Text = "This is a custom watermark (via design mode) – how to do it via aspose?";
para.Runs.Add(run);
sdtRichText.ChildNodes.Add(para);
doc.FirstSection.Body.AppendChild(sdtRichText);
doc.Save(MyDir + @"15.6.0.docx");
Regarding WORDSNET-12146, this issue is currently pending for analysis and is in the queue. Unfortunately, at the moment we cannot provide you any reliable estimate regarding this issue. We will inform you via this thread as soon as this issue is resolved. We apologize for any inconvenience.
Hi,
Thank you for the quick replay.
Your example works but only if you enter text to the field.
I try to create a field with watermark without entering text and it doesn’t work:
Document doc = new Document();
StructuredDocumentTag sdtRichText = new StructuredDocumentTag(doc, SdtType.RichText, MarkupLevel.Block);
sdtRichText.RemoveAllChildren();
sdtRichText.Placeholder.FirstSection.Body.FirstParagraph.Runs[0].Text = "this is the new watermark";
doc.FirstSection.Body.AppendChild(sdtRichText);
doc.Save(@"test.docx");
Thanks for your inquiry. You can simulate the desired behavior by using the following code:
Document doc = new Document();
StructuredDocumentTag sdtRichText = new StructuredDocumentTag(doc, SdtType.RichText, MarkupLevel.Block);
sdtRichText.Placeholder.FirstSection.Body.FirstParagraph.Runs[0].Text = "this is the new watermark";
((Paragraph)sdtRichText.FirstChild).Runs[0].Text = "this is the new watermark";
doc.FirstSection.Body.AppendChild(sdtRichText);
doc.Save(MyDir + @"15.6.0.docx");
Great! Now it works
So we are waiting for Q1 (if it possible to create a content control that will allow only numbers?) and Q3 (support of repeating section - WORDSNET-12146).
You will update this thread about these issues?
Thanks,
Omri
Regarding Q1, have you managed to create such content control using MS Word. If yes, could you please explain how I can do it?
Regarding Q3, the issue (WORDSNET-12146) is pending for analysis and is in the queue. We will inform you via this thread as soon as this issue is resolved. We apologize for any inconvenience.
Unfortunately, your issue is not resolved yet. Our product team has completed the analysis of this issue and the root cause has been identified. Repeating section content control is introduced in MS Word 2013 and Aspose.Words supports this feature at the moment. You should save document in compliance with ISO29500 OOXML specification, using the following code:
Document doc = new Document(MyDir + @"TestDocumentAspose.docx");
// Set save options to support writing repeating section content controls.
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
saveOptions.Compliance = OoxmlCompliance.Iso29500_2008_Transitional;
doc.Save(MyDir + @"15.7.0.docx", saveOptions);
This will preserve repeating section content controls in Aspose.Words generated output document. We will inform you via this thread as soon as this issue is resolved. We apologize for any inconvenience.
Thanks for being patient. We have a good news i.e. our product team has resolved this issue (WORDSNET-12146) and they have planned to include the fix to your issue in 15.10.0 release of Aspose.Words. We will inform you via this thread as soon as next release containing the fix to this issue is published at the start of next month.
I’ve tested the new version (15.10.0) and it seems that you have added a new SdtType named RepeatingSection.
The purpose of this feature was to be able to create and read repeating sections.
but, when I’m trying to create a new section I get an exception: “Creation of such SdtType is not allowed.”.
My code:
StructuredDocumentTag test1 = new StructuredDocumentTag(doc, SdtType.RepeatingSection, MarkupLevel.Block);
Thanks for your inquiry. We will provide a way in Aspose.Words to add a new repeating section content control programmatically. We had logged this requirement in our issue tracking system as WORDSNET-12655. Our product team is looking into the details of this problem and we will keep you updated on the status of this issue. We apologize for your inconvenience.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.