Пример #1
0
        /// <summary>
        /// 设置某单元格内的数据
        /// </summary>
        /// <param name="cell">要读取的Cell</param>
        /// <param name="val">值</param>
        /// <returns>单元格内的数据</returns>
        private void SetCellValue(Microsoft.Office.Interop.Word.Cell cell, string val)
        {
            object cellstart = cell.Range.Start;
            object cellend   = cell.Range.End;

            this.m_wddoc.Range(ref cellstart, ref cellend).Text = val;
        }
Пример #2
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();
        }
Пример #3
0
        /// <summary>
        /// 检查单元格是否行合并过且横跨多个页面
        /// </summary>
        internal static bool IsCellMultiPagesMerged(Word.Table table, Word.Cell cell)
        {
            // 判断是否合并过?
            var cellRowSpan = GetCellRowSpan(table, cell);

            if (cellRowSpan <= 1)
            {
                return(false);
            }
            var isMultiPagesMerged = false;
            var cellPageNum        = GetCellPageNum(cell);

            // 拆分,为了解析方便
            cell.Split(NumRows: cellRowSpan);
            // 查找每个基本单元格的页码
            for (var curRowIndex = cell.RowIndex + 1; curRowIndex < cell.RowIndex + cellRowSpan; curRowIndex++)
            {
                var curCell        = table.Cell(curRowIndex, cell.ColumnIndex);
                var curCellPageNum = GetCellPageNum(curCell);
                if (curCellPageNum > cellPageNum)   // 找到某个基本单元格在另外一页
                {
                    isMultiPagesMerged = true;
                }
                // 重新合并
                cell.Merge(curCell);
            }

            return(isMultiPagesMerged);
        }
Пример #4
0
 private static void ApplyContentsStyle(WordNet.Cell cell, WordNet.WdCellVerticalAlignment verticalAlignment = WordNet.WdCellVerticalAlignment.wdCellAlignVerticalCenter)
 {
     cell.VerticalAlignment = verticalAlignment;
     cell.Range.Font.Name   = "Arial";
     cell.Range.Font.Size   = 8;
     cell.Range.Font.Bold   = 0;
 }
Пример #5
0
        /** Checks if the acronyms in the table appear in the rest of the document. **/
        private void CheckAcronymsInTable()
        {
            frm.SetMainText("Checking acronyms in the table.");

            int numRows     = acronymTable.Rows.Count;
            int currentItem = 0;

            for (int i = 2; i <= numRows; i++)
            {
                SetNumber(currentItem++, numRows);

                Word.Cell leftCell  = acronymTable.Cell(i, 1);
                Word.Cell rightCell = acronymTable.Cell(i, 2);

                String acronym = leftCell.Range.Text;
                acronym = acronym.Remove(acronym.Length - 2);
                SearchForEntry(leftCell, acronym);

                String definition = rightCell.Range.Text;
                definition = definition.Remove(definition.Length - 2);
                SearchForEntry(rightCell, definition);

                inTable.Add(acronym.Trim());
            }
        }
Пример #6
0
        /// <summary>
        /// 获取单元格真实占据列数量(对于合并单元格这个值大于1)
        /// </summary>
        internal static int GetCellColumnSpan(Word.Table table, Word.Cell cell)
        {
            var lastColIndex = table.Columns.Count;
            var colCount     = 0;
            var cellCount    = 0;

            for (var colIndex = cell.ColumnIndex; colIndex <= lastColIndex; colIndex++)
            {
                try {
                    var refCell = table.Cell(cell.RowIndex, colIndex);
                    // 坐标正常流程才能往下
                    if (cellCount < 1)   // 第一次获取成功代表自身
                    {
                        colCount++;
                        cellCount++;
                    }
                    else     // 第二次合并成功代表下一个有效单元格,结束
                    {
                        break;
                    }
                } catch (COMException) { // 获取失败,说明合并过
                    colCount++;
                }
            }
            return(colCount);
        }
Пример #7
0
        public void SetCellsColor(int iCol1, int iCol2, int iRow1, int iRow2, MSWord.WdColor color, MSWord.WdColor text_color = MSWord.WdColor.wdColorAutomatic, int indTable = -1)
        {
            GetTableReference(indTable);

            MSWord.Cell pCell1 = m_pTable.Cell(iRow1, iCol1);
            if (pCell1 == null)
            {
                return;
            }
            MSWord.Cell pCell2 = m_pTable.Cell(iRow2, iCol2);
            if (pCell2 == null)
            {
                return;
            }

            MSWord.Range r = m_pDoc.Range(pCell1.Range.Start, pCell2.Range.End);
            r.Select();
            MSWord.Selection sel = m_pApp.Selection;
            sel.Shading.Texture = MSWord.WdTextureIndex.wdTextureNone;
            sel.Shading.ForegroundPatternColor = MSWord.WdColor.wdColorAutomatic;
            sel.Shading.BackgroundPatternColor = color;
            if (text_color != MSWord.WdColor.wdColorAutomatic)
            {
                sel.Font.Color = text_color;
            }
        }
Пример #8
0
        /// <summary>
        /// Metod koj kreira tabela vo dokumentot vo koja se zapisuvaat
        /// najprvo zaglavijata na kolonite, a potoa i
        /// polinjata so vrednostite za izvestajot
        /// </summary>
        /// <param name="rowNum"></param>
        /// <param name="colNum"></param>
        public void CreateTable(int rowNum, int colNum)
        {
            object start = 0;
            object end   = 0;

            object styleName = "Table Grid 3";

            _wordRange = _wordApplication.ActiveDocument.Range(ref start, ref end);
            _wordApplication.ActiveDocument.Tables.Add(_wordRange, rowNum, colNum, ref _value, ref _value);
            _wordTable = _wordDocument.Tables[1];
            _wordTable.Range.Font.Size = 8;
            _wordTable.set_Style(ref styleName);

            for (int k = 0; k < colNum; k++)
            {
                _wordCell            = _wordTable.Cell(1, k + 1);
                _wordCell.Range.Text = (string)Headers[k];
            }


            for (int i = 0; i < rowNum; i++)
            {
                for (int j = 0; j < colNum; j++)
                {
                    _wordCell            = _wordTable.Cell(i + 2, j + 1);
                    _wordCell.Range.Text = Convert.ToString(FillValues[i, j]);
                }
            }
        }
Пример #9
0
        /// <summary>
        /// 分离单元格
        /// </summary>
        public static void SeparateCell()
        {
            object oMissing = System.Reflection.Missing.Value;

            Microsoft.Office.Interop.Word._Application WordApp;
            Microsoft.Office.Interop.Word._Document    WordDoc;
            WordApp         = new Microsoft.Office.Interop.Word.Application();
            WordApp.Visible = true;
            WordDoc         = WordApp.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);

            object start = 0;
            object end   = 0;

            Microsoft.Office.Interop.Word.Range tableLocation = WordDoc.Range(ref start, ref end);
            WordDoc.Tables.Add(tableLocation, 3, 4, ref oMissing, ref oMissing);

            Microsoft.Office.Interop.Word.Table newTable = WordDoc.Tables[1];
            object beforeRow = newTable.Rows[1];

            newTable.Rows.Add(ref beforeRow);

            Microsoft.Office.Interop.Word.Cell cell = newTable.Cell(1, 1);
            cell.Merge(newTable.Cell(1, 2));

            object Rownum    = 2;
            object Columnnum = 2;

            cell.Split(ref Rownum, ref Columnnum);
        }
Пример #10
0
        /// <summary>
        /// 合并单元格
        /// </summary>
        public static void CombinationCell()
        {
            object oMissing = System.Reflection.Missing.Value;

            Microsoft.Office.Interop.Word._Application WordApp;
            Microsoft.Office.Interop.Word._Document    WordDoc;
            WordApp         = new Microsoft.Office.Interop.Word.Application();
            WordApp.Visible = true;
            WordDoc         = WordApp.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);

            object start = 0;
            object end   = 0;

            Microsoft.Office.Interop.Word.Range tableLocation = WordDoc.Range(ref start, ref end);
            WordDoc.Tables.Add(tableLocation, 3, 4, ref oMissing, ref oMissing);

            Microsoft.Office.Interop.Word.Table newTable = WordDoc.Tables[1];
            object beforeRow = newTable.Rows[1];

            newTable.Rows.Add(ref beforeRow);

            Microsoft.Office.Interop.Word.Cell cell = newTable.Cell(2, 1);//2行1列合并2行2列为一起
            cell.Merge(newTable.Cell(2, 2));
            //cell.Merge( newTable.Cell( 1, 3 ) );
        }
Пример #11
0
        public void SetCellsFont(int FirstColumn, int LastColumn, int FirstRow, int LastRow, string strName, int bold, float size, int indTable)
        {
            GetTableReference(indTable);

            MSWord.Cell pCellBegin = m_pTable.Cell(FirstRow, FirstColumn);
            MSWord.Cell pCellEnd   = m_pTable.Cell(LastRow, LastColumn);
            if (pCellBegin == null)
            {
                return;
            }
            if (pCellEnd == null)
            {
                return;
            }

            MSWord.Range range = m_pDoc.Range(pCellBegin.Range.Start, pCellEnd.Range.End);
            range.Select();
            MSWord.Selection sel = m_pApp.Selection;
            //MSWord.Font old_font = sel.Font;
            if (strName != "")
            {
                sel.Font.Name = strName;
            }
            if (bold != -1)
            {
                sel.Font.Bold = bold;
            }
            if (size > 0)
            {
                sel.Font.Size = size;
            }
            //sel.Font = old_font;
        }
Пример #12
0
        public Wordy.Range wstawWierszDoTabeli(object bookmark, Wordy.Table tab, int wiersz, string[] kolumny, bool Walidowac = true)
        {
            int i = 1;

            tab.Rows.Add();

            Wordy.Cell cel = null;
            foreach (String kol in kolumny)
            {
                String t = kol;

                //      t =  usunNieobslugiwaneZnacznikiHtml(t); <<< pytanie co sie zwali
                //       t = kowertujZnacznikiHTML(t);     <<pytanie co sie zwali
                cel = tab.Cell(wiersz, i);
                if (t == null)
                {
                    t = " ";
                }

                cel.Range.Text = t;
                cel.Range.set_Style(stylNorm);
                //cel.Range.Bold = 1;                  // nie działa poprawnie
                if (Walidowac)
                {
                    if (t == "")
                    {
                        cel.Range.Comments.Add(cel.Range, "Niekompletny wiersz w tabeli - kolumna: " + i + ".");
                    }
                }
                i++;
            }
            return(cel.Range);
        }
Пример #13
0
        private void Pregunta3()
        {
            p1 = "INCORRECTO";

            Word.Tables tablas = docAlumno.Tables;
            if (tablas.Count == 1)
            {
                Word.Table tabla    = tablas[1];
                int        filas    = tabla.Rows.Count;
                int        columnas = tabla.Columns.Count;


                if (filas == 6 && columnas == 2 && tabla.Uniform == false)
                {
                    Word.Cell cell = tabla.Cell(filas, 1);

                    try
                    {
                        Word.Column col = cell.Column;
                    }
                    catch (Exception)
                    {
                        p1 = "CORRECTO";
                    }
                }
            }
            GuardarPuntaje();
            CerrarWords();

            BorrarPreguntasTemporales();
        }
Пример #14
0
 /// <summary>
 /// Establece el estilo de la arista de una celda.
 /// </summary>
 /// <param name="cell">Celda a formatear.</param>
 /// <param name="style">Estilo de la línea.</param>
 /// <param name="borderType">Arista a colorear.</param>
 /// <param name="color">Color de la línea.</param>
 private void SetCellBorder(Word.Cell cell, Word.WdLineStyle style = Word.WdLineStyle.wdLineStyleSingle, Word.WdBorderType borderType = Word.WdBorderType.wdBorderBottom, Word.WdColor color = Word.WdColor.wdColorBlack)
 {
     Word.Border border = cell.Borders[borderType];
     border.Visible   = true;
     border.LineStyle = style;
     border.LineWidth = Word.WdLineWidth.wdLineWidth050pt;
     border.Color     = color;
 }
Пример #15
0
        private static void ApplyHeadingStyle(WordNet.Cell cell, int width = 300)
        {
            cell.Width = width;

            cell.Range.Font.Name = "Arial";
            cell.Range.Font.Size = 10;
            cell.Range.Font.Bold = 1;
        }
Пример #16
0
        private ICell CreateCell(nat.Cell cell)
        {
            var words = _wordFactory.CreateFromRange(cell.Range);

            return(new Cell(
                       cell.ColumnIndex,
                       cell.RowIndex,
                       words));
        }
            //---------------------------------------------------------------------------------------------------------
            /// <summary>
            /// Объединение ячеек по горизонтали
            /// </summary>
            /// <param name="cell">Ячейка</param>
            /// <param name="count">Количество объединяемых ячеек</param>
            /// <returns>Ячейка</returns>
            //---------------------------------------------------------------------------------------------------------
            public static Word.Cell MergeHorizontal(this Word.Cell cell, Int32 count = 1)
            {
                Int32 row_index     = cell.RowIndex;
                Int32 collumn_index = cell.ColumnIndex;

                Word.Table table_owner = cell.Parent as Word.Table;
                cell.Merge(table_owner.Cell(row_index, collumn_index + count));
                return(cell);
            }
Пример #18
0
        public void SetTextInCell(int Column, int Row, string strText, int indTable = -1, string strDefault = "", bool bAdd = false)
        {
            if (strText == "")
            {
                strText = strDefault;
                if (strText == "")
                {
                    return;
                }
            }

            int top  = 1;
            int left = 1;

            //MSWord.Columns pCols = null;
            //MSWord.Rows pRows = null;
            MSWord.Cell      pCell = null;
            MSWord.Selection pSel  = null;

            GetTableReference(indTable);

            //pCols = m_pTable.Columns;
            //if (pCols == null) return;
            //pRows = m_pTable.Rows;
            //if (pRows == null) return;

            if (Column >= 0)
            {
                left = Column;
            }
            if (Row >= 0)
            {
                top = Row;
            }

            // проверяем правильность установки границ диапазона
            // получаем верхнюю левую ячейку диапазона
            pCell = m_pTable.Cell(top, left);
            if (pCell == null)
            {
                return;
            }

            if (!bAdd)
            {
                pCell.Range.Text = strText;
            }
            else
            {
                pCell.Select();
                pSel = m_pApp.Selection;
                pSel.EndKey();

                pSel.Text = strText;
                pSel.Collapse(0);
            }
        }
Пример #19
0
 public Wordy.Range wstawObiektEA_RTFDoKomorki(Word word, Wordy.Table tab, Wordy.Cell cel, CModel modelProjektu, EA.Element el)
 { ///nie używany nigdy kod
     /*
      * cel.Range.InsertParagraph();
      * wstawNotatkeEAtoRTF(modelProjektu.Repozytorium, el);
      * word.wstawZalacznikRTF(el);
      */
     return(cel.Range);
 }
Пример #20
0
        /// <summary>
        /// filling the table in the document from invoice listview
        /// </summary>
        /// <param name="app"> word application </param>
        /// <param name="doc"> opened document </param>
        void AddDescription(word.Application app, Document doc)
        {
            Logger.GetInstance().SaveLog("AddDescription entered ");
            Table dataTbl = null;

            foreach (Table tbl in doc.Tables)
            {
                Range     rng   = tbl.Range;
                word.Cell cell  = tbl.Cell(1, 1);
                word.Cell cell2 = tbl.Cell(1, 2);

                if (cell.Range.Text.Contains("Device") && cell2.Range.Text.Contains("Description"))
                {
                    dataTbl = tbl;
                }
            }

            int   count     = listView1.Items.Count;
            float tblHeight = 0;

            for (int i = 1; i < dataTbl.Rows.Count; i++)
            {
                Row row = dataTbl.Rows[i];
                tblHeight += row.Height;
            }

            float rowHeight = tblHeight / count;

            if (count >= dataTbl.Rows.Count)
            {
                for (int i = dataTbl.Rows.Count; i <= count; i++)
                {
                    dataTbl.Rows.Add(dataTbl.Rows[2]);
                }
            }
            else
            {
                for (int i = dataTbl.Rows.Count; i > count + 1; i--)
                {
                    dataTbl.Rows[i].Delete();
                }
            }

            for (int i = 0; i < listView1.Items.Count; i++)
            {
                dataTbl.Rows[i + 2].Height = rowHeight;
                ListViewItem itm    = listView1.Items[i];
                Cell         device = dataTbl.Cell(i + 2, 1);
                device.Range.Text = itm.Text;
                dataTbl.Cell(i + 2, 2).Range.Text = itm.SubItems[1].Text;
                dataTbl.Cell(i + 2, 3).Range.Text = itm.SubItems[2].Text;
                dataTbl.Cell(i + 2, 4).Range.Text = itm.SubItems[3].Text;
                dataTbl.Cell(i + 2, 5).Range.Text = itm.SubItems[4].Text;
            }
            Logger.GetInstance().SaveLog("AddDescription exit ");
        }
Пример #21
0
 public void SplitCell(int Column, int FirstRow, int LastRow, int iCntCols, int iCntRows, int indTable = -1)
 {
     GetTableReference(indTable);
     for (int i = FirstRow; i <= LastRow; i++)
     {
         MSWord.Cell pCellBegin = m_pTable.Cell(i, Column);
         pCellBegin.Select();
         m_pApp.Selection.Cells.Split(iCntRows, iCntCols, false);
     }
 }
Пример #22
0
 static void SetHeadings(Word.Cell tblCell, string text)
 {
     tblCell.Range.Text                        = text;
     tblCell.Range.Borders.Enable              = 1;
     tblCell.Range.ParagraphFormat.SpaceAfter  = 0;
     tblCell.Range.ParagraphFormat.SpaceBefore = 0;
     tblCell.Range.Borders.InsideColor         = Word.WdColor.wdColorBlack;
     tblCell.Range.Borders.OutsideColor        = Word.WdColor.wdColorBlack;
     tblCell.Range.ParagraphFormat.Alignment   = Word.WdParagraphAlignment.wdAlignParagraphCenter;
 }
Пример #23
0
        public void addTable2(XmlNode tableNode)
        {
            if (tableNode == null)
            {
                return;
            }

            string bookmark = tableNode.Attributes["k"].Value;

            if (!wDoc.Bookmarks.Exists(bookmark))
            {
                return;
            }

            XmlNodeList rows = tableNode.SelectNodes("tr");
            int         c = 0, r = rows.Count;
            object      nothing = Missing.Value;

            // get max cols
            foreach (XmlNode row in rows)
            {
                int t = row.SelectNodes("td").Count;
                c = Math.Max(c, t);
            }

            // create table of size c x r
            object bm = bookmark;

            Word.Range wrdRng = wDoc.Bookmarks.get_Item(ref bm).Range;
            Word.Table table  = wDoc.Tables.Add(wrdRng, r, c, ref nothing, ref nothing);
            table.Borders.InsideLineStyle  = Word.WdLineStyle.wdLineStyleSingle;
            table.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;
            table.PreferredWidthType       = Word.WdPreferredWidthType.wdPreferredWidthPercent;
            table.Columns[1].Width         = 100;
            table.Columns[2].Width         = 400;

            for (int i = 0; i < r; i++)
            {
                XmlNode     row  = rows[i];
                XmlNodeList cols = row.SelectNodes("td");

                for (int j = 0; j < c; j++)
                {
                    setCellContent(table.Cell(i + 1, j + 1), cols[j]);
                }
            }

            for (int i = 0; i < c; i++)
            {
                Word.Cell cell = table.Cell(1, i + 1);
                cell.Height = 35;
                cell.Range.Shading.ForegroundPatternColor =
                    Word.WdColor.wdColorGray25;
            }
        }
Пример #24
0
 // Merge several column into one column
 public void MergeColumn(Word.Table tb, Word.Cell[] cells)
 {
     if (cells.Length > 1)
     {
         Word.Cell c   = cells[0];
         int       len = cells.Length;
         for (int i = 1; i < len; i++)
         {
             c.Merge(cells[i]);
         }
     }
     wordApp.Selection.Cells.VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
 }
 //---------------------------------------------------------------------------------------------------------
 /// <summary>
 /// Установка стили ячейки заголовка
 /// </summary>
 /// <param name="cell">Ячейка</param>
 /// <param name="size">Размер шрифта</param>
 /// <param name="is_bold">Жирный шрифт</param>
 /// <returns>Ячейка</returns>
 //---------------------------------------------------------------------------------------------------------
 public static Word.Cell SetHeaderStyle(this Word.Cell cell, Single size = 10, Boolean is_bold = true)
 {
     cell.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
     cell.VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
     cell.Range.Shading.BackgroundPatternColor = Word.WdColor.wdColorGray30;
     cell.Range.Font.Size = size;
     cell.Range.Font.Bold = is_bold ? 1 : 0;
     cell.Range.Font.Name = "Times New Roman";
     cell.Range.ParagraphFormat.Space1();
     cell.Range.ParagraphFormat.SpaceAfter  = 0;
     cell.Range.ParagraphFormat.SpaceBefore = 0;
     return(cell);
 }
Пример #26
0
        /// <summary>
        /// 检查单元格是否是行合并过的?
        /// </summary>
        internal static bool IsCellRowMerged(Word.Cell cell)
        {
            bool isMerged;

            // 若尝试获取该单元格的下一行单元格失败,那么说明该单元格是行合并过的
            try {
                var cellNextRow = cell.Tables[1].Cell(cell.RowIndex + 1, cell.ColumnIndex);
                // 获取成功,没合并过
                isMerged = false;
            } catch (COMException) { // 获取失败,说明合并过
                isMerged = true;
            }
            return(isMerged);
        }
Пример #27
0
        public void PopulateTableCell(int row, int column, string value, string name = "")
        {
            if (String.IsNullOrEmpty(name))
            {
                object t   = _document.Application.Selection.Information[WordOM.WdInformation.wdWithInTable];
                var    isT = false;
                Boolean.TryParse(t.ToString(), out isT);
                if (isT)
                {
                    //var cell = _document.Application.Selection.Tables[1].Cell(row, column);
                    //cell.Range.Text = value;

                    //_document.Application.Selection.Tables[1].Columns[1].Cells

                    WordOM.Table table = _document.Application.Selection.Tables[1];
                    foreach (WordOM.Cell c in table.Range.Cells)
                    {
                        if (c.ColumnIndex == column && c.RowIndex == row)
                        {
                            //foreach (WordOM.Row r in c.Row)
                            //{
                            //    if (r.Index == row)
                            //    {
                            c.Range.Text = value;
                            //    }
                            //}
                        }
                    }

                    //for (int rI = 1; rI < table.Rows.Count; rI ++)
                    //{
                    //    if (rI == row)
                    //    {

                    //    }
                    //}
                }
            }
            else
            {
                foreach (WordOM.Table table in _document.Tables)
                {
                    if (String.Equals(name, table.Title, StringComparison.OrdinalIgnoreCase))
                    {
                        WordOM.Cell cell = table.Cell(row, column);
                        cell.Range.Text = value;
                    }
                }
            }
        }
Пример #28
0
        public void DeleteRowEx(int Row, int indTable = -1)
        {
            GetTableReference(indTable);

            MSWord.Cell pCell = m_pTable.Cell(Row, 1);
            pCell.Select();
            m_pSelection = m_pApp.Selection;
            if (m_pSelection == null)
            {
                return;
            }

            //m_pSelection.MoveDown(MSWord.WdUnits.wdLine, 2);
            m_pSelection.Rows.Delete();
        }
Пример #29
0
        public void InsertBookMark(string name, ref int?row, ref int?column)
        {
            try
            {
                Word.Cell c = Globals.ThisAddIn.Application.Selection.Cells[1];
                DocumentModel.AddBookMark(c.Range, name);

                row    = c.RowIndex;
                column = c.ColumnIndex;
            }
            catch (Exception)
            {
                DocumentModel.AddBookMark(Globals.ThisAddIn.Application.Selection.Range, name);
            }
        }
Пример #30
0
        public void DeleteColumnEx(int Column, int indTable)
        {
            GetTableReference(indTable);

            MSWord.Cell pCell = m_pTable.Cell(1, Column);
            pCell.Select();
            m_pSelection = m_pApp.Selection;
            if (m_pSelection == null)
            {
                return;
            }

            //m_pSelection.MoveDown(MSWord.WdUnits.wdLine, 2);
            m_pSelection.Columns.Delete();
        }
Пример #31
0
 private int check_Kernel(List<OfficeElement> ls)
 {
     int points = 0, i;
     int curPart = -1;            //当前正在分析哪一部分的考点
     for (i = 0; i < ls.Count; i++)
     {
         OfficeElement oe = ls[i];
         #region 具体考点对象定位
         if (oe.AttribName == "Root")
             continue;
         if (oe.AttribName == "Documents")
             continue;
         if (oe.AttribName == "Paragraph")
         {
             #region 段落定位
             try
             {
                 int paraIdx = int.Parse(oe.AttribValue);
                 stuPara = stuDoc.Paragraphs[paraIdx];
                 ansPara = ansDoc.Paragraphs[paraIdx];
             }
             catch
             {
                 points = 0;
                 break;
             }
             #endregion
             curPart = PART_PARAGRAPH;
             continue;
         }
         if (oe.AttribName == "Table")
         {
             #region 表格定位
             try
             {
                 int tabIdx = int.Parse(oe.AttribValue);
                 stuTab = stuDoc.Tables[tabIdx];
                 ansTab = ansDoc.Tables[tabIdx];
             }
             catch
             {
                 points = 0;
                 break;
             }
             #endregion
             curPart = PART_TABLE;
             continue;
         }
         if (oe.AttribName == "Cell")
         {
             #region 单元格定位
             try
             {
                 int rowIdx, colIdx, commaIdx;
                 commaIdx = oe.AttribValue.IndexOf(',');
                 rowIdx = int.Parse(oe.AttribValue.Substring(0, commaIdx));
                 colIdx = int.Parse(oe.AttribValue.Substring(commaIdx + 1));
                 stuCell = stuTab.Cell(rowIdx, colIdx);
                 ansCell = ansTab.Cell(rowIdx, colIdx);
             }
             catch
             {
                 points = 0;
                 break;
             }
             #endregion
             curPart = PART_CELL;
             continue;
         }
         if (oe.AttribName == "Textbox")
         {
             #region 文本框定位
             try
             {
                 int tbIdx = int.Parse(oe.AttribValue);
                 object ob = tbIdx;
                 stuSp = stuDoc.Shapes.get_Item(ref ob);
                 ansSp = ansDoc.Shapes.get_Item(ref ob);
                 stuTf = stuSp.TextFrame;
                 ansTf = ansSp.TextFrame;
             }
             catch
             {
                 points = 0;
                 break;
             }
             #endregion
             curPart = PART_TEXTBOX;
             continue;
         }
         if (oe.AttribName == "PageSetup")
         {
             #region 页面设置定位
             try
             {
                 stuPs = stuDoc.PageSetup;
                 ansPs = ansDoc.PageSetup;
             }
             catch
             {
                 points = 0;
                 break;
             }
             #endregion
             continue;
         }
         #endregion
         #region 段落属性判分
         if (curPart == PART_PARAGRAPH)
         {
             switch (oe.AttribName)
             {
                 case "Indent":
                     break;
                 case "Font":
                     stuRange = stuPara.Range;
                     ansRange = ansPara.Range;
                     break;
                 case "Dropcap":
                     stuDc = stuPara.DropCap;
                     ansDc = ansPara.DropCap;
                     break;
                 case "TextColumns":
                     stuTc = stuPara.Range.PageSetup.TextColumns;
                     ansTc = ansPara.Range.PageSetup.TextColumns;
                     break;
                 #region 段落部分
                 case "Alignment":
                     if (stuPara.Alignment == ansPara.Alignment)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "CharacterUnitFirstLineIndent":
                     if (stuPara.CharacterUnitFirstLineIndent == ansPara.CharacterUnitFirstLineIndent)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "CharacterUnitLeftIndent":
                     if (stuPara.CharacterUnitLeftIndent == ansPara.CharacterUnitLeftIndent)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "CharacterUnitRightIndent":
                     if (stuPara.CharacterUnitRightIndent == ansPara.CharacterUnitRightIndent)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "LineUnitBefore":
                     if (stuPara.LineUnitBefore == ansPara.LineUnitBefore)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "LineUnitAfter":
                     if (stuPara.LineUnitAfter == ansPara.LineUnitAfter)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "LineSpacingRule":
                     if (stuPara.LineSpacingRule == ansPara.LineSpacingRule)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "LineSpacing":
                     if (stuPara.LineSpacing == ansPara.LineSpacing)
                         points = int.Parse(oe.AttribValue);
                     break;
                 #endregion
                 #region 文字部分
                 case "Text":
                     if (stuRange.Text == ansRange.Text)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "FontSize":
                     if (stuRange.Font.Size == ansRange.Font.Size)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "FontName":
                     if (stuRange.Font.Name == ansRange.Font.Name)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Bold":
                     if (stuRange.Font.Bold == ansRange.Font.Bold)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Italic":
                     if (stuRange.Font.Italic == ansRange.Font.Italic)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Underline":
                     if (stuRange.Font.Underline == ansRange.Font.Underline)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "UnderlineColor":
                     if (stuRange.Font.UnderlineColor == ansRange.Font.UnderlineColor)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "ForeColor":
                     if (stuRange.Font.Color == ansRange.Font.Color)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "HighLightColor":
                     if (stuRange.HighlightColorIndex == ansRange.HighlightColorIndex)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Superscript":
                     if (stuRange.Font.Superscript == ansRange.Font.Superscript)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Subscript":
                     if (stuRange.Font.Subscript == ansRange.Font.Subscript)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Spacing":
                     if (stuRange.Font.Spacing == ansRange.Font.Spacing)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Animation":
                     if (stuRange.Font.Animation == ansRange.Font.Animation)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "BackgroundPatternColor":
                     if (stuRange.Shading.BackgroundPatternColor == ansRange.Shading.BackgroundPatternColor)
                         points = int.Parse(oe.AttribValue);
                     break;
                 #endregion
                 #region 首字下沉
                 case "Position":
                     if (stuDc.Position == ansDc.Position)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "DcFontName":
                     if (stuDc.FontName == ansDc.FontName)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "LinesToDrop":
                     if (stuDc.LinesToDrop == ansDc.LinesToDrop)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "DistanceFromText":
                     if (stuDc.DistanceFromText == ansDc.DistanceFromText)
                         points = int.Parse(oe.AttribValue);
                     break;
                 #endregion
                 #region 分栏与栏宽
                 case "TextColumnsCount":
                     if (stuTc.Count == ansTc.Count)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "TextColumnsWidth":
                     if (stuTc.Width == ansTc.Width)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "TextColumnsSpacing":
                     if (stuTc.Spacing == ansTc.Spacing)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "TextColumnsLineBetween":
                     if (stuTc.LineBetween == ansTc.LineBetween)
                         points = int.Parse(oe.AttribValue);
                     break;
                 #endregion
             }
             continue;
         }
         #endregion
         #region 表格属性判分
         if (curPart == PART_TABLE)
         {
             switch (oe.AttribName)
             {
                 case "Rows":
                     if (stuTab.Rows.Count == ansTab.Rows.Count)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Columns":
                     if (stuTab.Columns.Count == ansTab.Columns.Count)
                         points = int.Parse(oe.AttribValue);
                     break;
             }
             continue;
         }
         #endregion
         #region 单元格属性判分
         if (curPart == PART_CELL)
         {
             switch (oe.AttribName)
             {
                 case "Text":
                     if (stuCell.Range.Text == ansCell.Range.Text)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Height":
                     if (stuCell.Height == ansCell.Height)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Width":
                     if (stuCell.Width == ansCell.Width)
                         points = int.Parse(oe.AttribValue);
                     break;
             }
             continue;
         }
         #endregion
         #region 文本框属性判分
         if (curPart == PART_TEXTBOX)
         {
             switch (oe.AttribName)
             {
                 case "Text":
                     if (stuTf.TextRange.Text == ansTf.TextRange.Text)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Orientation":
                     if (stuTf.Orientation == ansTf.Orientation)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "FontName":
                     if (stuTf.TextRange.Font.Name == ansTf.TextRange.Font.Name)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "FontSize":
                     if (stuTf.TextRange.Font.Size == ansTf.TextRange.Font.Size)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "ForeColor":
                     if (stuTf.TextRange.Font.Color == ansTf.TextRange.Font.Color)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "HighLightColor":
                     if (stuTf.TextRange.HighlightColorIndex == ansTf.TextRange.HighlightColorIndex)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Spacing":
                     if (stuTf.TextRange.Font.Spacing == ansTf.TextRange.Font.Spacing)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Alignment":
                     if (stuTf.TextRange.ParagraphFormat.Alignment == ansTf.TextRange.ParagraphFormat.Alignment)
                         points = int.Parse(oe.AttribValue);
                     break;
             }
             continue;
         }
         #endregion
         #region 页面设置属性判分
         if (curPart == PART_PAGESETUP)
         {
             switch (oe.AttribName)
             {
                 case "TopMargin":
                     if (stuPs.TopMargin == ansPs.TopMargin)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "BottomMargin":
                     if (stuPs.BottomMargin == ansPs.BottomMargin)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "LeftMargin":
                     if (stuPs.LeftMargin == ansPs.LeftMargin)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "RightMargin":
                     if (stuPs.RightMargin == ansPs.RightMargin)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "HeaderDistance":
                     if (stuPs.HeaderDistance == ansPs.HeaderDistance)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "FooterDistance":
                     if (stuPs.FooterDistance == ansPs.FooterDistance)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Orientation":
                     if (stuPs.Orientation == ansPs.Orientation)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "GutterPos":
                     if (stuPs.GutterPos == ansPs.GutterPos)
                         points = int.Parse(oe.AttribValue);
                     break;
             }
             continue;
         }
         #endregion
     }
     return points;
 }
 internal Cell(Microsoft.Office.Interop.Word.Cell _cell, int _numberOfColumnsAccordingToTable)
 {
     m_cell = _cell;
     m_numberOfColumnsAccordingToTable = _numberOfColumnsAccordingToTable;
 }