コード例 #1
0
        public override void DynamicInsert(GeneratorBase.MethodParams mp)
        {
            List <string> Data = DataProvider.GETStringData(mp.DataPath);

            if (mp.IsInTableCell)
            {
                using (WordprocessingDocument document = WordprocessingDocument.Open(Path, true))
                {
                    var mainPart  = document.MainDocumentPart;
                    var bookmarks = from bm in mainPart.Document.Body.Descendants <BookmarkStart>()
                                    where bm.Name == mp.BookMarkName
                                    select bm;
                    var bookmark = bookmarks.SingleOrDefault();
                    if (bookmark != null)
                    {
                        var table = bookmark.Parent.Parent.Parent.Parent;

                        if (table is Table)
                        {
                            while (table.Elements <TableRow>().Count() - mp.TableCellRow.Value < Data.Count)
                            {
                                TableRow rowCopy = (TableRow)table
                                                   .Elements <TableRow>().ElementAt(mp.TableCellRow.Value)
                                                   .CloneNode(true);
                                rowCopy.RemoveAllChildren <BookmarkStart>();
                                rowCopy.RemoveAllChildren <BookmarkEnd>();

                                foreach (var cell in rowCopy.Elements <TableCell>())
                                {
                                    cell.RemoveAllChildren <Paragraph>();
                                    cell.Append(new Paragraph());
                                }

                                table.Append(rowCopy);
                            }

                            for (int i = 0; i < Data.Count; i++)
                            {
                                var cell = table
                                           .Elements <TableRow>().ElementAt(mp.TableCellRow.Value + i)
                                           .Elements <TableCell>().ElementAt(mp.TableCellColumn.Value);

                                cell.RemoveAllChildren <Paragraph>();
                                Paragraph p   = new Paragraph();
                                Run       run = p.AppendChild(new Run());
                                run.AppendChild(new Text(Data[i]));
                                cell.Append(p);
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
        private void InsertButton_Click(object sender, RoutedEventArgs e)
        {
            string MethodName = "DynamicInsert";

            DataTempletItem item = DataTempletTree.SelectedItem as DataTempletItem;
            int?            cellrow = null, cellcolumn = null;

            DocumentViewModel.InsertBookMark(item.Name, ref cellrow, ref cellcolumn);

            GeneratorBase.MethodParams mp
                = new GeneratorBase.MethodParams(item.Name, item.Path, ((cellrow == null && cellcolumn == null) ? false : true), cellrow - 1, cellcolumn - 1);
            // DocumentViewModel.CallMethod(MethodName, mp);

            RecordViewModel.AddRecord(MethodName, mp);
        }
コード例 #3
0
 public void AddRecord(string MethodName, GeneratorBase.MethodParams mp)
 {
     Recorder.AddMethodCall(new MethodCall(MethodName, mp));
 }
コード例 #4
0
 public void CallMethod(string MethodName, GeneratorBase.MethodParams mp)
 {
     // DocumentModel.DynamicInsert(BookMarkName, DataModel.GetData(DataPath));
     DocumentModel.MethodDictionary[MethodName](mp);
 }
コード例 #5
0
        public override void DynamicInsert(GeneratorBase.MethodParams mp)
        {
            List <string> Data = DataModel.GetData(mp.DataPath);

            if (Data.Count == 0)
            {
                return;
            }

            Word.Bookmark bookmark = null;
            foreach (Word.Bookmark bm in _application.ActiveDocument.Bookmarks)
            {
                if (bm.Name == mp.BookMarkName)
                {
                    bookmark = bm;
                    break;
                } // if (bm.Name == BookMarkName)
            }     // foreach (Word.Bookmark bm in _application.ActiveDocument.Bookmarks)
            if (bookmark is null)
            {
                return;
            }// if (bookmark is null)
            else
            {
                if (bookmark.Column)
                {
                    Word.Table table = bookmark.Range.Tables[1];
                    Word.Cell  c     = bookmark.Range.Cells[1];

                    int distance = Data.Count - table.Rows.Count + c.RowIndex - 1;
                    if (distance > 0)
                    {
                        for (int i = 0; i < distance; i++)
                        {
                            table.Rows.Add();
                        }
                    }
                    int index       = 0;
                    int columnindex = c.ColumnIndex;
                    while (c != null)
                    {
                        if (index == Data.Count)
                        {
                            break;
                        }
                        if (c.ColumnIndex == columnindex)
                        {
                            c.Range.Text = Data[index++];
                        }

                        c = c.Next;
                    } // while (c != null)
                }     // if (bookmark.Column)
                else
                {
                    for (int i = 0; i < Data.Count; i++)
                    {
                        bookmark.Range.Text += Data[i];
                    }
                } // elif (!bookmark.Column)
            }     // elif (bookmark is not null)
        }