public static TextCharacterPropertiesType GetRunProperties(this DocumentFormat.OpenXml.Presentation.Shape shape) { Paragraph paragraph = shape.TextBody.FirstElement <Paragraph>(); if (paragraph != null) { Run run = paragraph.FirstElement <Run>(); if (run != null) { return(run.RunProperties.CloneNode(true) as RunProperties); } EndParagraphRunProperties endProp = paragraph.FirstElement <EndParagraphRunProperties>(); return(endProp.CloneNode(true) as EndParagraphRunProperties); } return(null); }
private static Run CreateNewRun(Paragraph paragraph) { Run run = new Run() { Text = new Text() }; EndParagraphRunProperties runProperties = paragraph.Elements <EndParagraphRunProperties>().FirstOrDefault(); if (runProperties != null) { RunProperties newRunProperties = new RunProperties() { Language = runProperties.Language, FontSize = runProperties.FontSize, Dirty = runProperties.Dirty }; foreach (var prop in runProperties.Elements()) { newRunProperties.Append(prop.CloneNode(true)); } run.InsertAt(newRunProperties, 0); } return(run); }
private void SetCellStyleFromLegend(TableRow tableRow, Row row) { int tableColumnIndex = 0; if (element.UseRowHeaders) { tableColumnIndex++; } if (row.Legends.All(l => l == null)) { return; } for (int dataColumnIndex = 0; dataColumnIndex < row.Data.Count; dataColumnIndex++) { if (row.Legends[dataColumnIndex] != null) { TableCell tableCell = tableRow.Elements <TableCell>().ElementAt(tableColumnIndex); ShapeElement legend = row.Legends[dataColumnIndex] as ShapeElement; if (legend != null) { A.SolidFill fill = legend.Element.GetFill(); A.Outline outline = legend.Element.GetOutline(); A.SolidFill outlineSolidFill = outline.FirstElement <A.SolidFill>(); if (tableCell.TableCellProperties.Elements <A.SolidFill>().Count() == 0) { tableCell.TableCellProperties.AppendChild <A.SolidFill>(fill.CloneNode(true) as A.SolidFill); } else { tableCell.TableCellProperties.ReplaceChild <A.SolidFill>(fill.CloneNode(true), tableCell.TableCellProperties.FirstElement <A.SolidFill>()); } if (outlineSolidFill != null) { if (tableCell.TableCellProperties.LeftBorderLineProperties != null) { tableCell.TableCellProperties.LeftBorderLineProperties.RemoveAllChildren <NoFill>(); tableCell.TableCellProperties.LeftBorderLineProperties.RemoveAllChildren <A.SolidFill>(); tableCell.TableCellProperties.LeftBorderLineProperties.Append(outlineSolidFill.CloneNode(true)); } if (tableCell.TableCellProperties.TopBorderLineProperties != null) { tableCell.TableCellProperties.TopBorderLineProperties.RemoveAllChildren <NoFill>(); tableCell.TableCellProperties.TopBorderLineProperties.RemoveAllChildren <A.SolidFill>(); tableCell.TableCellProperties.TopBorderLineProperties.Append(outlineSolidFill.CloneNode(true)); } if (tableCell.TableCellProperties.RightBorderLineProperties != null) { tableCell.TableCellProperties.RightBorderLineProperties.RemoveAllChildren <NoFill>(); tableCell.TableCellProperties.RightBorderLineProperties.RemoveAllChildren <A.SolidFill>(); tableCell.TableCellProperties.RightBorderLineProperties.Append(outlineSolidFill.CloneNode(true)); } if (tableCell.TableCellProperties.BottomBorderLineProperties != null) { tableCell.TableCellProperties.BottomBorderLineProperties.RemoveAllChildren <NoFill>(); tableCell.TableCellProperties.BottomBorderLineProperties.RemoveAllChildren <A.SolidFill>(); tableCell.TableCellProperties.BottomBorderLineProperties.Append(outlineSolidFill.CloneNode(true)); } } TextCharacterPropertiesType prop = legend.Element.GetRunProperties(); foreach (Paragraph paragraph in tableCell.TextBody.Elements <Paragraph>()) { foreach (Run run in paragraph.Elements <Run>()) { run.RunProperties.RemoveAllChildren(); foreach (var item in prop.ChildElements) { run.RunProperties.AppendChild(item.CloneNode(true)); } } EndParagraphRunProperties endParagraphProperties = paragraph.FirstElement <EndParagraphRunProperties>(); if (endParagraphProperties != null) { endParagraphProperties.RemoveAllChildren(); foreach (var item in prop.ChildElements) { endParagraphProperties.AppendChild(item.CloneNode(true)); } } } } } tableColumnIndex++; } }