所有形状的集合参考循环通过集合

现在你已经拥有了文档中所有形状引用的集合。使用 foreach 遍历集合,并通过每次迭代创建一个 Blip 对象。将 Blip 对象嵌入值设置为先前从图像部件捕获的图片 ID 参考。还要创建一个 Stretch 对象和 FillRectangle 对象(这些并不是必需的,它们只是用于正确对齐图像)。并将每个附加到其父对象,如 XML 树等效。

foreach (DocumentFormat.OpenXml.Office2010.Word.DrawingShape.WordprocessingShape sp in shapes2)
                              {
                                  //Wps.ShapeProperties shapeProperties1 = 
                                  A.BlipFill blipFill1 = new A.BlipFill() { Dpi = (UInt32Value)0U, RotateWithShape = true };
                                  A.Blip blip1 = new A.Blip() { Embed = temp };

                                  A.Stretch stretch1 = new A.Stretch();
                                  A.FillRectangle fillRectangle1 = new A.FillRectangle() { Left = 10000, Top = 10000, Right = 10000, Bottom = 10000 };
                                  Wps.WordprocessingShape wordprocessingShape1 = new Wps.WordprocessingShape();

                                      stretch1.Append(fillRectangle1);
                                      blipFill1.Append(blip1);
                                      blipFill1.Append(stretch1);
                                      Wps.ShapeProperties shapeProperties1 = sp.Descendants<Wps.ShapeProperties>().First();
                                      shapeProperties1.Append(blipFill1);
                                      
                              }