I am trying to extract color of the font from a PPTx file , I am a beginner using Open XML SDK. My aim is to extract the font color, replace the color and save the file. Here is what I have tried so far.
using Drawing = DocumentFormat.OpenXml.Drawing;
public static void SetPPTShapeColor(string docName)
{
using (PresentationDocument ppt = PresentationDocument.Open(docName, true))
{
// Get the relationship ID of the first slide.
PresentationPart part = ppt.PresentationPart;
OpenXmlElementList slideIds = part.Presentation.SlideIdList.ChildElements;
string relId = (slideIds[0] as SlideId).RelationshipId;
Console.WriteLine(relId);
// Get the slide part from the relationship ID.
SlidePart slidepart = (SlidePart)part.GetPartById(relId);
if (slidepart != null && slidepart.Slide!=null)
{
// Get the shape tree that contains the shape to change
ShapeTree tree = slidepart.Slide.CommonSlideData.ShapeTree;
// Get the first shape in the shape tree.
Drawing.Shape shape = tree.GetFirstChild<Drawing.Shape>();
if (shape != null)
{
// Get the style of the shape.
Drawing.ShapeStyle style = shape.ShapeStyle;
// Get the fill reference.
Drawing.FillReference fillRef = style.FillReference;
// Set the fill color to SchemeColor Accent 6;
fillRef.SchemeColor = new Drawing.SchemeColor();
fillRef.SchemeColor.Val = Drawing.SchemeColorValues.Accent6;
// Save the modified slide.
slidepart.Slide.Save();
}
}
}
}
Please let me know if anybody knows how to extract the font color. The above code does not seem to extract the color of the font.