Esempio n. 1
0
        private void ReadWord(string path, string groupID)
        {
            if (IsWork())
            {
                return;
            }
            _work = true;
            _syncContext.Post(PostLabelText, new TextPostData(lab_status, "載入中"));
            _syncContext.Post(PostProcess, 5);

            _app         = new Microsoft.Office.Interop.Word.Application();
            _app.Visible = false;
            _syncContext.Post(PostProcess, 25);

            object unknow = Type.Missing;
            object file   = path;

            _doc = _app.Documents.Open(ref file,
                                       ref unknow, ref unknow, ref unknow, ref unknow,
                                       ref unknow, ref unknow, ref unknow, ref unknow,
                                       ref unknow, ref unknow, ref unknow, ref unknow,
                                       ref unknow, ref unknow, ref unknow);
            _syncContext.Post(PostProcess, 50);

            string content = _doc.Content.Text;

            CloseDoc();

            _datas.Add(new WordData(content, groupID));

            _syncContext.Post(PostProcess, 100);
            _syncContext.Post(PostLabelText, new TextPostData(lab_status, "已完成"));
            _work = false;
        }
 public bool open(string wordFile)
 {
     this.objWordApp = new Microsoft.Office.Interop.Word.Application();
     if (this.objWordApp == null)
     {
         textBox1.AppendText("Error: Word could not be started. Check that your office installation and project references are correct.");
         return(false);
     }
     this.objWordApp.Visible = false;
     try
     {
         Microsoft.Office.Interop.Word.Document objDoc = this.objWordApp.Documents.Open(wordFile);
         if (objDoc.Tables.Count == 0)
         {
             textBox1.AppendText("Error: This document contains no tables");
             return(false);
         }
         Microsoft.Office.Interop.Word.Table tbl = objDoc.Tables[1];
         tbl.Range.Copy();
     }
     catch (Exception ex)
     {
         textBox1.AppendText("Error: " + ex.Message);
         return(false);
     }
     return(true);
 }
Esempio n. 3
0
        public static bool ReadWordText(Microsoft.Office.Interop.Word._Application app, string filePath, out string docText)
        {
            docText = string.Empty;
            try
            {
                Microsoft.Office.Interop.Word._Document doc = null;//实例化一个新的word文档
                object unknow             = Type.Missing;
                object paramSourceDocPath = filePath;
                object ConfirmConversions = false;
                object readOnly           = true;
                object AddToRecentFiles   = false;
                object Visible            = false;
                object Revert             = false;
                object Format             = Microsoft.Office.Interop.Word.WdOpenFormat.wdOpenFormatAuto;
                object OpenAndRepair      = false;
                object NoEncodingDialog   = true;
                doc = app.Documents.Open(ref paramSourceDocPath,
                                         ref ConfirmConversions, ref readOnly, ref AddToRecentFiles, ref unknow, ref unknow,
                                         ref Revert, ref unknow, ref unknow, ref Format, ref unknow,
                                         ref Visible, ref OpenAndRepair, ref NoEncodingDialog, ref unknow, ref unknow);

                if (doc != null)
                {
                    docText = doc.Content.Text + " ";//将全篇内容存入字符串中,最后补一个空格,表示文档能够打开
                    doc.Close(ref unknow, ref unknow, ref unknow);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(false);
        }
Esempio n. 4
0
        public static void PrintWordDot(string lv模板文件名, List <string> lv模板词汇, List <string> lv替换词汇)
        {
            object   path;       //文件路径
            string   strContent; //文件内容
            string   lvssss = Application.StartupPath + "\\Microsoft.Office.Interop.Word.dll";
            Assembly ass;
            string   lv模板文件名含路径 = Application.StartupPath + "\\" + lv模板文件名;
            Object   oMissing   = System.Reflection.Missing.Value;
            object   obj模板      = oMissing;
            object   obj;

            //获取并加载DLL类库中的程序集
            ass = Assembly.LoadFile(lvssss);

            obj = ass.CreateInstance("Microsoft.Office.Interop.Word.ApplicationClass");
            //获取类的类型:必须使用名称空间+类名称
            Microsoft.Office.Interop.Word._Application WordApp = obj as Microsoft.Office.Interop.Word._Application;
            WordApp.Visible = true;
            try
            {
                Microsoft.Office.Interop.Word._Document WordDoc = WordApp.Documents.Add(ref obj模板, ref oMissing, ref oMissing, ref oMissing);
                object FindText, ReplaceWith, Replace;
                for (int lvi = 0; lvi < lv模板词汇.Count; lvi++)
                {
                    WordDoc.Content.Find.Text = lv模板词汇[lvi];
                    //要查找的文本
                    FindText = lv模板词汇[lvi];
                    //替换文本
                    //ReplaceWith = strNewText;
                    ReplaceWith = lv替换词汇[lvi];

                    //wdReplaceAll - 替换找到的所有项。
                    //wdReplaceNone - 不替换找到的任何项。
                    //wdReplaceOne - 替换找到的第一项。
                    Replace = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll;


                    //移除Find的搜索文本和段落格式设置
                    WordDoc.Content.Find.ClearFormatting();
                    WordDoc.Content.Find.Execute(ref FindText, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref ReplaceWith, ref Replace, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                }
                WordDoc.PrintPreview();
                WordDoc.Saved = true;
                //关闭wordDoc文档
                WordDoc.Close(ref oMissing, ref oMissing, ref oMissing);
                //关闭wordApp组件对象
                WordApp.Quit(ref oMissing, ref oMissing, ref oMissing);
            }
            catch //(Exception ex)
            {
                WordApp.Quit(ref oMissing, ref oMissing, ref oMissing);
                throw;
            }
        }
Esempio n. 5
0
        public bool CreateWord(bool isVisible)
        {
            try
            {
                oWord = new Microsoft.Office.Interop.Word.Application();
                oWord.Visible = isVisible;

                return true;
            }
            catch ( Exception )
            {
                return false;
            }
        }
Esempio n. 6
0
        private void CloseDoc()
        {
            if (_doc != null)
            {
                _doc.Close();
                _doc = null;
            }

            if (_app != null)
            {
                _app.Quit();
                _app = null;
            }
        }
Esempio n. 7
0
        private void WriteWord(string filepath, string path, string content)
        {
            _app = new Microsoft.Office.Interop.Word.Application();
            _doc = _app.Documents.Open(filepath);

            _doc.Paragraphs.Last.Range.Font.Name = "新明細體";
            _doc.Paragraphs.Last.Range.ParagraphFormat.AddSpaceBetweenFarEastAndDigit = 0;
            _doc.Paragraphs.Last.Range.Text = content;


            Object Nothing     = System.Reflection.Missing.Value;
            object objWordName = path;

            _doc.SaveAs(ref objWordName, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
            CloseDoc();
        }
        //WebSocketSession resumeview_Server_Session;
        public file_Converting_Server()
        {
            word_Application_Count = 5;
            System.IO.StreamReader reader = new System.IO.StreamReader("settings.txt");
            int port_Int             = 2012;
            int given_Max_Connection = 100;

            while (!reader.EndOfStream)
            {
                string temp_SingleLine = reader.ReadLine();
                if (temp_SingleLine.Contains("Port"))
                {
                    string port_String = temp_SingleLine.Substring(temp_SingleLine.IndexOf(":") + 1);
                    int.TryParse(port_String, out port_Int);
                }
                if (temp_SingleLine.Contains("Max_Connection"))
                {
                    string max_Connection_String = temp_SingleLine.Substring(temp_SingleLine.IndexOf(":") + 1);
                    int.TryParse(max_Connection_String, out given_Max_Connection);
                }
            }
            reader.Close();

            this.Setup(new RootConfig(), new ServerConfig
            {
                Port = port_Int,
                Ip   = "Any",
                MaxConnectionNumber = given_Max_Connection,
                MaxCommandLength    = 100000,
                Mode = SuperSocket.SocketBase.SocketMode.Async,
                Name = "SuperWebSocket Server"
            }, SocketServerFactory.Instance);

            file_Paths = new System.Collections.Concurrent.ConcurrentQueue <string>();

            threads = new List <System.Threading.Thread>();
            for (int i = 0; i < word_Application_Count; ++i)
            {
                System.Threading.Thread temp_Thread = new System.Threading.Thread(new System.Threading.ThreadStart(start_Operation));
                temp_Thread.IsBackground = true;
                threads.Add(temp_Thread);
            }

            assign_The_Function_For_Events();
            app = new Microsoft.Office.Interop.Word.Application();
        }
Esempio n. 9
0
        string GetTextFromWordFile(string path)
        {
            Office.Word._Application appWord = null;
            Office.Word._Document    docWord = null;

            Object filename              = path;
            Object ConfirmConversions    = Missing.Value;
            Object ReadOnly              = true;
            Object AddToRecentFiles      = Missing.Value;
            Object PasswordDocument      = Missing.Value;
            Object PasswordTemplate      = Missing.Value;
            Object Revert                = Missing.Value;
            Object WritePasswordDocument = Missing.Value;
            Object WritePasswordTemplate = Missing.Value;
            Object Format                = Missing.Value;
            Object Encoding              = Missing.Value;
            Object Visible               = false;

            Object saveChanges    = false;
            Object originalFormat = null;
            Object routeDoc       = null;

            appWord         = new Office.Word.Application();
            appWord.Visible = false;
            docWord         = appWord.Documents.Open2000(ref filename, ref ConfirmConversions, ref ReadOnly,
                                                         ref AddToRecentFiles, ref PasswordDocument, ref PasswordTemplate,
                                                         ref Revert, ref WritePasswordDocument, ref WritePasswordTemplate,
                                                         ref Format, ref Encoding, ref Visible);
            if (docWord.ProtectionType == Office.Word.WdProtectionType.wdNoProtection)
            {
                docWord.ActiveWindow.Selection.WholeStory();
                docWord.ActiveWindow.Selection.Copy();
                GetClipboardContent();
            }
            else
            {
                curr_clpbrd_content = "";
            }
            appWord.ActiveDocument.Close(ref saveChanges, ref originalFormat, ref routeDoc);
            appWord.Quit(ref saveChanges, ref originalFormat, ref routeDoc);


            return(curr_clpbrd_content);
        }
        //method for using find a nd replace
        private void findAndReplace(Microsoft.Office.Interop.Word._Application application,
                                    object findText, object replaceText)
        {
            object matchCase         = true;
            object matchWholeWord    = true;
            object matchWildCards    = false;
            object matchSoundsLike   = false;
            object matchAllWordForms = false;
            object forward           = true;
            object format            = false;
            object matchKashida      = false;
            object matchDiacritics   = false;
            object matchAlefHamza    = false;
            object matchControl      = false;
            object replace           = 2;
            object wrap = 1;

            application.Selection.Find.Execute(ref findText, ref matchCase,
                                               ref matchWholeWord, ref matchWildCards, ref matchSoundsLike,
                                               ref matchAllWordForms, ref forward, ref wrap, ref format,
                                               ref replaceText, ref replace, ref matchKashida,
                                               ref matchDiacritics,
                                               ref matchAlefHamza, ref matchControl);
        }
Esempio n. 11
0
        /// <summary>
        /// 预览Word
        /// </summary>
        public string PreviewWord(string physicalPath, string url, string scode)
        {
            Microsoft.Office.Interop.Word._Application application = null;
            Microsoft.Office.Interop.Word._Document    doc         = null;
            application = new Microsoft.Office.Interop.Word.Application();
            object missing    = Type.Missing;
            object trueObject = true;

            application.Visible       = false;
            application.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;
            doc = application.Documents.Open(physicalPath, missing, trueObject, missing, missing, missing,
                                             missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
            //Save Excel to Html
            object format     = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML;
            string htmlName   = scode + ".html";//Path.GetFileNameWithoutExtension(physicalPath)
            String outputFile = Path.GetDirectoryName(physicalPath) + "\\" + htmlName;

            doc.SaveAs(outputFile, format, missing, missing, missing,
                       missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, missing,
                       missing, missing, missing, missing);
            doc.Close();
            application.Quit();
            return(Path.GetDirectoryName(Server.UrlDecode(url)) + "\\" + htmlName);
        }
Esempio n. 12
0
        public bool Quit()
        {
            try
            {
                object saveOption = Word.WdSaveOptions.wdDoNotSaveChanges;
                oWord.Quit(ref saveOption, ref Nothing, ref Nothing);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(oWord);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(oDoc);
                oWord = null;
                oDoc = null;
                odoc = null;
                GC.Collect();

                return true;
            }
            catch ( Exception )
            {
                return false;
            }
        }
Esempio n. 13
0
        private void BtnExportTP_Click(object sender, EventArgs e)
        {
            mf.wsm.Visible = true;
            mf.wsm.Update();

            Microsoft.Office.Interop.Word._Application oWord = null;
            try
            {
                oWord = new Microsoft.Office.Interop.Word.Application();
            }
            catch
            {
                mf.wsm.Visible = false;
                MessageBox.Show("На ПК не установлен пакет Microsoft Office Word 2007 или позднее. Экспорт невозможен.", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Microsoft.Office.Interop.Word._Document oDoc = null;
            try
            {
                oDoc = oWord.Documents.Add(Environment.CurrentDirectory + "\\templateTP.docx");
            }
            catch
            {
                mf.wsm.Visible = false;
                MessageBox.Show("Отсутствует файл шаблона тех. проекта \"templateTP.docx\". Экспорт невозможен.", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Microsoft.Office.Interop.Word.Table wordTable;
            Microsoft.Office.Interop.Word.Range bm;
            int row = 0;

            using (KPSZIContext db = new KPSZIContext())
            {
                #region Заполнение СФХ
                var listOfSFHs     = db.SFHs.ToList().Intersect(IS.listOfSFHs).ToList();
                var listOfSFHTypes = new List <SFHType>();

                foreach (SFH sfh in listOfSFHs)
                {
                    listOfSFHTypes.Add(sfh.SFHType);
                }
                listOfSFHTypes = listOfSFHTypes.Distinct().OrderBy(st => st.SFHTypeId).ToList();

                bm = oDoc.Bookmarks["SFH"].Range;
                bm.Tables.Add(bm, listOfSFHTypes.Count, 2, Type.Missing, Type.Missing);
                wordTable = bm.Tables[1];
                wordTable.Borders.InsideLineStyle       = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
                wordTable.Borders.OutsideLineStyle      = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
                wordTable.Rows.Alignment                = Microsoft.Office.Interop.Word.WdRowAlignment.wdAlignRowLeft;
                wordTable.Range.Cells.VerticalAlignment = Microsoft.Office.Interop.Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                wordTable.Range.Select();

                List <SFHType> lst = new List <SFHType>();

                row = 1;

                foreach (SFHType sfhtype in listOfSFHTypes)
                {
                    if (IS.listOfSFHs.Where(s => s.SFHType.Name == sfhtype.Name).ToList().Count == 0)
                    {
                        continue;
                    }

                    wordTable.Cell(row, 1).Range.Text = sfhtype.Name;
                    string sfhs = "";
                    foreach (SFH sfh in IS.listOfSFHs.Where(sfh => sfh.SFHType.Name == sfhtype.Name).ToList())
                    {
                        sfhs += sfh.Name + ", ";
                    }
                    sfhs = sfhs.TrimEnd(' ').TrimEnd(',');
                    wordTable.Cell(row, 2).Range.Text = sfhs;
                    row++;
                }

                #endregion

                #region Базовый набор мер
                bm = oDoc.Bookmarks["Basic_Set"].Range;
                bm.Tables.Add(bm, mf.dgvBasicMeas.Rows.Count + 1, 2, Type.Missing, Type.Missing);
                wordTable = bm.Tables[1];
                wordTable.Borders.InsideLineStyle       = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
                wordTable.Borders.OutsideLineStyle      = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
                wordTable.Columns.PreferredWidthType    = Microsoft.Office.Interop.Word.WdPreferredWidthType.wdPreferredWidthPercent;
                wordTable.Columns[1].PreferredWidth     = 6f;
                wordTable.Columns[2].PreferredWidth     = 94f;
                wordTable.Rows.Alignment                = Microsoft.Office.Interop.Word.WdRowAlignment.wdAlignRowLeft;
                wordTable.Rows[1].Alignment             = Microsoft.Office.Interop.Word.WdRowAlignment.wdAlignRowCenter;
                wordTable.Range.Cells.VerticalAlignment = Microsoft.Office.Interop.Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                wordTable.Range.Select();

                wordTable.Cell(1, 1).Range.Text = "№ п/п";
                wordTable.Cell(1, 2).Range.Text = "Наименование базовой меры";

                row = 2;
                foreach (DataGridViewRow dgvrow in mf.dgvBasicMeas.Rows)
                {
                    wordTable.Cell(row, 1).Range.Text   = (row - 1).ToString();
                    wordTable.Cell(row++, 2).Range.Text = dgvrow.Cells[1].Value.ToString();
                }

                #endregion

                #region Адаптация базового набора мер
                bm = oDoc.Bookmarks["Adaptive_Set"].Range;
                bm.Tables.Add(bm, StageMeasures.ListOfExcludedMeasures.Count + 1, 2, Type.Missing, Type.Missing);
                wordTable = bm.Tables[1];
                wordTable.Borders.InsideLineStyle       = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
                wordTable.Borders.OutsideLineStyle      = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
                wordTable.Columns.PreferredWidthType    = Microsoft.Office.Interop.Word.WdPreferredWidthType.wdPreferredWidthPercent;
                wordTable.Columns[1].PreferredWidth     = 6f;
                wordTable.Columns[2].PreferredWidth     = 94f;
                wordTable.Rows.Alignment                = Microsoft.Office.Interop.Word.WdRowAlignment.wdAlignRowLeft;
                wordTable.Rows[1].Alignment             = Microsoft.Office.Interop.Word.WdRowAlignment.wdAlignRowCenter;
                wordTable.Range.Cells.VerticalAlignment = Microsoft.Office.Interop.Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                wordTable.Range.Select();

                wordTable.Cell(1, 1).Range.Text = "№ п/п";
                wordTable.Cell(1, 2).Range.Text = "Наименование меры";

                row = 2;
                foreach (GISMeasure gm in StageMeasures.ListOfExcludedMeasures)
                {
                    wordTable.Cell(row, 1).Range.Text   = (row - 1).ToString();
                    wordTable.Cell(row++, 2).Range.Text = gm.ToString();
                }
                #endregion

                #region Уточненение адаптированного базового набора мер
                //Вывод УБИ-меры
                bm = oDoc.Bookmarks["Thr_Meas"].Range;
                bm.Tables.Add(bm, mf.dgvThrMeas.Rows.Count + 1, 3, Type.Missing, Type.Missing);
                wordTable = bm.Tables[1];
                wordTable.Borders.InsideLineStyle       = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
                wordTable.Borders.OutsideLineStyle      = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
                wordTable.Columns.PreferredWidthType    = Microsoft.Office.Interop.Word.WdPreferredWidthType.wdPreferredWidthPercent;
                wordTable.Columns[1].PreferredWidth     = 6f;
                wordTable.Columns[2].PreferredWidth     = 19f;
                wordTable.Columns[3].PreferredWidth     = 75f;
                wordTable.Rows.Alignment                = Microsoft.Office.Interop.Word.WdRowAlignment.wdAlignRowLeft;
                wordTable.Rows[1].Alignment             = Microsoft.Office.Interop.Word.WdRowAlignment.wdAlignRowCenter;
                wordTable.Range.Cells.VerticalAlignment = Microsoft.Office.Interop.Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                wordTable.Range.Select();

                wordTable.Cell(1, 1).Range.Text = "№ п/п";
                wordTable.Cell(1, 2).Range.Text = "Наименование угрозы";
                wordTable.Cell(1, 3).Range.Text = "Меры по нейтрализации УБИ";

                row = 2;
                foreach (DataGridViewRow dgvrow in mf.dgvThrMeas.Rows)
                {
                    wordTable.Cell(row, 1).Range.Text   = (row - 1).ToString();
                    wordTable.Cell(row, 2).Range.Text   = dgvrow.Cells[1].Value.ToString();
                    wordTable.Cell(row++, 3).Range.Text = dgvrow.Cells[2].Value.ToString();
                }

                //Вывод добавляемых мер
                bm = oDoc.Bookmarks["Add_Meas"].Range;
                bm.Tables.Add(bm, StageMeasures.ListOfAddedMeasures.Count + 1, 2, Type.Missing, Type.Missing);
                wordTable = bm.Tables[1];
                wordTable.Borders.InsideLineStyle       = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
                wordTable.Borders.OutsideLineStyle      = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
                wordTable.Columns.PreferredWidthType    = Microsoft.Office.Interop.Word.WdPreferredWidthType.wdPreferredWidthPercent;
                wordTable.Columns[1].PreferredWidth     = 6f;
                wordTable.Columns[2].PreferredWidth     = 94f;
                wordTable.Rows.Alignment                = Microsoft.Office.Interop.Word.WdRowAlignment.wdAlignRowLeft;
                wordTable.Rows[1].Alignment             = Microsoft.Office.Interop.Word.WdRowAlignment.wdAlignRowCenter;
                wordTable.Range.Cells.VerticalAlignment = Microsoft.Office.Interop.Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                wordTable.Range.Select();

                wordTable.Cell(1, 1).Range.Text = "№ п/п";
                wordTable.Cell(1, 2).Range.Text = "Наименование добавляемой меры";

                row = 2;
                foreach (GISMeasure gm in StageMeasures.ListOfAddedMeasures)
                {
                    wordTable.Cell(row, 1).Range.Text   = (row - 1).ToString();
                    wordTable.Cell(row++, 2).Range.Text = gm.ToString();
                }
                #endregion

                #region Итоговый перечень мер
                bm = oDoc.Bookmarks["Final_Set"].Range;
                bm.Tables.Add(bm, mf.dgvConcreteMeas.Rows.Count + 1, 2, Type.Missing, Type.Missing);
                wordTable = bm.Tables[1];
                wordTable.Borders.InsideLineStyle       = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
                wordTable.Borders.OutsideLineStyle      = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
                wordTable.Columns.PreferredWidthType    = Microsoft.Office.Interop.Word.WdPreferredWidthType.wdPreferredWidthPercent;
                wordTable.Columns[1].PreferredWidth     = 6f;
                wordTable.Columns[2].PreferredWidth     = 94f;
                wordTable.Rows.Alignment                = Microsoft.Office.Interop.Word.WdRowAlignment.wdAlignRowLeft;
                wordTable.Rows[1].Alignment             = Microsoft.Office.Interop.Word.WdRowAlignment.wdAlignRowCenter;
                wordTable.Range.Cells.VerticalAlignment = Microsoft.Office.Interop.Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                wordTable.Range.Select();

                wordTable.Cell(1, 1).Range.Text = "№ п/п";
                wordTable.Cell(1, 2).Range.Text = "Наименование меры";

                row = 2;
                foreach (DataGridViewRow dgvrow in mf.dgvConcreteMeas.Rows)
                {
                    wordTable.Cell(row, 1).Range.Text   = (row - 1).ToString();
                    wordTable.Cell(row++, 2).Range.Text = dgvrow.Cells[1].Value.ToString();
                }
                #endregion

                #region Перечень предлагаемых СЗИ
                bm = oDoc.Bookmarks["SZIs_Set"].Range;
                bm.Tables.Add(bm, mf.dgvSZIs.Rows.Count + 1, 5, Type.Missing, Type.Missing);
                wordTable = bm.Tables[1];
                wordTable.Borders.InsideLineStyle    = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
                wordTable.Borders.OutsideLineStyle   = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
                wordTable.Columns.PreferredWidthType = Microsoft.Office.Interop.Word.WdPreferredWidthType.wdPreferredWidthPercent;
                wordTable.Columns[1].PreferredWidth  = 4.5f;
                wordTable.Columns[2].PreferredWidth  = 36.3f;
                wordTable.Columns[3].PreferredWidth  = 19.6f;
                wordTable.Columns[4].PreferredWidth  = 25.7f;
                wordTable.Columns[5].PreferredWidth  = 13.6f;

                wordTable.Rows.Alignment                = Microsoft.Office.Interop.Word.WdRowAlignment.wdAlignRowLeft;
                wordTable.Rows[1].Alignment             = Microsoft.Office.Interop.Word.WdRowAlignment.wdAlignRowCenter;
                wordTable.Range.Cells.VerticalAlignment = Microsoft.Office.Interop.Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                wordTable.Range.Select();

                wordTable.Cell(1, 1).Range.Text = "№";
                wordTable.Cell(1, 2).Range.Text = "Наименование СЗИ";
                wordTable.Cell(1, 3).Range.Text = "Вид";
                wordTable.Cell(1, 4).Range.Text = "Сертификат";
                wordTable.Cell(1, 5).Range.Text = "Уровень контроля отсутствия НДВ";


                row = 2;
                foreach (DataGridViewRow dgvrow in mf.dgvSZIs.Rows)
                {
                    wordTable.Cell(row, 1).Range.Text   = (row - 1).ToString();
                    wordTable.Cell(row, 2).Range.Text   = dgvrow.Cells[1].Value.ToString();
                    wordTable.Cell(row, 3).Range.Text   = dgvrow.Cells[2].Value.ToString();
                    wordTable.Cell(row, 4).Range.Text   = dgvrow.Cells[3].Value.ToString();
                    wordTable.Cell(row++, 5).Range.Text = dgvrow.Cells[4].Value.ToString();
                }
                #endregion

                #region Мера-СЗИ
                bm = oDoc.Bookmarks["Meas_SZIs"].Range;
                bm.Tables.Add(bm, mf.dgvMeasSZIs.Rows.Count + 1, 3, Type.Missing, Type.Missing);
                wordTable = bm.Tables[1];
                wordTable.Borders.InsideLineStyle    = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
                wordTable.Borders.OutsideLineStyle   = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
                wordTable.Columns.PreferredWidthType = Microsoft.Office.Interop.Word.WdPreferredWidthType.wdPreferredWidthPercent;
                wordTable.Columns[1].PreferredWidth  = 6f;
                wordTable.Columns[2].PreferredWidth  = 60f;
                wordTable.Columns[3].PreferredWidth  = 34f;

                wordTable.Rows.Alignment                = Microsoft.Office.Interop.Word.WdRowAlignment.wdAlignRowLeft;
                wordTable.Rows[1].Alignment             = Microsoft.Office.Interop.Word.WdRowAlignment.wdAlignRowCenter;
                wordTable.Range.Cells.VerticalAlignment = Microsoft.Office.Interop.Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                wordTable.Range.Select();

                wordTable.Cell(1, 1).Range.Text = @"№ п\п";
                wordTable.Cell(1, 2).Range.Text = "Название меры";
                wordTable.Cell(1, 3).Range.Text = "Перечень СЗИ";


                row = 2;
                foreach (DataGridViewRow dgvrow in mf.dgvMeasSZIs.Rows)
                {
                    wordTable.Cell(row, 1).Range.Text   = (row - 1).ToString();
                    wordTable.Cell(row, 2).Range.Text   = dgvrow.Cells[1].Value.ToString();
                    wordTable.Cell(row++, 3).Range.Text = dgvrow.Cells[2].Value.ToString();
                }
                #endregion

                #region Замена слов
                mf.FindAndReplace(oWord, "{ИМЯ_ИС}", IS.ISName);
                mf.FindAndReplace(oWord, "{КЗ}", IS.GISClass);

                #endregion


                oDoc.Activate();
                oWord.Visible = true;
            }
            mf.wsm.Visible = false;
        }
Esempio n. 14
0
 public ExportWord()
 {
     oWord = new Microsoft.Office.Interop.Word.Application();
 }
        private static void ShowForeground(Microsoft.Office.Interop.Word._Application app)
        {
            IntPtr handler = FindWindow(null, app.Caption);

            SetForegroundWindow(handler);
        }
Esempio n. 16
0
        public void BtnExportWord_CLick(object sender, EventArgs e)
        {
            mf.wsm.Visible = true;
            mf.wsm.Update();

            Microsoft.Office.Interop.Word._Application wordApp = null;
            try
            {
                wordApp = new Microsoft.Office.Interop.Word.Application();
            }
            catch
            {
                mf.wsm.Visible = false;
                MessageBox.Show("На ПК не установлен пакет Microsoft Office Word 2007 или позднее. Экспорт невозможен.", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Microsoft.Office.Interop.Word.Document  wordDoc;
            Microsoft.Office.Interop.Word.Paragraph wordParag;


            wordDoc = wordApp.Documents.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing);

            wordParag                            = wordDoc.Paragraphs.Add();
            wordParag.Range.Text                 = "Требования к параметрам настройки средств защиты информации в ИС \"" + IS.ISName + "\"";
            wordParag.Range.Font.Name            = "Times New Roman";
            wordParag.Range.Font.Size            = 18;
            wordParag.Range.Font.Bold            = 1;
            wordParag.Range.Paragraphs.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
            wordParag.Range.InsertParagraphAfter(); wordParag.Range.InsertParagraphAfter();
            using (KPSZIContext db = new KPSZIContext())
            {
                foreach (MeasureGroup mg in db.MeasureGroups.ToList())
                {
                    //Группа мер
                    bool isMeasureGroupInTable = false;
                    for (int i = mf.dgvConfigNMeasures.Rows.Count - 1; i >= 0; i--)
                    {
                        if (mf.dgvConfigNMeasures.Rows[i].Cells[0].Value.ToString().Contains(mg.ShortName + "."))
                        {
                            isMeasureGroupInTable = true;
                        }
                    }
                    if (!isMeasureGroupInTable)
                    {
                        continue;
                    }
                    wordParag.Range.Text                 = '\t' + mg.Name;
                    wordParag.Range.Font.Name            = "Times New Roman";
                    wordParag.Range.Font.Size            = 16;
                    wordParag.Range.Font.Bold            = 1;
                    wordParag.Range.Font.Italic          = 0;
                    wordParag.Range.Paragraphs.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphJustify;

                    wordParag.Range.InsertParagraphAfter();

                    foreach (DataGridViewRow dgvr in mf.dgvConfigNMeasures.Rows)
                    {
                        if (dgvr.Cells[0].Value.ToString().Contains(mg.ShortName + "."))
                        {
                            //Мера
                            wordParag.Range.Text                 = '\t' + dgvr.Cells[0].Value.ToString();
                            wordParag.Range.Font.Name            = "Times New Roman";
                            wordParag.Range.Font.Size            = 14;
                            wordParag.Range.Font.Bold            = 1;
                            wordParag.Range.Font.Italic          = 0;
                            wordParag.Range.Paragraphs.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphJustify;

                            wordParag.Range.InsertParagraphAfter();

                            //тип сзи
                            string         szis     = "";
                            string         measure  = dgvr.Cells[0].Value.ToString();
                            List <SZISort> szisorts = db.GisMeasures.ToList().Where(m => (m.MeasureGroup.ShortName + "." + m.Number + " " + m.Description) == measure).First().SZISorts.ToList();

                            var listOfSZIs = db.SZIs.ToList().Intersect(IS.listOfSZIs).ToList();
                            foreach (SZI sz in listOfSZIs)
                            {
                                SZI m = db.SZIs.Where(t => t.SZIId == sz.SZIId).First();
                                sz.SZISorts = m.SZISorts.ToList();
                            }
                            foreach (SZISort s in szisorts)
                            {
                                szis += s.Name + ": " + listOfSZIs.Where(szi => szi.SZISorts.Contains(s)).First().Name + "; ";
                            }
                            if (szis != "")
                            {
                                szis = szis.Substring(0, szis.Length - 2) + ".";

                                wordParag.Range.Text                 = '\t' + szis;
                                wordParag.Range.Font.Name            = "Times New Roman";
                                wordParag.Range.Font.Size            = 14;
                                wordParag.Range.Font.Bold            = 0;
                                wordParag.Range.Font.Italic          = 1;
                                wordParag.Range.Paragraphs.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphJustify;

                                wordParag.Range.InsertParagraphAfter();
                            }


                            string[] configOptions = dgvr.Cells[1].Value.ToString().Split('\n');
                            for (int i = 0; i < configOptions.Length - 1; i++)
                            {
                                //Параметры
                                char divider = i == configOptions.Length - 2 ? '.' : ';';
                                wordParag.Range.Text                 = "\t– " + configOptions[i] + divider;
                                wordParag.Range.Font.Name            = "Times New Roman";
                                wordParag.Range.Font.Size            = 12;
                                wordParag.Range.Font.Bold            = 0;
                                wordParag.Range.Font.Italic          = 0;
                                wordParag.Range.Paragraphs.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphJustify;
                                wordParag.Range.InsertParagraphAfter();
                            }
                            wordParag.Range.InsertParagraphAfter();
                        }
                        else
                        {
                            continue;
                        }
                    }
                    wordParag.Range.InsertParagraphAfter();
                }
                wordApp.Visible = true;

                mf.wsm.Visible = false;
            }
        }