Пример #1
0
        /// <summary>
        /// �������table���ͳ��ַ���{0}.{1}��ʽ��
        /// {0}Ϊ������Ϊ��ţ�{1}Ϊż����Ϊ�𰸡�
        /// </summary>
        /// <param name="nowTable"></param>
        /// <returns></returns>
        public System.Collections.Generic.List<string> AnswerTableToParagraph(Microsoft.Office.Interop.Word.Table nowTable)
        {
            System.Collections.Generic.List<string> Dict = new System.Collections.Generic.List<string>();

            if (nowTable.Rows.Count % 2 == 0 && nowTable.Rows.Count > 0)
            {
                for (int rowPos = 1; rowPos <= nowTable.Rows.Count; rowPos = rowPos + 2)
                {
                    for (int columPos = 1; columPos <= nowTable.Columns.Count; columPos++)
                    {
                        string key = nowTable.Cell(rowPos, columPos).Range.Text;
                        string value = nowTable.Cell(rowPos+1, columPos).Range.Text;
                        key = key.Remove(key.Length - 2, 2).Trim() ;
                        value = value.Remove(value.Length - 2, 2).Trim();
                        if (!string.IsNullOrEmpty(key))
                        {
                            Dict.Add(string.Format("{0}.{1}", key, value));
                        }
                    }
                }
            }
            return  Dict;
        }
Пример #2
0
 public void _DesginTable(ref Microsoft.Office.Interop.Word.Table table, List<int> columnWeight)
 {
     for (int i = 0; i < table.Rows.Count; i++)
         for (int j = 0; j < table.Columns.Count; j++)
             table.Cell(i + 1, j + 1).Width = columnWeight[j];
 }
Пример #3
0
 //合并单元格 表名,开始行号,开始列号,结束行号,结束列号
 public void MergeCell(Microsoft.Office.Interop.Word.Table table, int row1, int column1, int row2, int column2)
 {
     table.Cell(row1, column1).Merge(table.Cell(row2, column2));
 }
Пример #4
0
 //给表格中单元格插入元素,table所在表格,row行号,column列号,value插入的元素
 public void InsertCell(Microsoft.Office.Interop.Word.Table table, int row, int column, string value)
 {
     table.Cell(row, column).Range.Text = value;
 }
 private static void InsertWordTableRows(Microsoft.Office.Interop.Word.Table wordTable, int rowNumberToStartInsert, int numberOfNewRows)
 {
     Range range = wordTable.Cell(rowNumberToStartInsert, 1).Range;
     range.MoveStart(WdUnits.wdCell, -1);
     range.Collapse(WdCollapseDirection.wdCollapseEnd);
     if (numberOfNewRows > 0) {
         for (int i = 0; i < numberOfNewRows; i++) {
             wordTable.Rows.Add(range);
         }
     }
 }
        private static void FillTransitionTable(Microsoft.Office.Interop.Word.Table wordTable, int wordTableBeginRow, Table table)
        {
            InsertWordTableRows(wordTable, wordTableBeginRow, table.GetNumRows() - 1);

            for (int row = 0; row < table.GetNumRows(); row++) {
                string condition = table.GetData(row, (int)TableColumns.Transitions.Condition);
                string action = table.GetData(row, (int)TableColumns.Transitions.Action);
                string goingTo = table.GetData(row, (int)TableColumns.Transitions.Goto);
                string conditionDate = table.GetData(row, (int)TableColumns.Transitions.ConditionDateStamp);
                string actionDate = table.GetData(row, (int)TableColumns.Transitions.ActionDateStamp);
                string goingToDate = table.GetData(row, (int)TableColumns.Transitions.GotoDateStamp);

                Cell cell = wordTable.Cell(wordTableBeginRow + row, 1);
                cell.Range.InsertAfter(Common.StripBracketLabels(condition));
                SetCellBackgroundColorIfNecessary(cell, conditionDate);

                cell = wordTable.Cell(wordTableBeginRow + row, 2);
                BuildConditionActionGotoCell(cell, "", "", action, actionDate, goingTo, goingToDate);
            }
        }
        private static void FillPromptTypesTable(Microsoft.Office.Interop.Word.Table wordTable, int wordTableBeginRow, Table table)
        {
            // prompts with conditions get split over 2 rows - need to add extra for them
            int conditionsWithPrompts = CountConditionsWithPrompts(table, (int)TableColumns.ConfirmationPrompts.Condition, (int)TableColumns.ConfirmationPrompts.Wording);
            // There's already one row in the template, so always subtract 1
            InsertWordTableRows(wordTable, wordTableBeginRow, table.GetNumRows() + conditionsWithPrompts - 1);

            int level = 0;
            int wordingLevel = 0;
            int currentWordTableRow = wordTableBeginRow;
            for (int row = 0; row < table.GetNumRows(); row++) {
                string type = table.GetData(row, (int)TableColumns.PromptTypes.Type);
                string condition = table.GetData(row, (int)TableColumns.PromptTypes.Condition);
                string wording = Common.StripBracketLabels(table.GetData(row, (int)TableColumns.PromptTypes.Wording));
                string id = table.GetData(row, (int)TableColumns.PromptTypes.Id);
                string typeDate = table.GetData(row, (int)TableColumns.PromptTypes.TypeDateStamp);
                string conditionDate = table.GetData(row, (int)TableColumns.PromptTypes.ConditionDateStamp);
                string wordingDate = table.GetData(row, (int)TableColumns.PromptTypes.WordingDateStamp);
                string idDate = table.GetData(row, (int)TableColumns.PromptTypes.IdDateStamp);

                Cell cell = wordTable.Cell(currentWordTableRow, 1);
                if (OptionOrPromptTypeEntriesSameAsPrevious(table, row, (int)TableColumns.ConfirmationPrompts.Option))
                    cell.Range.Borders[WdBorderType.wdBorderTop].LineStyle = WdLineStyle.wdLineStyleNone;
                else {
                    cell.Range.InsertAfter(Common.StripBracketLabels(type));
                    level = 0;
                    wordingLevel = 0;
                }
                SetCellBackgroundColorIfNecessary(cell, typeDate);

                cell = wordTable.Cell(currentWordTableRow, 2);
                if (condition.Length > 0) {
                    level = Common.GetConditionLevel(condition);
                    wordingLevel = level + 1;
                }
                condition = condition.Replace(Strings.IndentCharacterString, "").Trim();
                if (condition.Length > 0) {
                    cell.Range.ParagraphFormat.IndentCharWidth((short)level);
                    cell.Range.InsertAfter(condition);
                    cell.Range.Font.Italic = 1;
                    SetCellBackgroundColorIfNecessary(cell, conditionDate);
                }

                if (wording.Length > 0) {
                    if (condition.Length > 0) {
                        // goes on a separate line after the condition row and indented
                        currentWordTableRow++;
                        // clear the border in column 1 so it looks like part of the one above
                        wordTable.Cell(currentWordTableRow, 1).Range.Borders[WdBorderType.wdBorderTop].LineStyle = WdLineStyle.wdLineStyleNone;
                    }
                    cell = wordTable.Cell(currentWordTableRow, 2);
                    cell.Range.ParagraphFormat.IndentCharWidth((short)wordingLevel);
                    cell.Range.InsertAfter(wording);
                    SetCellBackgroundColorIfNecessary(cell, wordingDate);
                }

                if (id.Length > 0) {
                    cell = wordTable.Cell(currentWordTableRow, 3);
                    cell.Range.InsertAfter(id);
                    SetCellBackgroundColorIfNecessary(cell, idDate);
                }

                currentWordTableRow++;
            }
        }
        private static void FillNameValuePairs(Microsoft.Office.Interop.Word.Table wordTable, int wordTableBeginRow, Table table)
        {
            InsertWordTableRows(wordTable, wordTableBeginRow, table.GetNumRows() - 1);

            for (int row = 0; row < table.GetNumRows(); row++) {
                string name = table.GetData(row, (int)TableColumns.NameValuePairs.Name);
                string value = table.GetData(row, (int)TableColumns.NameValuePairs.Value);
                //string notes = table.GetData(row, (int)TableColumns.NameValuePairs.Notes);
                string nameDate = table.GetData(row, (int)TableColumns.NameValuePairs.NameDateStamp);
                string valueDate = table.GetData(row, (int)TableColumns.NameValuePairs.ValueDateStamp);
                //string notesDate = table.GetData(row, (int)TableColumns.NameValuePairs.NotesDateStamp);

                Cell cell = wordTable.Cell(wordTableBeginRow + row, 1);
                cell.Range.InsertAfter(name);
                SetCellBackgroundColorIfNecessary(cell, nameDate);

                cell = wordTable.Cell(wordTableBeginRow + row, 2);
                cell.Range.InsertAfter(value);
                SetCellBackgroundColorIfNecessary(cell, valueDate);

                //cell = wordTable.Cell(wordTableBeginRow + row, 3);
                //cell.Range.InsertAfter(notes);
                //SetCellBackgroundColorIfNecessary(cell, notesDate);
            }
        }
        /*private static void SetCellBackgroundColorIfNecessary(Cell cell, string dateTime)
        {
            WdColorIndex index = GetHighlightColorIndex(dateTime);
            if (index != WdColorIndex.wdNoHighlight)
                cell.Range.Font.Shading.BackgroundPatternColorIndex = index;
        }*/
        private static void FillMaxHandling(Microsoft.Office.Interop.Word.Table wordTable, int wordTableBeginRow, Table table)
        {
            InsertWordTableRows(wordTable, wordTableBeginRow, table.GetNumRows() - 1);

            for (int row = 0; row < table.GetNumRows(); row++) {
                string condition = table.GetData(row, (int)TableColumns.MaxHandling.Condition);
                string count = table.GetData(row, (int)TableColumns.MaxHandling.Count);
                string action = table.GetData(row, (int)TableColumns.MaxHandling.Action);
                string goingTo = table.GetData(row, (int)TableColumns.MaxHandling.Goto);
                string countDate = table.GetData(row, (int)TableColumns.MaxHandling.CountDateStamp);
                string actionDate = table.GetData(row, (int)TableColumns.MaxHandling.ActionDateStamp);
                string goingToDate = table.GetData(row, (int)TableColumns.MaxHandling.GotoDateStamp);

                if (count.Trim().Length == 0)
                    count = Strings.MaxHandlerGlobalReferenceNote;
                if (action.Trim().Length == 0 && goingTo.Trim().Length == 0)
                    action = Strings.MaxHandlerGlobalReferenceNote;

                Cell cell = wordTable.Cell(wordTableBeginRow + row, 1);
                cell.Range.InsertAfter(condition);

                cell = wordTable.Cell(wordTableBeginRow + row, 2);
                cell.Range.InsertAfter(count);
                SetCellBackgroundColorIfNecessary(cell, countDate);

                BuildConditionActionGotoCell(wordTable.Cell(wordTableBeginRow + row, 3), "", "", action, actionDate, goingTo, goingToDate);
            }
        }
        private static void FillCommandTransitionTable(Microsoft.Office.Interop.Word.Table wordTable, int wordTableBeginRow, Table table)
        {
            InsertWordTableRows(wordTable, wordTableBeginRow, table.GetNumRows() - 1);

            for (int row = 0; row < table.GetNumRows(); row++) {
                string option = table.GetData(row, (int)TableColumns.CommandTransitions.Option);
                string vocab = table.GetData(row, (int)TableColumns.CommandTransitions.Vocab);
                string dtmf = table.GetData(row, (int)TableColumns.CommandTransitions.DTMF);
                string condition = table.GetData(row, (int)TableColumns.CommandTransitions.Condition);
                string action = table.GetData(row, (int)TableColumns.CommandTransitions.Action);
                string goingTo = table.GetData(row, (int)TableColumns.CommandTransitions.Goto);
                string confirm = table.GetData(row, (int)TableColumns.CommandTransitions.Confirm);
                string optionDate = table.GetData(row, (int)TableColumns.CommandTransitions.OptionDateStamp);
                string vocabDate = table.GetData(row, (int)TableColumns.CommandTransitions.VocabDateStamp);
                string dtmfDate = table.GetData(row, (int)TableColumns.CommandTransitions.DTMFDateStamp);
                string conditionDate = table.GetData(row, (int)TableColumns.CommandTransitions.ConditionDateStamp);
                string actionDate = table.GetData(row, (int)TableColumns.CommandTransitions.ActionDateStamp);
                string goingToDate = table.GetData(row, (int)TableColumns.CommandTransitions.GotoDateStamp);
                string confirmDate = table.GetData(row, (int)TableColumns.CommandTransitions.ConfirmDateStamp);

                Cell cell = wordTable.Cell(wordTableBeginRow + row, 1);
                if (OptionOrPromptTypeEntriesSameAsPrevious(table, row, (int)TableColumns.CommandTransitions.Option))
                    cell.Range.Borders[WdBorderType.wdBorderTop].LineStyle = WdLineStyle.wdLineStyleNone;
                else
                    cell.Range.InsertAfter(Common.StripBracketLabels(option));
                SetCellBackgroundColorIfNecessary(cell, optionDate);

                cell = wordTable.Cell(wordTableBeginRow + row, 2);
                cell.Range.InsertAfter(vocab);
                SetCellBackgroundColorIfNecessary(cell, vocabDate);

                cell = wordTable.Cell(wordTableBeginRow + row, 3);
                cell.Range.InsertAfter(dtmf);
                SetCellBackgroundColorIfNecessary(cell, dtmfDate);

                cell = wordTable.Cell(wordTableBeginRow + row, 4);
                BuildConditionActionGotoCell(cell, condition, conditionDate, action, actionDate, goingTo, goingToDate);

                cell = wordTable.Cell(wordTableBeginRow + row, 5);
                cell.Range.InsertAfter(confirm);
                SetCellBackgroundColorIfNecessary(cell, confirmDate);
            }
        }