Source Code for Me (s-c.me)

Allows you to paste souce code to blogs! Adapted for Twitter! Here is Search Form in case you missed your code.
Code:
Selected Language:
Show Linenumbers:
Short link for Twitter:
HTML:

HTML view:

Copy Source | Copy HTML
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Text.RegularExpressions;// регулярные выражения
  9. using System.IO;//работа с файлами
  10.  
  11. namespace BestApplicationEvah
  12. {
  13.     public partial class WebBrowser_I : WebBrowser
  14.     {
  15.         public WebBrowser_I()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         /// <summary>
  21.         /// Временная директория в которую складываются все файлы отправляемые на печать.
  22.         /// </summary>
  23.         private string printdirectory = "Rprint";
  24.  
  25.         /// <summary> Временная директория в которую складываются все файлы отправляемые на печать. </summary>
  26.         public string PrintDir { get { return printdirectory; } set { printdirectory = value; } }
  27.  
  28.         /// <summary>
  29.         /// Функция преобразования html в правильный формат для показа в doc
  30.         /// </summary>        
  31.         /// <param name="file">Название файла. Желательно с расширением doc</param>
  32.         /// <param name="HTML">Html для преобразований</param>
  33.         /// <returns></returns>
  34.         private string HtmlToDocFile(ref string file, string HTML)
  35.         {
  36.             /*** много кода ***/
  37.         }
  38.  
  39.         /// <summary>
  40.         /// Функция сохраняет текущую страницу, как указанный файл и открывает его
  41.         /// </summary>
  42.         /// <param name="file">Имя создаваемого файла, должно иметь расширение DOC</param>
  43.         public void OpenAsDoc(string file)
  44.         {
  45.             this.OpenAsDoc(file, false);
  46.         }
  47.  
  48.         /// <summary>
  49.         /// Функция сохраняет текущую страницу, как указанный файл и открывает его
  50.         /// </summary>
  51.         /// <param name="file">Имя создаваемого файла, должно иметь расширение DOC</param>
  52.         /// <param name="newWindow">Открыть файл в новом окне?</param>
  53.         public void OpenAsDoc(string file, bool newWindow)
  54.         {
  55.             string err = this.HtmlToDocFile(ref file, this.DocumentText);
  56.             if (!String.IsNullOrEmpty(err))
  57.             {
  58.                 //вывод сообщения об ошибке
  59.                 MessageBox.Show(err, "Ошибка");
  60.             }
  61.  
  62.             //и отображаем доковский файл в броузере
  63.             this.Navigate(Directory.GetCurrentDirectory() + "/"+ this.printdirectory + "/" + file,newWindow);
  64.         }
  65.  
  66.         /// <summary>
  67.         /// Открытие HTML в MS Word...
  68.         /// </summary>
  69.         /// <param name="file">Название файла для сохранения информации</param>
  70.         public void OpenInWord(string file){
  71.             //создадим из контента файл
  72.             string err = this.HtmlToDocFile(ref file, this.DocumentText);
  73.             if (!String.IsNullOrEmpty(err))
  74.             {
  75.                 //вывод сообщения об ошибке
  76.                 MessageBox.Show(err, "Ошибка");
  77.             }
  78.  
  79.             try
  80.             {
  81.                 //Create an object for missing values. This will be passed when ever we don’t want to pass value
  82.                 Object missing = System.Reflection.Missing.Value;
  83.                 //Objects for true and false to be used in the word document for passing true or false.
  84.                 //Object true = true;
  85.                 //Object false = false;
  86.                 //Creating objects of word and document
  87.                 Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
  88.                 Microsoft.Office.Interop.Word.Document oWordDoc = new Microsoft.Office.Interop.Word.Document();
  89.                 object fileName = Directory.GetCurrentDirectory() + "/" + this.printdirectory + "/" + file;
  90.                 // You can keep it true if you want to open the file in readonly mode
  91.                 object readOnly = false;
  92.                 // we can keep it false if you want to open the file but not make it invisible
  93.                 object isVisible = true;
  94.                 //открытие файла
  95.                 oWordDoc = oWord.Documents.Open(ref fileName, ref missing, ref
  96.                   readOnly, ref missing, ref missing, ref missing, ref
  97.                   missing, ref missing, ref missing, ref missing, ref
  98.                   missing, ref isVisible, ref missing, ref missing, ref
  99.                   missing);
  100.                 //делаемся видимыми
  101.                 oWord.Application.Visible = true;
  102.                 //oWord.ShowMe();//смысл функции остался неизвестным
  103.                 //автопечать
  104.                 //oWord.PrintOut(ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
  105.                 //    ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
  106.                 //    ref missing, ref missing);
  107.             }
  108.             catch(Exception WordExc)
  109.             {
  110.                 MessageBox.Show(WordExc.Message, "Ошибка при работа с MS Word");
  111.             }
  112.         }
  113.     }
  114. }




Based on Manoli.Net's CodeFormatter. Made by Topbot (c) 2008-2012