private void DeleteFirstPage() { MSWord.Selection objSelection = winword.Selection; objSelection.GoTo(MSWord.WdGoToItem.wdGoToPage, MSWord.WdGoToDirection.wdGoToAbsolute, 1, 1); objSelection.Bookmarks[@"\Page"].Select(); objSelection.Delete(); }
public void InvertCase() { string result = ""; char inverso; //Percorre cada caracte da string que recebeu a selecao foreach (char caracter in Selecao.Text) { //testa se o caracter é letra. Se for testa e inverte, senao add ao resultado if (Char.IsLetter(caracter)) { if (Char.IsLower(caracter)) { inverso = Char.ToUpper(caracter); } else { inverso = Char.ToLower(caracter); } result += inverso; } else { if (caracter != Char.Parse("\r")) { result += caracter; } } } Selecao.Delete(); Selecao.InsertAfter(result); }
private void button1_Click(object sender, RibbonControlEventArgs e) { Word.Document doc = (Word.Document)Globals.ThisAddIn.Application.ActiveDocument; Word.Selection sel = (Word.Selection)Globals.ThisAddIn.Application.Selection; sel.Text.Trim(); if (sel.Text.IndexOf("$") == 0) { System.Diagnostics.Debug.WriteLine("oi"); File.WriteAllText("C:/oi.txt", sel.Text); //sempre tem erro aqui // Start the child process System.Diagnostics.Process p = new System.Diagnostics.Process(); // Redirect the output stream of the child process. p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.FileName = "cmd.exe"; p.StartInfo.Arguments = "/C java -jar C:/mathtoweb.jar C:/oi.txt -rep -unicode -line -stdout"; p.Start(); // Do not wait for the child process to exit before // reading to the end of its redirected stream. // p.WaitForExit(); // Read the output stream first and then wait. string output = p.StandardOutput.ReadToEnd(); p.WaitForExit(); string data = getBetween(output, "<math ", "</math>"); if (data != "") { data = "<math " + data + "</math>"; System.Windows.Forms.Clipboard.SetText(data); sel.Paste(); sel.OMaths[1].Type = Word.WdOMathType.wdOMathInline; } } else { string texto = File.ReadAllText("C:/oi.txt"); sel.Delete(); System.Windows.Forms.Clipboard.SetText(texto); sel.Paste(); } }
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; }
private void Format_otvet() { // Инициализация 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 + "\\otvet.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); //Word.Document Doc = new Word.Document(); o_Doc = o_Word.Documents.Application.ActiveDocument; 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_Find.ClearFormatting(); o_Find.Replacement.ClearFormatting(); o_Find.Text = "ФИО: Переходченко М.В."; //Object wrap = Type.Missing; ; //Object replace = Type.Missing; ; o_Find.Execute(FindText: Type.Missing, 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_Find.ClearFormatting(); o_Find.Replacement.ClearFormatting(); o_Find.Text = "----------------------------------------------------------------------------^p----------------------------------------------------------------------------"; o_Find.Replacement.Text = "----------------------------------------------------------------------------^m----------------------------------------------------------------------------"; Object wrap = Word.WdFindWrap.wdFindContinue; Object replace = Word.WdReplace.wdReplaceAll; o_Find.Execute(FindText: Type.Missing, MatchCase: false, MatchWholeWord: false, MatchWildcards: false, MatchSoundsLike: Type.Missing, MatchAllWordForms: false, Forward: true, Wrap: wrap, Format: false, ReplaceWith: Type.Missing, Replace: replace); o_Find.ClearFormatting(); o_Find.Replacement.ClearFormatting(); 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); int PagesCount = o_Word.Documents.Application.ActiveDocument.Content.ComputeStatistics(Word.WdStatistic.wdStatisticPages); 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 + " Всего страниц: " + PagesCount.ToString(); }
public void Format_vedLic() { // Инициализация Word this.Cursor = Cursors.WaitCursor; Word.Application o_Word = new Word.Application(); Word.Document o_Doc = new Word.Document(); if (chkVisible.Checked) { o_Word.Visible = false; } else { o_Word.Visible = true; } string dt_pick = dTPicker.Value.ToString("dd.MM.yyyy"); string dt_pick_save = dTPicker.Value.ToString("MMdd"); string[] Filelst = System.IO.Directory.GetFiles(txtFrom.Text, "day*.txt"); if (System.IO.File.Exists(Filelst.ToString())) { o_Word.Visible = true; MessageBox.Show("Файл " + Filelst.ToString() + " не найден.", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //Открытие и редактирование документа //Object o_filename = txtFrom.Text + "\\DAY"+dt_pick_save+".TXT"; Object o_filename = Filelst[0]; 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; o_Word.Documents.Open(ref o_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.Orientation = Word.WdOrientation.wdOrientLandscape; o_Doc.PageSetup.LeftMargin = o_Word.CentimetersToPoints(1f); o_Doc.PageSetup.RightMargin = o_Word.CentimetersToPoints(1f); o_Doc.PageSetup.TopMargin = o_Word.CentimetersToPoints(1f); o_Doc.PageSetup.BottomMargin = o_Word.CentimetersToPoints(1f); Word.Find o_Find = o_Word.Selection.Find; Word.Selection o_Sel = o_Word.Selection; o_Sel.WholeStory(); //выделяет весь текст o_Sel.Font.Size = 4; o_Sel.HomeKey(Unit: Word.WdUnits.wdStory, Extend: Word.WdMovementType.wdMove); //o_Sel.TypeText("Ведомость открытых лицевых счетов "+dt_pick+" г."+"\r\r"); o_Sel.TypeText("Ведомость открытых лицевых счетов " + dt_pick + " г."); o_Sel.TypeParagraph(); o_Sel.TypeParagraph(); o_Sel.EndKey(Unit: Word.WdUnits.wdLine, Extend: Word.WdMovementType.wdExtend); o_Sel.Delete(); //Поиск и замена o_Find.ClearFormatting(); o_Find.Replacement.ClearFormatting(); o_Find.Text = "^m"; o_Find.Replacement.Text = " "; Object wrap = Word.WdFindWrap.wdFindContinue; Object replace = Word.WdReplace.wdReplaceAll; o_Find.Execute(FindText: Type.Missing, MatchCase: false, MatchWholeWord: false, MatchWildcards: false, MatchSoundsLike: Type.Missing, MatchAllWordForms: false, Forward: true, Wrap: wrap, Format: false, ReplaceWith: Type.Missing, Replace: replace); o_Find.ClearFormatting(); o_Find.Replacement.ClearFormatting(); o_Sel.EndKey(Unit: Word.WdUnits.wdStory, Extend: Type.Missing); o_Sel.TypeParagraph(); o_Sel.TypeParagraph(); o_Sel.TypeText("Руководитель ________________ Алпеева Галина Ивановна"); o_Sel.TypeParagraph(); o_Sel.TypeParagraph(); o_Sel.TypeText("Гл.бухгалтер ________________ Зотова Елена Сергеевна"); //Сохранение в формате .doc Object s_fileName = txtFrom.Text + "\\arch\\DAY" + dt_pick_save + ".doc"; Object fileformat = Word.WdSaveFormat.wdFormatDocument; o_Doc.SaveAs(ref s_fileName, ref fileformat); //Выход из Word без сохранения 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 = "Файл " + o_filename + " сохранен в " + s_fileName; }