This is a migrated thread and some comments may be shown as answers.

Generate Report

4 Answers 32 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
wei
Top achievements
Rank 1
wei asked on 30 Jul 2020, 04:21 AM

Hello,

I want to load document(.docx) and replace some content, 

here is code:

RadFlowDocument document;
using (Stream input = System.IO.File.OpenRead(templatePath))
{
    document = provider.Import(input);               
}
RadFlowDocumentEditor editor = new RadFlowDocumentEditor(document);

1. Replace text: I use :

editor.ReplaceText("#Name#", "AAAAAAA");

 

4 Answers, 1 is accepted

Sort by
0
wei
Top achievements
Rank 1
answered on 30 Jul 2020, 04:34 AM
2. Find Table and replce content
I use 
IEnumerable<Table> tables = editor.Document.EnumerateChildrenOfType<Table>();
foreach (var table in tables)
{
    //find table caption="XX"
    //do domething
}

now I have problem,how can i find the table caption?

like this link:
https://docs.telerik.com/devtools/aspnet-ajax/controls/editor/functionality/dialogs/table-wizard

3. How can I find and replace text like #Chart# to a Chart?
0
Georgi
Telerik team
answered on 31 Jul 2020, 08:31 PM

Hi,

Thank you for your interest in Telerik Document Processing.

If I am understanding correctly the scenario, you would like to find a caption of a table and modify its content, am I right? When a caption is added to a table, the caption content may be represented as a Paragraph element with a Caption style. In order to achieve the desired result, after the document is imported using the WordsProcessing library, you can iterate the Paragraph elements with a Caption style id and manipulate their content, for example:

foreach (var paragraph in document.EnumerateChildrenOfType<Paragraph>().Where(p => p.StyleId == "Caption"))
{
    paragraph.Inlines.AddRun(" modified");
}

Regarding the replacement of text content with a chart, I am afraid that with the current implementation of the library charts are not supported. We have logged a feature request in our feedback portal: Add possibility to work with charts in a flow document, where you can vote to increase its priority and subscribe to be notified when the status of the item changes. I am sorry that I couldn't find any workaround to provide you with.

Regards,
Georgi
Progress Telerik

0
wei
Top achievements
Rank 1
answered on 03 Aug 2020, 07:46 AM
Thanks for reply,

Because there are many table in the word template and table order maybe change by user,

so I want to find an attribute to determine which table it is.

I use:

document.EnumerateChildrenOfType<Paragraph>().Where(p => p.StyleId == "Caption") 

but it not found, hope there is an easier way to find the table, like this: 

document.Tables.FirstOrDefault(t => t.TableCaption == "Target_Table");//Reference DocX

Regarding point 3, I will think of other ways,

Thanks :-)
0
Georgi
Telerik team
answered on 05 Aug 2020, 07:07 AM

Hello,

Please, excuse me for misunderstanding you in my previous answer. The example I mentioned is related to Paragraph elements with a caption style designated to a Table, Figure, or Equation, and not to a table with caption property. Table caption property is not supported by the current implementation of the WordsProcessing library. We have logged a feature request in our feedback portal: Add support of alternative text of a Table. I am afraid that I couldn't find any other table properties appropriate for the scenario you would like to achieve.

We had a team discussion about this feature request and we have increased the priority of this item. However, the implementation of the item depends on whether it passes the QA check and I cannot commit to a specific time-frame when it will be delivered. Please, make sure to click the Follow button to be notified when the status of the item changes.

Regards,
Georgi
Progress Telerik

Tags
General Discussions
Asked by
wei
Top achievements
Rank 1
Answers by
wei
Top achievements
Rank 1
Georgi
Telerik team
Share this question
or