Beispiel #1
0
        static void Main(string[] args)
        {
            //string path = "test-doc.rtf";
            //string readText = File.ReadAllText(path);
            //var docin = DocX.Load(RtfDocx(readText));
            //var tins = docin.Tables[0];

            string fileName = @"exempleWord.docx";

            doc = DocX.Create(fileName);

            doc.PageLayout.Orientation = Orientation.Landscape;

            //Formatting Text Paragraph
            Formatting textParagraphFormat = new Formatting
            {
                //font family
                FontFamily = new Font("Times New Roman"),
                //font size
                Size = 10D,
                //Spaces between characters
                //Spacing = 1
            };



            //Create Table with 2 rows and 3 columns.
            var   header = new string[] { "Было", "Статус", "Стало" };
            Table t      = doc.AddTable(2, header.Length);

            t.Alignment = Alignment.center;
            t.SetWidthsPercentage(new float[] { 45F, 10F, 45F }, doc.PageWidth - 40);
            // t.Design = TableDesign.TableGrid;SetColumnWidth(t, new int[] { 45, 10, 45 }, doc.PageWidth);
            //t.AutoFit = AutoFit.Fixed;
            //            t.SetWidthsPercentage(new float[] { 45F,10F, 45F },doc.PageWidth);

            SetColumnWidth(t, new int[] { 45, 10, 45 }, doc.PageWidth - 40);
            FillRow(t.Rows[0], header, System.Drawing.Color.LightGray, true);


            Globals.Load_CradleAPI();
            Globals.GetArgs();
            //&TBL2&ПД&BL0&БЛ1&&Рзд ПД-37&ТЛ-1
            var bl1   = Globals.Args[3];
            var bl2   = Globals.Args[4];
            var phase = Globals.Args[2];
            var proj  = new Project();
            var ldap  = new LDAPInformation();

            if (!proj.Connect(Globals.CRADLE_CDS_HOST, Globals.CRADLE_PROJECT_CODE, Globals.CRADLE_USERNAME, Globals.CRADLE_PASSWORD, true,
                              Cradle.Server.Connection.API_LICENCE, ldap, false))
            {
                return;
            }
            ;
            var project = proj;

            proj.SetBaselineMode(CAPI_BASELINE_MODE.SPECIFIED, bl2);
            Console.WriteLine("Начало обработки проекта " + proj.Title);

            int row = 1;

            Item root = new Item(CAPI_INFO.NOTE, "Раздел ТЗ " + phase);

            root.Identity = Globals.Args[6];
            root.Baseline = bl2;
            root.Version  = "01";
            root.Draft    = " ";
            if (root.Open(false))
            {
                root.Close();
                OutItems(t, root, ref row);
            }
            //SetColumnWidth(t,new int[] { 45, 10, 45 }, doc.PageWidth);

            doc.InsertTable(t);
            //SetColumnWidth(t, new int[] { 45, 10, 45 }, doc.PageWidth);
            //doc.InsertDocument(docin);
            doc.Save();
            Process.Start("WINWORD.EXE", fileName);
        }
Beispiel #2
0
        static void OutItems(Table gtable, Item it, ref int row)
        {
            int myrow = row;

            //sl.InsertRow();
            //row++;
            Console.Write(".");

            {
                LinkedItem linked_item  = null;
                List       linked_items = null;
                Navigation nav          = null;
                int        num_linked_items;
                nav = new Navigation();

                nav.Type = "Включает";

                nav.Direction = CAPI_XREF_DIR.ONLY_DOWN;
                // Get linked items
                if (it.GetLinkedItems(CAPI_LINKS.ALL, nav, CAPI_INFO.NOTE, CAPI_SUBTYPE.NULL, "", null, default(int), default(QueryStereotypeTest), default(QueryModelviewTest), null, out linked_items))
                {
                    num_linked_items = linked_items.Length;
                    var loopTo = num_linked_items - 1;
                    for (int i = 0; i <= loopTo; i++)
                    {
                        if (linked_items.GetElement(i, out linked_item))
                        {
                            var            l_it       = linked_item.Item;
                            Frame          frame      = null;
                            string         frame_text = null;
                            BinaryContents frame_tbl  = null;
                            BinaryContents frame_pic  = null;
                            DocX           docin      = null;
                            Table          tins       = null;
                            Picture        pins       = null;
                            Paragraph      par        = null;
                            l_it.Open(false);
                            if (!l_it.GetFrame("TEXT", out frame))
                            {
                                return;
                            }

                            // Get TEXT frame contents
                            if (!frame.GetContents(out frame_text))
                            {
                                return;
                            }
                            if (l_it.NoteType != "Титульный лист")
                            {
                                if (!l_it.GetFrame("Таблица", out frame))
                                {
                                    return;
                                }

                                // Get  frame contents
                                if (!frame.GetContents(out frame_tbl))
                                {
                                    return;
                                }
                                if (frame_tbl.Size != 0)
                                {
                                    byte[] memdocx = new byte[frame_tbl.Size];
                                    IntPtr pnt     = frame_tbl.Data;

                                    Marshal.Copy(pnt, memdocx, 0, memdocx.Length);
                                    docin = DocX.Load(BRtfDocx(memdocx));
                                    tins  = docin.Tables[0];
                                }
                                if (!l_it.GetFrame("Рисунок", out frame))
                                {
                                    return;
                                }

                                // Get  frame contents
                                if (!frame.GetContents(out frame_pic))
                                {
                                    return;
                                }
                                if (frame_pic.Size != 0)
                                {
                                    byte[] memdocx = new byte[frame_pic.Size];
                                    IntPtr pnt     = frame_pic.Data;

                                    Marshal.Copy(pnt, memdocx, 0, memdocx.Length);
                                    Stream stream = BRtfImage(memdocx);
                                    stream.Position = 0;

                                    Image img = doc.AddImage(stream);
                                    pic = img.CreatePicture();
                                    double scale = (double)pic.Width / (double)pic.Height;
                                    pic.WidthInches  = 3;
                                    pic.HeightInches = pic.WidthInches / scale;
                                }
                            }

                            l_it.Close();

                            gtable.InsertRow();
                            row++;
                            gtable.Rows[row].Cells[1].Paragraphs.First().Append(l_it.Identity);
                            //gtable.Rows[row].Cells[2].InsertParagraph().Append(frame_text);
                            gtable.Rows[row].Cells[2].Paragraphs.First().Append(frame_text);
                            if (frame_tbl != null)
                            {
                                if (frame_tbl.Size != 0)
                                {
                                    gtable.Rows[row].Cells[2].InsertParagraph().InsertTableAfterSelf(tins);
                                    gtable.Rows[row].Cells[2].InsertParagraph(docin.InsertParagraph(""));
                                }
                            }
                            if (frame_pic != null)
                            {
                                if (frame_pic.Size != 0)
                                {
                                    //Image img = doc.AddImage(bRtfDocx(memdocx));
                                    //Picture pic = img.CreatePicture();
                                    //gtable.Rows[row].Cells[0].Paragraphs.First().InsertPicture(pic);
                                    gtable.Rows[row].Cells[2].InsertParagraph().InsertPicture(pic);
                                    //gtable.Rows[row].Cells[2].InsertParagraph(doc.InsertParagraph(""));
                                }
                            }
                            //sl.InsertRow();
                        }
                    }
                    linked_items.Dispose();
                }

                nav.Type = "Содержит";

                nav.Direction = CAPI_XREF_DIR.ONLY_DOWN;
                // Get linked items
                if (it.GetLinkedItems(CAPI_LINKS.ALL, nav, CAPI_INFO.NOTE, CAPI_SUBTYPE.NULL, "", null, default(int), default(QueryStereotypeTest), default(QueryModelviewTest), null, out linked_items))
                {
                    num_linked_items = linked_items.Length;
                    var loopTo = num_linked_items - 1;
                    for (int i = 0; i <= loopTo; i++)
                    {
                        if (linked_items.GetElement(i, out linked_item))
                        {
                            var l_it = linked_item.Item;
                            gtable.InsertRow();
                            row++;
                            OutItems(gtable, l_it, ref row);
                        }
                    }
                    linked_items.Dispose();
                }

                gtable.Rows[myrow].Cells[1].Paragraphs.First().Append(it.Identity);
                gtable.Rows[myrow].Cells[2].Paragraphs.First().Append(it.Name);
                //sl.InsertRow();

                return;
            }
        }