I only see an option for text, which causes all of the formatting to be changed. When I save the ouput of a content control in Word, if I use to string, nothing is returned, and get text returns the correct data but the format is changed.
namespace ContentControl
{
public class CC_Class
{
static void Main(string[] args)
{
Aspose.Words.Document doc = new Aspose.Words.Document(@"d:\RDCManEULAedit.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
Aspose.Words.Document newdoc = new Aspose.Words.Document(@"d:\NewDoc.docx");
DocumentBuilder newbuilder = new DocumentBuilder(newdoc);
// Get the first content control from the document
StructuredDocumentTag SdtRTBlock = (StructuredDocumentTag)doc.GetChild(NodeType.StructuredDocumentTag, 0, true);
newbuilder.InsertParagraph();
newbuilder.Writeln(SdtRTBlock.GetText());
// newbuilder.Writeln(SdtRTBlock.ToString());
newdoc.Save(@"d:\newdoc.docx", SaveFormat.Docx);
Hi Nathan,
Thanks for your inquiry. Could you please attach your input Word document here for testing? I will investigate the issue on my side and provide you more information.
I attached the file I am testing with now.
Hi Nathan,
Thanks for sharing the detail. I have tested the scenario using Aspose.Words for .NET 15.4.0 and have not found any issue. Please use Node.ToString(SaveFormat.Text) method to convert content control to text and use NodeImporter.ImportNode method to import a node from one document into another. Please check following code example for your kind reference and let us know if you have any more queries.
Document doc = new Document(MyDir + "RDCManEULAedit.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
Aspose.Words.Document newdoc = new Aspose.Words.Document();
DocumentBuilder newbuilder = new DocumentBuilder(newdoc);
// Get the first content control from the document
StructuredDocumentTag SdtRTBlock = (StructuredDocumentTag)doc.GetChild(NodeType.StructuredDocumentTag, 0, true);
newbuilder.InsertParagraph();
newbuilder.Writeln("GetText()");
newbuilder.Writeln(SdtRTBlock.GetText());
newbuilder.Writeln("ToString()");
newbuilder.Writeln(SdtRTBlock.ToString(SaveFormat.Text));
newdoc.Save(MyDir + "Out.docx");
newdoc = new Aspose.Words.Document();
NodeImporter imp = new NodeImporter(doc, newdoc, ImportFormatMode.KeepSourceFormatting);
Node impNode = imp.ImportNode(SdtRTBlock, true);
newdoc.FirstSection.Body.AppendChild(impNode);
newdoc.Save(MyDir + "Save formatted StructuredDocumentTag.docx");
Fantastic, worked great. Thank you for your time.
Hi Nathan,
Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.