コード例 #1
0
        public void copyTableData(List <int> oldTablesNumbers, int newTableNumber, ref Dictionary <string, string> dict, ref Dictionary <string, string> constantsDict, ref Word.Document newDoc)
        {
            string oldFilePath = constantsDict["Reading Old Documents Path"] + "\\INT-002-002-" + dict["OldServiceID"] + "-DTD " + dict["OldServiceSubject"] + ".docx";

            Console.WriteLine(oldFilePath);
            Word.Document oldDoc          = wordApp.Documents.Open(oldFilePath);
            Word.Table    newRequestTable = newDoc.Tables[newTableNumber];
            int           index           = 2;

            foreach (int k in oldTablesNumbers)
            {
                Console.WriteLine("Reading old Table Number " + k);
                Word.Table oldRequestTable = oldDoc.Tables[k];
                Word.Rows  oldRequestRows  = oldRequestTable.Rows;
                for (int i = 3; i <= oldRequestRows.Count - 1; i++)
                {
                    newRequestTable.Rows.Add(newRequestTable.Rows[index]);
                    Word.Row oldRow = oldRequestRows[i];
                    for (int j = 1; j <= oldRow.Cells.Count; j++)
                    {
                        Word.Cell cell1 = newRequestTable.Cell(index, j);
                        //Console.WriteLine(i + " " + j + " " + oldRequestTable.Cell(i, j).Range.Text);
                        cell1.Range.Text = oldRequestTable.Cell(i, j).Range.Text;
                    }
                    index++;
                }
            }
            newRequestTable.Rows[index].Delete();
            oldDoc.Close();
        }
コード例 #2
0
        public void SetTableHeadingRows(long CountHeadingRows, int indTable = -1)
        {
            GetTableReference(indTable);

            MSWord.Rows pRows = m_pTable.Rows;
            if (pRows == null)
            {
                return;
            }

            for (int i = 0; i < CountHeadingRows; i++)
            {
                pRows[i + 1].HeadingFormat = -1;
            }
        }
コード例 #3
0
        public void ConvertToTable(string strText, int row_cnt = -1, int col_cnt = -1, bool bSetBorders = true, string bookmark = "")
        {
            string strReturn  = "" + (char)10;
            bool   bUseReturn = false;

            if (strText.IndexOf(strReturn) >= 0)
            {
                bUseReturn = true;
            }

            strText = strText.Replace(strReturn, "#enter#");

            if (bookmark == "")
            {
                if (m_pDoc == null)
                {
                    m_pDoc = m_pApp.ActiveDocument;
                }
                if (m_pDoc == null)
                {
                    return;
                }

                m_pDoc.Select();
                m_pSelection = m_pApp.Selection;
                if (m_pSelection == null)
                {
                    return;
                }

                m_pSelection.Collapse(0);

                object varInfo = m_pSelection.get_Information(MSWord.WdInformation.wdWithInTable);
                if (Convert.ToBoolean(varInfo) == true)
                {
                    m_pDoc.Select();
                    m_pSelection = m_pApp.Selection;
                    if (m_pSelection == null)
                    {
                        return;
                    }
                    m_pSelection.Collapse(0);
                }
            }
            else
            {
                m_pSelection.GoTo(-1, Type.Missing, Type.Missing, bookmark);
            };

            m_pSelection.Font.Bold = 0;
            m_pSelection.Text      = strText;

            m_pSelection.Paragraphs.SpaceAfter      = 0;
            m_pSelection.Paragraphs.SpaceBefore     = 0;
            m_pSelection.Paragraphs.LineSpacingRule = MSWord.WdLineSpacing.wdLineSpaceSingle;


            if (row_cnt < 0 && col_cnt < 0)
            {
                m_pTable = m_pSelection.ConvertToTable(1, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                                       Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                                       Type.Missing, 0, 0);
            }
            else
            {
                m_pTable = m_pSelection.ConvertToTable(1, row_cnt, col_cnt, 0, 0,
                                                       Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                                       Type.Missing, 0, 0);
            }

            // выравниваем талицу (не содержимое!!!)
            if (m_pTable == null)
            {
                return;
            }

            MSWord.Rows pRows = m_pSelection.Rows;
            pRows.AllowBreakAcrossPages = 0;

            m_pSelection.Collapse(0);

            MSWord.Borders pBorders = m_pTable.Borders;
            if (pBorders == null)
            {
                return;
            }
            if (bSetBorders)
            {
                pBorders.Enable = 1;
            }
            else
            {
                pBorders.Enable = 0;
            }

            if (bUseReturn)
            {
                m_pTable.Select();
                MSWord.Selection sel = m_pApp.Selection;

                MSWord.Find find = sel.Find;
                find.ClearFormatting();
                MSWord.Replacement replace = find.Replacement;
                replace.ClearFormatting();
                find.Text              = "#enter#";
                replace.Text           = "^p";
                find.MatchCase         = false;
                find.MatchWholeWord    = false;
                find.MatchWildcards    = false;
                find.MatchSoundsLike   = false;
                find.MatchAllWordForms = false;
                find.Wrap              = MSWord.WdFindWrap.wdFindContinue;
                MSWord.WdReplace repl = MSWord.WdReplace.wdReplaceAll;
                find.Execute(find.Text, find.MatchCase, find.MatchWholeWord, find.MatchWildcards,
                             find.MatchSoundsLike, find.MatchAllWordForms, Type.Missing, find.Wrap, Type.Missing, replace.Text, repl);
            }
        }