Replace as You Type Smart Quotes and Straight Quotes in Word Document | C# .NET

Hi,

I have an issue generating smart quotes when adding content to a Word document. Part of our product is amending text in the document to something that is pre-configured by a user. However it has come to our attention that quotes don’t seem to be able to be converted to smart quotes as per the option in Word itself (Options>proofing>autocorrect options>autoformat as you type>replace as you type>“straight quotes” with “smart quotes”).

Is there a setting that we were unable to find to enable straight quotes to be converted to smart quotes when we add them to the document, does this need to be processed in some other way, or is this simply not supported?

Any help you can provide would be greatly appreciated.

@SyseroSteve,

We have logged your requirement in our issue tracking system. Your ticket number is WORDSNET-22744. We will further look into the details of this requirement and will keep you updated here on the status of the linked ticket.

@SyseroSteve,

Regarding WORDSNET-22744, please tell, do you only use DocumentBuilder Class to write content or what other API methods of Aspose.Words do you use to write text inside Word document?

We use a variety in different scenarios but for an example here of something I know has the issue we are manually replacing Word StructuredDocumentTags with Runs by cloning the Run inside the Sdt, deleting the sdt and putting the new Run in its place. We are using .ParentNode.InsertBefore() as the actual insertion method.

@SyseroSteve,

We have logged these details in our issue tracking system and will keep you posted here on any further updates.

@SyseroSteve,

Regarding WORDSNET-22744, I am afraid, it is not feasible for us to integrate requested feature into all Aspose.Words’ methods that set document’s text. But we suggest you to please use the following code to replace the quotes in the entire document:

Document doc = new Document(dir + "test.docx");

doc.Range.Replace(new Regex("(?<=\\s|\ue00d|^)\""), "“");
doc.Range.Replace(new Regex("\""), "”");

doc.Save(dir + "out.docx");

Or, to change only some node, this code can be used:

Document doc = new Document(dir + "test.docx");

doc.FirstSection.Body.FirstParagraph.Range.Replace(new Regex("(?<=\\s|\ue00d|^)\""), "“");
doc.FirstSection.Body.FirstParagraph.Range.Replace(new Regex("\""), "”");

doc.Save(dir + "out.docx");