Beispiel #1
0
        public void  ChangeLastNameForSecondRow(string pFileName, string pTextValue)
        {
            var fileName = Path.Combine(DocumentFolder, pFileName);

            if (!File.Exists(fileName))
            {
                CreateDocumentWithTableFromArray(fileName);
            }

            // Open our document, second parameter indicates edit more
            using (var document = WordprocessingDocument.Open(fileName, true))
            {
                // Get the sole table in the document
                Table table = document.MainDocumentPart.Document.Body.Elements <Table>().First();

                // Find the second row in the table.
                TableRow row = table.Elements <TableRow>().ElementAt(1);

                // Find the second cell in the row.
                TableCell cell = row.Elements <TableCell>().ElementAt(1);

                // Find the first paragraph in the table cell.
                Paragraph p = cell.Elements <Paragraph>().First();

                // Find the first run in the paragraph.
                Run run = p.Elements <Run>().First();

                // Set the text for the run.
                Text text = run.Elements <Text>().First();
                text.Text = pTextValue;

                document.Save();
            }
        }
Beispiel #2
0
        //:::::WORD DOCUMENT PROCESSING PART:::::
        public static void AddToTable(String fileName, String tableName, int elemNo, String txt, int elemRow = 0)
        {
            List <WordP.Table> tables = null;

            using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(fileName, true))
            {
                tables = new List <WordP.Table>(wordDoc.MainDocumentPart.Document.Body.Elements <WordP.Table>());
                tables.ForEach(table =>
                {
                    WordP.TableProperties tblProperties = table.GetFirstChild <WordP.TableProperties>();
                    if (tblProperties != null)
                    {
                        WordP.TableCaption caption = tblProperties.GetFirstChild <WordP.TableCaption>();
                        if (caption != null)
                        {
                            if (caption.Val.HasValue && caption.Val.Value.Equals(tableName))
                            {
                                WordP.TableRow row = table.Elements <WordP.TableRow>().ElementAt(elemNo);

                                // Find the third cell in the row.
                                WordP.TableCell cell = row.Elements <WordP.TableCell>().ElementAt(elemRow);

                                // Find the first paragraph in the table cell.
                                WordP.Paragraph p = cell.Elements <WordP.Paragraph>().First();

                                // Find the first run in the paragraph.
                                WordP.Run r = p.Elements <WordP.Run>().First();

                                // Set the text for the run.
                                WordP.Text t = r.Elements <WordP.Text>().First();
                                t.Text       = txt;

                                // you have got your table. process the rest.
                            }
                        }
                    }
                });
            }
        }
        private void setupHABehaveTableTemplate()
        {
            String templateDoc = _projecto.Template_Mnemonica;

            String filename = rootPath + "docTemplates\\" + templateDoc + "_BEHAVE_HA.docx";

            using (WordprocessingDocument tempDoc = WordprocessingDocument.Open(filename, true))
            {

                tempTable = (wp.Table)tempDoc.MainDocumentPart.Document.Body.Elements<wp.Table>().ElementAt(0).Clone();

                tempRowHeader = (wp.TableRow)tempTable.Elements<wp.TableRow>().ElementAt(0).Clone();
                tempRowHeader2 = (wp.TableRow)tempTable.Elements<wp.TableRow>().ElementAt(1).Clone();
                tempRowImpar = (wp.TableRow)tempTable.Elements<wp.TableRow>().ElementAt(2).Clone();
                tempRowPar = (wp.TableRow)tempTable.Elements<wp.TableRow>().ElementAt(3).Clone();

                symbUp = tempRowImpar.Elements<wp.TableCell>().ElementAt(1).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Elements<wp.SymbolChar>().First() as wp.SymbolChar;
                symbH = tempRowPar.Elements<wp.TableCell>().ElementAt(1).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Elements<wp.SymbolChar>().First() as wp.SymbolChar;
                symbDw = tempTable.Elements<wp.TableRow>().ElementAt(4).Elements<wp.TableCell>().ElementAt(1).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Elements<wp.SymbolChar>().First() as wp.SymbolChar;

                tempTable.Elements<wp.TableRow>().ElementAt(0).Remove();
                tempTable.Elements<wp.TableRow>().ElementAt(0).Remove();
                tempTable.Elements<wp.TableRow>().ElementAt(0).Remove();
                tempTable.Elements<wp.TableRow>().ElementAt(0).Remove();
                tempTable.Elements<wp.TableRow>().ElementAt(0).Remove();

                tempParagraph = tempDoc.MainDocumentPart.Document.Body.Descendants<wp.Paragraph>().ElementAt(0).Clone() as wp.Paragraph;

            }
        }
        private void setupHAAADerailersTableTemplate()
        {
            String templateDoc = _projecto.Template_Mnemonica;

            String filename = rootPath + "docTemplates\\" + templateDoc + "_DERAILER_HAAA.docx";

            using (WordprocessingDocument tempDoc = WordprocessingDocument.Open(filename, true))
            {

                tempTable = (wp.Table)tempDoc.MainDocumentPart.Document.Body.Elements<wp.Table>().ElementAt(0).Clone();

                // selecciona as linhas
                tempRowHeader = (wp.TableRow)tempTable.Elements<wp.TableRow>().ElementAt(0).Clone();
                tempRowSeparador = (wp.TableRow)tempTable.Elements<wp.TableRow>().ElementAt(1).Clone();
                tempRowHeader2 = (wp.TableRow)tempTable.Elements<wp.TableRow>().ElementAt(2).Clone();
                tempRowImpar = (wp.TableRow)tempTable.Elements<wp.TableRow>().ElementAt(3).Clone();
                tempRowPar = (wp.TableRow)tempTable.Elements<wp.TableRow>().ElementAt(4).Clone();

                // selecciona os símbolos
                // Target
                // Neutro
                // A Desenvolver
                // linhas 3,4 e 5 Coluna 1

                symbDelevop = tempRowImpar.Elements<wp.TableCell>().ElementAt(3).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Elements<wp.SymbolChar>().First() as wp.SymbolChar;
                tempRowImpar.Elements<wp.TableCell>().ElementAt(3).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Elements<wp.SymbolChar>().First().Remove();
                symbNeutral = tempRowPar.Elements<wp.TableCell>().ElementAt(3).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Elements<wp.SymbolChar>().First() as wp.SymbolChar;
                tempRowPar.Elements<wp.TableCell>().ElementAt(3).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Elements<wp.SymbolChar>().First().Remove();

                symbTarget = tempTable.Elements<wp.TableRow>().ElementAt(5).Elements<wp.TableCell>().ElementAt(3).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Elements<wp.SymbolChar>().First() as wp.SymbolChar;
                tempTable.Elements<wp.TableRow>().ElementAt(5).Elements<wp.TableCell>().ElementAt(3).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Elements<wp.SymbolChar>().First().Remove();

                // limpa a tabela
                tempTable.Elements<wp.TableRow>().ElementAt(0).Remove();
                tempTable.Elements<wp.TableRow>().ElementAt(0).Remove();
                tempTable.Elements<wp.TableRow>().ElementAt(0).Remove();
                tempTable.Elements<wp.TableRow>().ElementAt(0).Remove();
                tempTable.Elements<wp.TableRow>().ElementAt(0).Remove();
                tempTable.Elements<wp.TableRow>().ElementAt(0).Remove();

                tempParagraph = tempDoc.MainDocumentPart.Document.Body.Descendants<wp.Paragraph>().ElementAt(0).Clone() as wp.Paragraph;

            }
        }
        private void setupGapTables()
        {
            gapTables = true;
            String templateDoc = _projecto.Template_Mnemonica;

            String filename = rootPath + "docTemplates\\" + templateDoc + "_GAP.docx";

            // são esperados tantas tabelas quantos grupos + 1
            tablesRank = new wp.Table[_projecto.GroupsCodes.Length]; // não é preciso o +1 porque o self está presente em todas a do self é substituida por todos
            parsHeading = new wp.Paragraph[_projecto.GroupsCodes.Length];
            using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(filename, true))
            {
                for (int i = 0; i < tablesRank.Length; i++)
                {
                    tablesRank[i] = (wp.Table)wordDoc.MainDocumentPart.Document.Body.Elements<wp.Table>().ElementAt(i).Clone();
                }

                trRankRowImpar = (wp.TableRow)tablesRank[0].Elements<wp.TableRow>().ElementAt(1);
                trRankRowPar = (wp.TableRow)tablesRank[0].Elements<wp.TableRow>().ElementAt(2);
                trRankRowImpar2 = (wp.TableRow)tablesRank[0].Elements<wp.TableRow>().ElementAt(3);

                // apanha simbolos de mais médio e menos
                UpSign = (wp.Run)trRankRowImpar.Elements<wp.TableCell>().ElementAt(3).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Clone();
                EqSign = (wp.Run)trRankRowPar.Elements<wp.TableCell>().ElementAt(3).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Clone();
                LessSign = (wp.Run)trRankRowImpar2.Elements<wp.TableCell>().ElementAt(3).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Clone();

                // eliminar o mais e o menos das linhas
                trRankRowImpar.Elements<wp.TableCell>().ElementAt(3).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Remove();
                trRankRowPar.Elements<wp.TableCell>().ElementAt(3).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Remove();
                trRankRowImpar2.Elements<wp.TableCell>().ElementAt(3).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Remove();

                // remoe as três linhas da primeira tabela
                tablesRank[0].Elements<wp.TableRow>().ElementAt(1).Remove();
                tablesRank[0].Elements<wp.TableRow>().ElementAt(1).Remove();
                tablesRank[0].Elements<wp.TableRow>().ElementAt(1).Remove();

                // agarra os parágrafos dos headins de cada tabela

                for (int i = 0; i < tablesRank.Length; i++)
                {
                    parsHeading[i] = (wp.Paragraph)wordDoc.MainDocumentPart.Document.Body.Elements<wp.Paragraph>().ElementAt(i);
                }
            }
        }
        public static void Fill(OpenXmlElement docNode, XmlElement macroListXml, WordprocessingDocument wdDoc)
        {
            /* Форматированный текст для встроенных элементов */
            IEnumerable <Paragraph> paragraphs = docNode.Elements <Paragraph>();

            foreach (Paragraph paragraph in paragraphs)
            {
                IEnumerable <SdtRun> sdtRuns = paragraph.Elements <SdtRun>();
                foreach (SdtRun sdtRun in sdtRuns)
                {
                    // Из SdtProperties взять Tag для идентификации Content Control
                    SdtProperties sdtProperties = sdtRun.GetFirstChild <SdtProperties>();
                    Tag           tag           = sdtProperties.GetFirstChild <Tag>();

                    // Найти в macroListXml Node макропеременной
                    String macroVarValue = FindMacroVar(macroListXml, tag.Val);

                    if (macroVarValue != null)
                    {
                        // Сохранить старый стиль Run
                        SdtContentRun  sdtContentRun = sdtRun.GetFirstChild <SdtContentRun>();
                        OpenXmlElement oldRunProps   = sdtContentRun.GetFirstChild <Run>().GetFirstChild <RunProperties>().CloneNode(true);

                        // Очистить Node Content Control
                        sdtContentRun.RemoveAllChildren();

                        // Создать новую Run Node
                        Run newRun = sdtContentRun.AppendChild(new Run());
                        // Вернуть старый стиль
                        newRun.AppendChild(oldRunProps);

                        // Вставить текст (без переносов строк!!!)
                        newRun.AppendChild(new Text(macroVarValue));
                    }
                }
            }

            /* Получить остальные Content Control */
            IEnumerable <SdtBlock> sdtBlocks = docNode.Elements <SdtBlock>();

            foreach (SdtBlock sdtBlock in sdtBlocks)
            {
                // Получить параметры(SdtProperties) Content Control
                SdtProperties sdtProperties = sdtBlock.GetFirstChild <SdtProperties>();

                // Получить Tag для идентификации Content Control
                Tag tag = sdtProperties.GetFirstChild <Tag>();

                // Получить значение макроперенной из macroListXml
                Console.WriteLine("Tag: " + tag.Val);
                String macroVarValue = FindMacroVar(macroListXml, tag.Val);

                // Если макропеременная есть в MacroListXml
                if (macroVarValue != null)
                {
                    Console.WriteLine("Value: " + macroVarValue);
                    // Получить блок содержимого Content Control
                    SdtContentBlock sdtContentBlock = sdtBlock.GetFirstChild <SdtContentBlock>();

                    /* Форматированный текст для абзацев */
                    if (sdtProperties.GetFirstChild <SdtPlaceholder>() != null && sdtContentBlock.GetFirstChild <Paragraph>() != null)
                    {
                        // Сохранить старый стиль параграфа
                        ParagraphProperties oldParagraphProperties = sdtContentBlock.GetFirstChild <Paragraph>().GetFirstChild <ParagraphProperties>().CloneNode(true) as ParagraphProperties;
                        String oldParagraphPropertiesXml           = oldParagraphProperties.InnerXml;

                        // Очистить ноду с контентом
                        sdtContentBlock.RemoveAllChildren();

                        InsertText(macroVarValue, oldParagraphPropertiesXml, sdtContentBlock);
                    }

                    /* Таблицы */
                    if (sdtProperties.GetFirstChild <SdtPlaceholder>() != null && sdtContentBlock.GetFirstChild <Table>() != null)
                    {
                        // Получить ноду таблицы
                        Table table = sdtContentBlock.GetFirstChild <Table>();

                        // Получить все строки таблицы
                        IEnumerable <TableRow> tableRows = table.Elements <TableRow>();

                        // Получить вторую строку из таблицы
                        TableRow tableRow     = tableRows.ElementAt(1) as TableRow;
                        Type     tableRowType = tableRow.GetType();

                        // Получить все стили столбцов
                        List <String> paragraphCellStyles       = new List <string>();
                        IEnumerable <OpenXmlElement> tableCells = tableRow.Elements <TableCell>();
                        foreach (OpenXmlElement tableCell in tableCells)
                        {
                            String paragraphCellStyleXml = tableCell.GetFirstChild <Paragraph>().GetFirstChild <ParagraphProperties>().InnerXml;
                            paragraphCellStyles.Add(paragraphCellStyleXml);
                        }

                        // Удалить все строки, после первой
                        while (tableRows.Count <TableRow>() > 1)
                        {
                            TableRow lastTableRows = tableRows.Last <TableRow>();
                            lastTableRows.Remove();
                        }

                        // Удалить последний элемент, если это не TableRow
                        OpenXmlElement lastNode = table.LastChild;
                        if (lastNode.GetType() != tableRowType)
                        {
                            lastNode.Remove();
                        }

                        string[] rowDelimiters    = new string[] { "|||" };
                        string[] columnDelimiters = new string[] { "^^^" };

                        // Получить массив строк из макропеременной
                        String[] rowsXml = macroVarValue.Split(rowDelimiters, StringSplitOptions.None);
                        int      i       = 0;
                        while (i < rowsXml.Length)
                        {
                            // Получить строку
                            String rowXml = rowsXml[i];

                            // Добавить ноду строки таблицы
                            TableRow newTableRow = table.AppendChild(new TableRow());

                            // Получить из строки массив ячеек
                            String[] cellsXml = rowXml.Split(columnDelimiters, StringSplitOptions.None);

                            int j = 0;
                            while (j < cellsXml.Length)
                            {
                                // Получить ячейку
                                String cellXml = cellsXml[j];

                                // Убрать символ CRLF в конце строки
                                cellXml = cellXml.TrimEnd(new char[] { '\n', '\r' });

                                // Добавить ноду ячейку в строку таблицы
                                TableCell newTableCell = newTableRow.AppendChild(new TableCell());

                                // Вставить текст
                                InsertText(cellXml, paragraphCellStyles[j], newTableCell);

                                j++;
                            }

                            i++;
                        }
                    }

                    /* Картинки */
                    if (sdtProperties.GetFirstChild <SdtContentPicture>() != null)
                    {
                        // Получить путь к файлу
                        String imageFilePath = macroVarValue;

                        // Получить расширение файла
                        String        extension = System.IO.Path.GetExtension(imageFilePath).ToLower();
                        ImagePartType imagePartType;
                        switch (extension)
                        {
                        case "jpeg":
                            imagePartType = ImagePartType.Jpeg;
                            break;

                        case "jpg":
                            imagePartType = ImagePartType.Jpeg;
                            break;

                        case "png":
                            imagePartType = ImagePartType.Png;
                            break;

                        case "bmp":
                            imagePartType = ImagePartType.Bmp;
                            break;

                        case "gif":
                            imagePartType = ImagePartType.Gif;
                            break;

                        default:
                            imagePartType = ImagePartType.Jpeg;
                            break;
                        }
                        ;

                        // Добавить ImagePart в документ
                        ImagePart imagePart = wdDoc.MainDocumentPart.AddImagePart(imagePartType);

                        // Получить картинку
                        using (FileStream stream = new FileStream(imageFilePath, FileMode.Open))
                        {
                            imagePart.FeedData(stream);
                        }

                        // Вычислить width и height
                        Bitmap    img         = new Bitmap(imageFilePath);
                        var       widthPx     = img.Width;
                        var       heightPx    = img.Height;
                        var       horzRezDpi  = img.HorizontalResolution;
                        var       vertRezDpi  = img.VerticalResolution;
                        const int emusPerInch = 914400;
                        const int emusPerCm   = 360000;
                        var       widthEmus   = (long)(widthPx / horzRezDpi * emusPerInch);
                        var       heightEmus  = (long)(heightPx / vertRezDpi * emusPerInch);

                        // Получить ID ImagePart
                        string relationShipId = wdDoc.MainDocumentPart.GetIdOfPart(imagePart);

                        Paragraph   paragraph   = sdtContentBlock.GetFirstChild <Paragraph>();
                        Run         run         = paragraph.GetFirstChild <Run>();
                        Drawing     drawing     = run.GetFirstChild <Drawing>();
                        Inline      inline      = drawing.GetFirstChild <Inline>();
                        Graphic     graphic     = inline.GetFirstChild <Graphic>();
                        GraphicData graphicData = graphic.GetFirstChild <GraphicData>();
                        Picture     pic         = graphicData.GetFirstChild <Picture>();
                        BlipFill    blipFill    = pic.GetFirstChild <BlipFill>();
                        Blip        blip        = blipFill.GetFirstChild <Blip>();

                        string prefix       = "r";
                        string localName    = "embed";
                        string namespaceUri = @"http://schemas.openxmlformats.org/officeDocument/2006/relationships";

                        OpenXmlAttribute oldEmbedAttribute = blip.GetAttribute("embed", namespaceUri);

                        IList <OpenXmlAttribute> attributes = blip.GetAttributes();

                        if (oldEmbedAttribute != null)
                        {
                            attributes.Remove(oldEmbedAttribute);
                        }

                        // Удалить хз что, выявлено практическим путем
                        blipFill.RemoveAllChildren <SourceRectangle>();

                        // Установить новую картинку
                        blip.SetAttribute(new OpenXmlAttribute(prefix, localName, namespaceUri, relationShipId));
                        blip.SetAttribute(new OpenXmlAttribute("cstate", "", "print"));

                        // Подогнать размеры
                        Extent extent = inline.GetFirstChild <Extent>();

                        OpenXmlAttribute oldCxExtent = extent.GetAttribute("cx", "");
                        if (oldCxExtent != null)
                        {
                            var maxWidthEmus = long.Parse(oldCxExtent.Value);
                            if (widthEmus > maxWidthEmus)
                            {
                                var ratio = (heightEmus * 1.0m) / widthEmus;
                                widthEmus  = maxWidthEmus;
                                heightEmus = (long)(widthEmus * ratio);
                            }

                            extent.GetAttributes().Remove(oldCxExtent);
                        }

                        OpenXmlAttribute oldCyExtent = extent.GetAttribute("cy", "");
                        if (oldCyExtent != null)
                        {
                            extent.GetAttributes().Remove(oldCyExtent);
                        }

                        extent.SetAttribute(new OpenXmlAttribute("cx", "", widthEmus.ToString()));
                        extent.SetAttribute(new OpenXmlAttribute("cy", "", heightEmus.ToString()));

                        ShapeProperties shapeProperties = pic.GetFirstChild <ShapeProperties>();
                        Transform2D     transform2D     = shapeProperties.GetFirstChild <Transform2D>();
                        Extents         extents         = transform2D.GetFirstChild <Extents>();

                        OpenXmlAttribute oldCxExtents = extents.GetAttribute("cx", "");
                        if (oldCxExtents != null)
                        {
                            extents.GetAttributes().Remove(oldCxExtents);
                        }

                        OpenXmlAttribute oldCyExtents = extents.GetAttribute("cy", "");
                        if (oldCyExtents != null)
                        {
                            extents.GetAttributes().Remove(oldCyExtents);
                        }

                        extents.SetAttribute(new OpenXmlAttribute("cx", "", widthEmus.ToString()));
                        extents.SetAttribute(new OpenXmlAttribute("cy", "", heightEmus.ToString()));

                        // Удалить placeholder
                        ShowingPlaceholder showingPlaceholder = sdtProperties.GetFirstChild <ShowingPlaceholder>();
                        if (showingPlaceholder != null)
                        {
                            sdtProperties.RemoveChild <ShowingPlaceholder>(showingPlaceholder);
                        }
                    }

                    /* Повторяющийся раздел */
                    if (sdtProperties.GetFirstChild <SdtRepeatedSection>() != null)
                    {
                        // Представить repeatedSection как новый xml документ (сделать корнем)
                        XmlDocument repeatedSectionXml = new XmlDocument();
                        repeatedSectionXml.LoadXml(macroVarValue);

                        // Получить корневой элемент repeatedSection
                        XmlElement rootRepeatedSectionXml = repeatedSectionXml.DocumentElement;

                        // Получить количество repeatedSectionItem
                        XmlNodeList repeatedSectionItems = rootRepeatedSectionXml.SelectNodes("repeatedSectionItem");
                        int         repeatedItemCount    = repeatedSectionItems.Count;

                        Console.WriteLine("Количество repeatedSectionItem: " + repeatedItemCount);

                        /* Блок клонирования ноды повтор. раздела до нужного количества */
                        for (int i = 0; i < repeatedItemCount; i++)
                        {
                            XmlElement macroListRepeatedSectionItem = rootRepeatedSectionXml.SelectSingleNode(String.Format(@"repeatedSectionItem[@id=""{0}""]", i)) as XmlElement;
                            Console.WriteLine("Item " + i + ": " + macroListRepeatedSectionItem.OuterXml);

                            SdtContentBlock sdtContentBlockRepeatedSectionItem = sdtContentBlock.Elements <SdtBlock>().Last <SdtBlock>().GetFirstChild <SdtContentBlock>();

                            Fill(sdtContentBlockRepeatedSectionItem, macroListRepeatedSectionItem, wdDoc);

                            if (i + 1 < repeatedItemCount)
                            {
                                SdtBlock clonedRepeatedSectionItem = sdtContentBlock.GetFirstChild <SdtBlock>().Clone() as SdtBlock;
                                sdtContentBlock.AppendChild <SdtBlock>(clonedRepeatedSectionItem);
                            }
                        }
                        /**/

                        //Fill(sdtContentBlock, macroListRepeatedSection, wdDoc);
                    }
                }

                Console.WriteLine();
            }
        }
Beispiel #7
0
    private void setupGapTables()
    {
        gapTables = true;
        String templateDoc = _projecto.Template_Mnemonica;

        String filename = templatePath + "\\" + templateDoc + "_GAP.docx";
        String[] tempShadingKey = {"T","G1","G2","G3","G4"};

        using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(filename, true))
        {

            tableRankT = (wp.Table)wordDoc.MainDocumentPart.Document.Body.Elements<wp.Table>().ElementAt(0).Clone();
            tableRankB = (wp.Table)wordDoc.MainDocumentPart.Document.Body.Elements<wp.Table>().ElementAt(1).Clone();
            tableRankC = (wp.Table)wordDoc.MainDocumentPart.Document.Body.Elements<wp.Table>().ElementAt(2).Clone();
            tableRankP = (wp.Table)wordDoc.MainDocumentPart.Document.Body.Elements<wp.Table>().ElementAt(3).Clone();
            tableRankO = (wp.Table)wordDoc.MainDocumentPart.Document.Body.Elements<wp.Table>().ElementAt(4).Clone();

            wp.Shading shading = (wp.Shading)tableRankT.Elements<wp.TableRow>().First().Elements<wp.TableCell>().First().Elements<wp.TableCellProperties>().First().Elements<wp.Shading>().First();
            GroupShading.Add(tempShadingKey[0], shading.Fill);
            shading = (wp.Shading)tableRankB.Elements<wp.TableRow>().First().Elements<wp.TableCell>().First().Elements<wp.TableCellProperties>().First().Elements<wp.Shading>().First();
            GroupShading.Add(tempShadingKey[1], shading.Fill);
            shading = (wp.Shading)tableRankC.Elements<wp.TableRow>().First().Elements<wp.TableCell>().First().Elements<wp.TableCellProperties>().First().Elements<wp.Shading>().First();
            GroupShading.Add(tempShadingKey[2], shading.Fill);
            shading = (wp.Shading)tableRankP.Elements<wp.TableRow>().First().Elements<wp.TableCell>().First().Elements<wp.TableCellProperties>().First().Elements<wp.Shading>().First();
            GroupShading.Add(tempShadingKey[3], shading.Fill);
            shading = (wp.Shading)tableRankO.Elements<wp.TableRow>().First().Elements<wp.TableCell>().First().Elements<wp.TableCellProperties>().First().Elements<wp.Shading>().First();
            GroupShading.Add(tempShadingKey[4], shading.Fill);

            trRankRowImpar = (wp.TableRow)tableRankT.Elements<wp.TableRow>().ElementAt(1);
            trRankRowPar = (wp.TableRow)tableRankT.Elements<wp.TableRow>().ElementAt(2);

            symbUp = trRankRowImpar.Elements<wp.TableCell>().ElementAt(3).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Elements<wp.SymbolChar>().First() as wp.SymbolChar;
            symbH = trRankRowPar.Elements<wp.TableCell>().ElementAt(3).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Elements<wp.SymbolChar>().First() as wp.SymbolChar;
            symbDw = tableRankT.Elements<wp.TableRow>().ElementAt(3).Elements<wp.TableCell>().ElementAt(3).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Elements<wp.SymbolChar>().First() as wp.SymbolChar;

            symbUpRun = trRankRowImpar.Elements<wp.TableCell>().ElementAt(3).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Clone() as wp.Run;
            symbHRun = trRankRowPar.Elements<wp.TableCell>().ElementAt(3).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Clone() as wp.Run;
            symbDwRun = tableRankT.Elements<wp.TableRow>().ElementAt(3).Elements<wp.TableCell>().ElementAt(3).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Clone() as wp.Run;

            tableRankT.Elements<wp.TableRow>().ElementAt(1).Remove();
            tableRankT.Elements<wp.TableRow>().ElementAt(1).Remove();
            tableRankT.Elements<wp.TableRow>().ElementAt(1).Remove();

            trRankRowImpar.Elements<wp.TableCell>().ElementAt(3).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Remove();
            trRankRowPar.Elements<wp.TableCell>().ElementAt(3).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Remove();

            parHeadingParT = (wp.Paragraph)wordDoc.MainDocumentPart.Document.Body.Elements<wp.Paragraph>().ElementAt(0);
            parHeadingParB = (wp.Paragraph)wordDoc.MainDocumentPart.Document.Body.Elements<wp.Paragraph>().ElementAt(1);
            parHeadingParC = (wp.Paragraph)wordDoc.MainDocumentPart.Document.Body.Elements<wp.Paragraph>().ElementAt(2);
            parHeadingParP = (wp.Paragraph)wordDoc.MainDocumentPart.Document.Body.Elements<wp.Paragraph>().ElementAt(3);
            parHeadingParO = (wp.Paragraph)wordDoc.MainDocumentPart.Document.Body.Elements<wp.Paragraph>().ElementAt(4);

        }
    }