我有一个带有图表的Word文档。该图表有两个矩形,我想让 txBody 更改文本。
我所知道的:
<cdr:txBody>
<a:bodyPr xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" vertOverflow="clip" lIns="54000" rIns="54000"/>
<a:lstStyle xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>
<a:p xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
<a:pPr algn="ctr"/>
<a:r>
<a:rPr lang="da-DK"/>
**<a:t>BB</a:t>**
</a:r>
</a:p>
</cdr:txBody>
使用 C# 和 DocumentFormat.OpenXml 我尝试了很多不同的方法: (我设法更改文档中的段落、内容控件、图形/图表和表格,但未更改给定图表中的矩形)
(doc是WordprocessingDocument)
`doc.MainDocumentPart?.ChartParts;'
-> 迭代chartSpaceChildElem 我可以找到图表(chart2.xml)-(我可以更改数值,但找不到矩形) 据我所知,我正在处理chart2.xml,但我需要处理drawing1.xml
我尝试过:
doc.MainDocumentPart.Document.Descendants<Drawing>()
doc.MainDocumentPart.Document.Descendants<UserShapes>()
doc.MainDocumentPart.Document.Descendants<DocumentFormat.OpenXml.Drawing.Shape>()
doc.MainDocumentPart.Document.Descendants<Chart>()
doc.MainDocumentPart.Document.Descendants<ExternalData>()
doc.MainDocumentPart?.ImageParts
doc.MainDocumentPart?.DiagramDataParts
以及诸如chartSpaceChildElem.Descendants<DocumentFormat.OpenXml.Office2016.Drawing.ChartDrawing.TxPrTextBody>()
之类的东西
这些都没有给我带来我想要的。
我想我可以获取MainDocumentPart(/word下)中的所有元素。 IE。文档、注释、脚注等。但 Drawing1.xml 位于 /word/drawings/ 下,我无法访问它?
有人可以告诉我如何使用 DocumentFormat.OpenXml 和 C# 来获取它吗? (我不想流式传输 xml。因为这需要我解压缩 word-doc)