我正在做自己的项目,我想将渐变边框应用于 ms word 文件中的所有图片。在我的研究中,我只能插入带有指定参数的新图片。问题是,我不知道如何访问和自定义现有的图片元素。我想,如果我创建新元素,然后简单地将它们附加到文件中,它将完成工作,但是绘图元素会以某种方式丢弃错误,因为它属于树或某种东西。下面是我的垃圾代码的代码片段。
using (WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open(document, true)) {
MainDocumentPart mainPart = wordprocessingDocument.MainDocumentPart;
int imageCount = mainPart.GetPartsCountOfType<ImagePart>();
Console.Write(imageCount);
Drawing sdtElementDrawing = mainPart.Document.Body.Descendants<Drawing>().First();
Body body1 = new Body();
Paragraph paragraph1 = new Paragraph();
Run run1 = new Run();
DW.Inline inline1 = new DW.Inline();
A.Graphic graphic1 = new A.Graphic();
A.GraphicData graphicData1 = new A.GraphicData();
PIC.Picture picture1 = new PIC.Picture();
PIC.ShapeProperties shapeProperties1 = new PIC.ShapeProperties();
A.NoFill noFill1 = new A.NoFill();
A.Outline outline1 = new A.Outline(new A.GradientFill(
new A.GradientStopList(
new A.GradientStop(
new A.SchemeColor(
new A.LuminanceModulation() { Val = 5000 },
new A.LuminanceOffset() { Val = 95000 }
) { Val = A.SchemeColorValues.Accent1 }
) { Position = 0 },
new A.GradientStop(
new A.SchemeColor(
new A.LuminanceModulation() { Val = 45000 },
new A.LuminanceOffset() { Val = 55000 }
) { Val = A.SchemeColorValues.Accent1 }
) { Position = 74000 },
new A.GradientStop(
new A.SchemeColor(
new A.LuminanceModulation() { Val = 45000 },
new A.LuminanceOffset() { Val = 55000 }
) { Val = A.SchemeColorValues.Accent1 }
) { Position = 83000 },
new A.GradientStop(
new A.SchemeColor(
new A.LuminanceModulation() { Val = 30000 },
new A.LuminanceOffset() { Val = 70000 }
) { Val = A.SchemeColorValues.Accent1 }
) { Position = 100000 }),
new A.LinearGradientFill() {
Angle = 5400000,
Scaled = true
}
));
shapeProperties1.Append(noFill1);
shapeProperties1.Append(outline1);
picture1.Append(shapeProperties1);
graphicData1.Append(picture1);
graphic1.Append(graphicData1);
inline1.Append(graphic1);
sdtElementDrawing.Append(inline1);
run1.Append(sdtElementDrawing);
paragraph1.Append(run1);
mainPart.Document.Body.Append(paragraph1);
}