private void DeleteFirstPage()
 {
     MSWord.Selection objSelection = winword.Selection;
     objSelection.GoTo(MSWord.WdGoToItem.wdGoToPage, MSWord.WdGoToDirection.wdGoToAbsolute, 1, 1);
     objSelection.Bookmarks[@"\Page"].Select();
     objSelection.Delete();
 }
示例#2
0
文件: UtilWord.cs 项目: vijju1608/VRF
        // 定位到指定的书签位置
        #region GoToBookMark
        /// <summary>
        /// 定位到指定的书签位置
        /// </summary>
        /// <param name="selection"></param>
        /// <param name="markName"></param>
        public static void GoToBookMark(ref Word.Selection selection, string markName)
        {
            object gotoWhat     = Word.WdGoToItem.wdGoToBookmark;
            object missing      = Type.Missing;
            object bookMarkName = markName;

            selection.GoTo(ref gotoWhat, ref missing, ref missing, ref bookMarkName);
        }
示例#3
0
        private void ResetGuangBiao(Word.Application wordApp)
        {
            object dummy = System.Reflection.Missing.Value;
            object what  = Word.WdGoToItem.wdGoToLine;
            object which = Word.WdGoToDirection.wdGoToFirst;
            object count = 1;

            Word.Selection ws = wordApp.Selection;
            ws.GoTo(ref what, ref which, ref count, ref dummy);
        }
示例#4
0
        public void GotoBookmark(string strBookmark)
        {
            if (m_pSelection == null)
            {
                if (m_pDoc == null)
                {
                    m_pDoc = m_pApp.ActiveDocument;
                }
                if (m_pApp == null)
                {
                    return;
                }

                m_pDoc.Select();
                m_pSelection = m_pApp.Selection;
                if (m_pSelection == null)
                {
                    return;
                }
            }

            m_pSelection.GoTo(-1, Type.Missing, Type.Missing, strBookmark);
            m_pSelection.Collapse(0);
        }
示例#5
0
        public void InsertPicture(string strFileName, MSWord.WdParagraphAlignment hAlign, string bookmark)
        {
            if (bookmark == "")
            {
                if (m_pDoc == null)
                {
                    m_pDoc = m_pApp.ActiveDocument;
                }
                if (m_pDoc == null)
                {
                    return;
                }

                m_pDoc.Select();
                m_pSelection = m_pApp.Selection;
                if (m_pSelection == null)
                {
                    return;
                }

                m_pSelection.Collapse(0);
            }
            else
            {
                m_pDoc.Select();
                m_pSelection = m_pApp.Selection;
                if (m_pSelection == null)
                {
                    return;
                }

                m_pSelection.GoTo(-1, Type.Missing, Type.Missing, bookmark);
            }

            MSWord.ParagraphFormat pParFormat = m_pSelection.ParagraphFormat;
            if (pParFormat == null)
            {
                return;
            }
            pParFormat.Alignment = hAlign;
            MSWord.InlineShapes shapes = m_pSelection.InlineShapes;
            if (shapes == null)
            {
                return;
            }
            shapes.AddPicture(strFileName, false, true);
        }
示例#6
0
        public void Format_vipLS()
        {
            // Инициализация Word
            this.Cursor = Cursors.WaitCursor;
            Word.Application o_Word      = new Word.Application();
            Word.Document    o_Doc       = new Word.Document();
            string           d_PrintName = o_Word.ActivePrinter;
            string           n_PrintName = comboBox1.SelectedItem.ToString();

            if (chkVisible.Checked)
            {
                o_Word.Visible = false;
            }
            else
            {
                o_Word.Visible = true;
            }

            //Открытие и редактирование документа
            Object filename              = txtFrom.Text + "\\vips.txt";
            Object confirmConversions    = Type.Missing;
            Object readOnly              = Type.Missing;
            Object addToRecentFiles      = Type.Missing;
            Object passwordDocument      = Type.Missing;
            Object passwordTemplate      = Type.Missing;
            Object revert                = Type.Missing;
            Object writePasswordDocument = Type.Missing;
            Object writePasswordTemplate = Type.Missing;
            Object format                = Type.Missing;
            Object encoding              = Microsoft.Office.Core.MsoEncoding.msoEncodingOEMCyrillicII;
            Object visible               = Type.Missing;
            Object openConflictDocument  = Type.Missing;
            Object openAndRepair         = Type.Missing;
            Object documentDirection     = Type.Missing;
            Object noEncodingDialog      = Type.Missing;

            if (!System.IO.File.Exists(filename.ToString()))
            {
                o_Word.Visible = true;
                MessageBox.Show("Файл " + filename.ToString() + " не найден.", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            o_Word.Documents.Open(ref filename,
                                  ref confirmConversions,
                                  ref readOnly,
                                  ref addToRecentFiles,
                                  ref passwordDocument,
                                  ref passwordTemplate,
                                  ref revert,
                                  ref writePasswordDocument,
                                  ref writePasswordTemplate,
                                  ref format,
                                  ref encoding,
                                  ref visible,
                                  ref openConflictDocument,
                                  ref openAndRepair,
                                  ref documentDirection,
                                  ref noEncodingDialog);

            o_Doc = o_Word.Documents.Application.ActiveDocument;
            //o_Doc.PageSetup.PaperSize = Word.WdPaperSize.wdPaperA3;
            o_Doc.PageSetup.PageWidth    = o_Word.CentimetersToPoints(29.7f);
            o_Doc.PageSetup.PageHeight   = o_Word.CentimetersToPoints(42f);
            o_Doc.PageSetup.LeftMargin   = o_Word.CentimetersToPoints(1.27f);
            o_Doc.PageSetup.RightMargin  = o_Word.CentimetersToPoints(1.27f);
            o_Doc.PageSetup.TopMargin    = o_Word.CentimetersToPoints(1.27f);
            o_Doc.PageSetup.BottomMargin = o_Word.CentimetersToPoints(1.27f);
            Word.Find      o_Find = o_Word.Selection.Find;
            Word.Selection o_Sel  = o_Word.Selection;

            o_Sel.WholeStory();
            o_Sel.Font.Size = 9;

            o_Find.ClearFormatting();
            o_Find.Replacement.ClearFormatting();
            Object p_findText = "Нереализованная отриц.";

            if (o_Find.Execute(ref p_findText,
                               MatchCase: false,
                               MatchWholeWord: false,
                               MatchWildcards: false,
                               MatchSoundsLike: Type.Missing,
                               MatchAllWordForms: false,
                               Forward: true,
                               Wrap: Type.Missing,
                               Format: false,
                               ReplaceWith: Type.Missing, Replace: Type.Missing))
            {
                o_Sel.EndKey(Unit: Word.WdUnits.wdLine, Extend: Type.Missing);
                o_Sel.HomeKey(Unit: Word.WdUnits.wdStory, Extend: Word.WdMovementType.wdExtend);
                o_Sel.Delete();
                o_Sel.Delete();
            }
            else
            {
                o_Find.ClearFormatting();
                o_Find.Replacement.ClearFormatting();
                Object s_findText = "Расходы по процентам";
                if (o_Find.Execute(ref s_findText,
                                   MatchCase: false,
                                   MatchWholeWord: false,
                                   MatchWildcards: false,
                                   MatchSoundsLike: Type.Missing,
                                   MatchAllWordForms: false,
                                   Forward: true,
                                   Wrap: Type.Missing,
                                   Format: false,
                                   ReplaceWith: Type.Missing, Replace: Type.Missing))
                {
                    o_Sel.EndKey(Unit: Word.WdUnits.wdLine, Extend: Type.Missing);
                    o_Sel.HomeKey(Unit: Word.WdUnits.wdStory, Extend: Word.WdMovementType.wdExtend);
                    o_Sel.Delete();
                    o_Sel.Delete();
                }
                else
                {
                    MessageBox.Show("Текст поиска не найден.", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    o_Word.Visible = true;
                    return;;
                }
            }

            //int pars = o_Doc.Paragraphs.Count;// узнаем количество строк в документе


            int PagesCount = o_Word.Documents.Application.ActiveDocument.Content.ComputeStatistics(Word.WdStatistic.wdStatisticPages);

            for (int i = 1; i <= PagesCount; i++)
            {
                o_Sel.GoTo(Word.WdGoToItem.wdGoToPage, Word.WdGoToDirection.wdGoToAbsolute, PagesCount, i);
                o_Sel.HomeKey(Unit: Word.WdUnits.wdLine, Extend: Type.Missing);
                o_Sel.MoveRight(Unit: Type.Missing, Count: 68, Extend: Word.WdMovementType.wdMove);
                o_Sel.ColumnSelectMode = true;
                o_Sel.MoveRight(Unit: Type.Missing, Count: 85, Extend: Word.WdMovementType.wdMove);
                o_Sel.MoveDown(Unit: Word.WdUnits.wdLine, Count: 109, Extend: Word.WdMovementType.wdMove);
                o_Sel.ColumnSelectMode = false;
                //MessageBox.Show("Остановка");
                o_Sel.Delete();
                //o_Sel.HomeKey(Unit: Word.WdUnits.wdLine, Extend: Type.Missing);
                //o_Sel.MoveDown(Unit: Word.WdUnits.wdLine, Count: 109, Extend: Type.Missing);
            }

            o_Doc.PageSetup.PageWidth  = o_Word.CentimetersToPoints(21f);
            o_Doc.PageSetup.PageHeight = o_Word.CentimetersToPoints(29.7f);
            //o_Doc.PageSetup.PaperSize = Word.WdPaperSize.wdPaperA4;
            o_Doc.PageSetup.LeftMargin = o_Word.CentimetersToPoints(2.35f);

            o_Word.ActivePrinter = n_PrintName;

            Object background           = Type.Missing;
            Object append               = Type.Missing;
            Object range                = Type.Missing;
            Object outputFileName       = Type.Missing;
            Object from                 = Type.Missing;
            Object to                   = Type.Missing;
            Object item                 = Type.Missing;
            Object copies               = Type.Missing;
            Object pages                = Type.Missing;
            Object pageType             = Type.Missing;
            Object printToFile          = Type.Missing;
            Object collate              = Type.Missing;
            Object fileName             = Type.Missing;
            Object activePrinterMacGX   = Type.Missing;
            Object manualDuplexPrint    = Type.Missing;
            Object printZoomColumn      = Type.Missing;
            Object printZoomRow         = Type.Missing;
            Object printZoomPaperWidth  = Type.Missing;
            Object printZoomPaperHeight = Type.Missing;

            o_Doc.PrintOut(ref background, ref append,
                           ref range, ref outputFileName, ref from, ref to,
                           ref item, ref copies, ref pages, ref pageType,
                           ref printToFile, ref collate, ref activePrinterMacGX,
                           ref manualDuplexPrint, ref printZoomColumn, ref printZoomRow,
                           ref printZoomPaperWidth, ref printZoomPaperHeight);

            o_Word.ActivePrinter = d_PrintName;

            Thread.Sleep(2000);

            Object saveChanges    = Word.WdSaveOptions.wdDoNotSaveChanges;
            Object originalFormat = Type.Missing;
            Object routeDocument  = Type.Missing;

            ((Word._Application)o_Word).Quit(ref saveChanges,
                                             ref originalFormat, ref routeDocument);
            o_Word = null;

            this.Cursor = Cursors.Default;
            tSSlb.Text  = "Файл " + filename + " отправлен на " + n_PrintName;
        }
示例#7
0
        public void ConvertToTable(string strText, int row_cnt = -1, int col_cnt = -1, bool bSetBorders = true, string bookmark = "")
        {
            string strReturn  = "" + (char)10;
            bool   bUseReturn = false;

            if (strText.IndexOf(strReturn) >= 0)
            {
                bUseReturn = true;
            }

            strText = strText.Replace(strReturn, "#enter#");

            if (bookmark == "")
            {
                if (m_pDoc == null)
                {
                    m_pDoc = m_pApp.ActiveDocument;
                }
                if (m_pDoc == null)
                {
                    return;
                }

                m_pDoc.Select();
                m_pSelection = m_pApp.Selection;
                if (m_pSelection == null)
                {
                    return;
                }

                m_pSelection.Collapse(0);

                object varInfo = m_pSelection.get_Information(MSWord.WdInformation.wdWithInTable);
                if (Convert.ToBoolean(varInfo) == true)
                {
                    m_pDoc.Select();
                    m_pSelection = m_pApp.Selection;
                    if (m_pSelection == null)
                    {
                        return;
                    }
                    m_pSelection.Collapse(0);
                }
            }
            else
            {
                m_pDoc.Select();
                m_pSelection = m_pApp.Selection;
                if (m_pSelection == null)
                {
                    return;
                }

                m_pSelection.GoTo(-1, Type.Missing, Type.Missing, bookmark);
            };

            m_pSelection.Font.Bold = 0;
            m_pSelection.Text      = strText;

            m_pSelection.Paragraphs.SpaceAfter      = 0;
            m_pSelection.Paragraphs.SpaceBefore     = 0;
            m_pSelection.Paragraphs.LineSpacingRule = MSWord.WdLineSpacing.wdLineSpaceSingle;


            if (row_cnt < 0 && col_cnt < 0)
            {
                m_pTable = m_pSelection.ConvertToTable(1, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                                       Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                                       Type.Missing, 0, 0);
            }
            else
            {
                m_pTable = m_pSelection.ConvertToTable(1, row_cnt, col_cnt, 0, 0,
                                                       Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                                       Type.Missing, 0, 0);
            }

            // выравниваем талицу (не содержимое!!!)
            if (m_pTable == null)
            {
                return;
            }

            MSWord.Rows pRows = m_pSelection.Rows;
            pRows.AllowBreakAcrossPages = 0;

            m_pSelection.Collapse(0);

            MSWord.Borders pBorders = m_pTable.Borders;
            if (pBorders == null)
            {
                return;
            }
            if (bSetBorders)
            {
                pBorders.Enable = 1;
            }
            else
            {
                pBorders.Enable = 0;
            }

            if (bUseReturn)
            {
                m_pTable.Select();
                MSWord.Selection sel = m_pApp.Selection;

                MSWord.Find find = sel.Find;
                find.ClearFormatting();
                MSWord.Replacement replace = find.Replacement;
                replace.ClearFormatting();
                find.Text              = "#enter#";
                replace.Text           = "^p";
                find.MatchCase         = false;
                find.MatchWholeWord    = false;
                find.MatchWildcards    = false;
                find.MatchSoundsLike   = false;
                find.MatchAllWordForms = false;
                find.Wrap              = MSWord.WdFindWrap.wdFindContinue;
                MSWord.WdReplace repl = MSWord.WdReplace.wdReplaceAll;
                find.Execute(find.Text, find.MatchCase, find.MatchWholeWord, find.MatchWildcards,
                             find.MatchSoundsLike, find.MatchAllWordForms, Type.Missing, find.Wrap, Type.Missing, replace.Text, repl);
            }
        }