Exemple #1
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++;
            }
        }