Exemple #1
0
 public static A.SolidFill GetFill(this DocumentFormat.OpenXml.Presentation.Shape shape)
 {
     A.SolidFill fill = shape.ShapeProperties.FirstElement <A.SolidFill>();
     if (fill != null)
     {
         return(fill.CloneNode(true) as A.SolidFill);
     }
     return(null);
 }
Exemple #2
0
        public void Process(ShapeElementBase shape)
        {
            element = shape as ShapeElement;
            if (element.Data == null)
            {
                return;
            }
            element.Data = element.Data.GetFragmentByIndexes(element.RowIndexes, element.ColumnIndexes);
            element.ProcessCommands(element.Data);

            var  visibleCmds = element.CommandsOf <VisibleCommand>();
            bool isVisible   = visibleCmds.Count == 0;

            foreach (var vis in visibleCmds)
            {
                isVisible |= vis.IsVisible;
            }

            if (isVisible)
            {
                if (!element.IsContentProtected)
                {
                    var    avaiableColumns = element.ColumnIndexes.Where(i => !i.IsHidden && element.Data.HasColumn(i));
                    var    avaiableRows    = element.RowIndexes.Where(i => !i.IsHidden && element.Data.HasRow(i));
                    Index  firstColumn     = avaiableColumns.Count() > 0 ? avaiableColumns.First() : new Index(0);
                    Index  firstRow        = avaiableRows.Count() > 0 ? avaiableRows.First() : new Index(0);
                    object data            = element.Data.Data(firstRow, firstColumn);
                    if (data != null)
                    {
                        element.Element.Replace(data.ToString());
                    }
                }

                ShapeElement legend = element.Data.Rows[0].Legends[0] as ShapeElement;
                if (legend != null)
                {
                    A.SolidFill fill    = legend.Element.GetFill();
                    A.Outline   outline = legend.Element.GetOutline();
                    element.Element.ShapeProperties.ReplaceChild <A.SolidFill>(fill.CloneNode(true), element.Element.ShapeProperties.FirstElement <A.SolidFill>());
                    element.Element.ShapeProperties.ReplaceChild <A.Outline>(outline.CloneNode(true), element.Element.ShapeProperties.FirstElement <A.Outline>());
                }
            }
            else
            {
                element.Element.Remove();
            }
        }
Exemple #3
0
        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++;
            }
        }