简体   繁体   English

在 PowerPoint OpenXml C# 中访问特定的 TextBody

[英]Accessing a specific TextBody in PowerPoint OpenXml C#

I am trying to extract text from specific text boxes in a PowerPoint template to fill a web form using OpenXml and C#.我正在尝试从 PowerPoint 模板中的特定文本框中提取文本,以使用 OpenXml 和 C# 填充 Web 表单。

So far, what I have seen online iterates through all text boxes using Slide.Descendants<TextBody>() in a foreach loop, or selects only the first or last text box using Slide.Descendants<TextBody>().First() .到目前为止,我在网上看到的在foreach循环中使用Slide.Descendants<TextBody>()遍历所有文本框,或者使用Slide.Descendants<TextBody>().First()仅选择第一个或最后一个文本框。

If I know that the text I am looking for is contained in say textBody10, is there a way for me to access that text body directly, or is there a way to identify the name of a given textbody within the foreach loop?如果我知道我要查找的文本包含在 textBody10 中,有没有办法让我直接访问该文本正文,或者有没有办法在 foreach 循环中识别给定文本正文的名称?

To solve the problem, I used a trial-and-error approach.为了解决这个问题,我使用了试错法。 I indexed the foreach loop with a local variable to identify the TextBody relevant to each field in the form.我使用局部变量对 foreach 循环进行索引,以标识与表单中每个字段相关的 TextBody。 I am not sure about the robustness of this solution, but it seems to be working fine for now.我不确定这个解决方案的稳健性,但它现在似乎工作正常。 If anyone has a more elegant solution, I would gladly hear it.如果有人有更优雅的解决方案,我很乐意听到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM