private void Client_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) { if (e.Error == null) { var contentDispositionString = ((System.Net.WebClient)sender).ResponseHeaders["Content-Disposition"]; ContentDisposition contentDisposition = new ContentDisposition(contentDispositionString); var tempPath = System.IO.Path.GetTempPath(); var actualFile = string.Format("{0}\\{1}", tempPath, contentDisposition.FileName); File.Copy(tempFileName, actualFile, true); Microsoft.Office.Interop.Word._Application oWord; Microsoft.Office.Interop.Word._Document oDoc; oWord = new Microsoft.Office.Interop.Word.Application(); var fileNameObject = actualFile as object; oWord.Documents.Open(ref fileNameObject); oWord.Visible = true; oWord.Activate(); } this.Close(); Application.Exit(); }
public void Compare(string orginal, string target) { Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application { Visible = true }; word.DocumentOpen += doc => { doc.Compare(target); doc.Close(); word.Activate(); }; word.Documents.Open(orginal); }
private void button9_Click(object sender, EventArgs e) { Microsoft.Office.Interop.Word.Application wordApp = null; wordApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application") as Microsoft.Office.Interop.Word.Application; wordApp.Visible = true; wordApp.Documents.Add(); wordApp.Activate(); Microsoft.Office.Core.COMAddIns addins = wordApp.COMAddIns; foreach (Microsoft.Office.Core.COMAddIn addin in addins) { Msg.ShowInfo(addin.ProgId); } }
private void bbProposalLetter_ItemClick(object sender, ItemClickEventArgs e) { try { SplashScreenManager.ShowForm(this, typeof(WaitForm1), true, true, false); SplashScreenManager.Default.SetWaitFormDescription("Bitte warten…"); if (ObjEProject == null) { ObjEProject = new EProject(); } if (ObjBProject == null) { ObjBProject = new BProject(); } ObjEProject = ObjBProject.GetPath(ObjEProject); var FolderPath = new DirectoryInfo(ObjEProject.TemplatePath).GetFiles("V-015*.dotx", SearchOption.AllDirectories).OrderByDescending(d => d.LastWriteTimeUtc).First(); Object oTemplatePath = ObjEProject.TemplatePath + "\\" + FolderPath; if (File.Exists(Convert.ToString(oTemplatePath))) { if (!Utility.fileIsOpen(Convert.ToString(oTemplatePath))) { Microsoft.Office.Interop.Word.Application ap = new Microsoft.Office.Interop.Word.Application(); ap.Documents.Open(oTemplatePath); ap.Visible = true; ap.Activate(); } else { throw new Exception("Bitte schließen Sie die Angebots-Dokumente aller Projekte"); } } } catch (Exception ex) { if (ex.Message.Contains("Sequence contains no elements")) { XtraMessageBox.Show("Die erforderliche Dokumentenvorlage ist nicht eingestellt!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } finally { SplashScreenManager.CloseForm(false); } }
private void bbAufmass_ItemClick(object sender, ItemClickEventArgs e) { try { SplashScreenManager.ShowForm(this, typeof(WaitForm1), true, true, false); SplashScreenManager.Default.SetWaitFormDescription("Bitte warten…"); if (ObjEProject == null) { ObjEProject = new EProject(); } if (ObjBProject == null) { ObjBProject = new BProject(); } ObjEProject = ObjBProject.GetPath(ObjEProject); Object oTemplatePath = ObjEProject.TemplatePath + "\\Aufmass_Template.dotx"; if (File.Exists(Convert.ToString(oTemplatePath))) { if (!Utility.fileIsOpen(Convert.ToString(oTemplatePath))) { Microsoft.Office.Interop.Word.Application ap = new Microsoft.Office.Interop.Word.Application(); ap.Documents.Open(oTemplatePath); ap.Visible = true; ap.Activate(); } else { throw new Exception("Bitte schließen Sie die Aufmass-Dokumente aller Projekte"); } } SplashScreenManager.CloseForm(false); } catch (Exception ex) { SplashScreenManager.CloseForm(false); Utility.ShowError(ex); } }
/// <summary>This function opens page text in Microsoft Word for editing. /// Just close Word after editing, and the revised text will appear in /// Page.text variable.</summary> /// <remarks>Appropriate PIAs (Primary Interop Assemblies) for available MS Office /// version must be installed and referenced in order to use this function. Follow /// instructions in "Compile and Run.bat" file to reference PIAs properly in compilation /// command, and then recompile the framework. Redistributable PIAs can be downloaded from /// http://www.microsoft.com/downloads/results.aspx?freetext=Office%20PIA</remarks> public void ReviseInMSWord() { #if MS_WORD_INTEROP if (string.IsNullOrEmpty(text)) throw new WikiBotException(Bot.Msg("No text on page to revise in Microsoft Word.")); Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application(); app.Visible = true; object mv = System.Reflection.Missing.Value; object template = mv; object newTemplate = mv; object documentType = Microsoft.Office.Interop.Word.WdDocumentType.wdTypeDocument; object visible = true; Microsoft.Office.Interop.Word.Document doc = app.Documents.Add(ref template, ref newTemplate, ref documentType, ref visible); doc.Words.First.InsertBefore(text); text = null; Microsoft.Office.Interop.Word.DocumentEvents_Event docEvents = (Microsoft.Office.Interop.Word.DocumentEvents_Event) doc; docEvents.Close += new Microsoft.Office.Interop.Word.DocumentEvents_CloseEventHandler( delegate { text = doc.Range(ref mv, ref mv).Text; doc.Saved = true; } ); app.Activate(); while (text == null); text = Regex.Replace(text, "\r(?!\n)", "\r\n"); app = null; doc = null; GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers(); Bot.LogEvent( Bot.Msg("Text of \"{0}\" page was revised in Microsoft Word."), title); #else throw new WikiBotException(Bot.Msg("Page.ReviseInMSWord() function requires MS " + "Office PIAs to be installed and referenced. Please, see remarks in function's " + "documentation in \"Documentation.chm\" file for additional instructions.\n")); #endif }
public void Créer_Document(string Fichier_Modele, bool OptionPDF) { if (Fichier_Modele.Length == 0) { return; } int K = 0; //Nombre de paragraphes dans le document string fichier = Fichier_Modele + ".docx"; App = new Microsoft.Office.Interop.Word.Application(); Doc = new Microsoft.Office.Interop.Word.Document(); //Ouverture du modèle désigné ou celui par défaut if (System.IO.File.Exists(CheminTemp + "\\Modeles\\" + fichier)) { App.Documents.Open(CheminTemp + "\\Modeles\\" + fichier); Doc = App.ActiveDocument; } else { Doc = App.Documents.Add(); Doc.Activate(); } //Traitement des informations foreach (ModeleDoc md_Zone in listeModeleDoc) { //Traitement d'une zone if (md_Zone.Type_Modele == Type_Modele.ZONE) { //Traitement des lignes dans la zone foreach (ModeleDoc md_Ligne in listeModeleDoc) { if (md_Ligne.Type_Modele == Type_Modele.LIGNE && md_Ligne.Parent_ID == md_Zone.ID) { Doc.Paragraphs.Add(); Microsoft.Office.Interop.Word.Range table = Doc.Paragraphs[K + 1].Range; if (md_Ligne.Contenu == "SAUT_LIGNE") { table.InsertBreak(Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak); } else { List <ModeleDoc> listeColonne = new List <ModeleDoc>(); //Détermine le nombre de colonnes composant la ligne foreach (ModeleDoc md_Colonne in listeModeleDoc) { if (md_Colonne.Type_Modele == Type_Modele.COLONNE && md_Colonne.Parent_ID == md_Ligne.ID) { listeColonne.Add(md_Colonne); } } //Création du tableau Microsoft.Office.Interop.Word.Table Tb = Doc.Tables.Add(table, 1, listeColonne.Count); Tb.PreferredWidth = 100; Tb.PreferredWidthType = Microsoft.Office.Interop.Word.WdPreferredWidthType.wdPreferredWidthPercent; //Traitement des colonnes dans la ligne for (int col = 0; col < listeColonne.Count; col++) { ModeleDoc md_Col = listeColonne[col]; Tb.Cell(1, col).Range.Text = md_Col.Contenu; //Alignement { if (md_Col.Alignement == Alignement.Gauche) { Tb.Cell(1, col).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft; } if (md_Col.Alignement == Alignement.Centré) { Tb.Cell(1, col).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; } if (md_Col.Alignement == Alignement.Droit) { Tb.Cell(1, col).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight; } if (md_Col.Alignement == Alignement.Justifié) { Tb.Cell(1, col).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphJustify; } } //Bordures { if (md_Col.Bordure.Contains("L")) { Tb.Cell(1, col).Range.Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderLeft].LineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle; } if (md_Col.Bordure.Contains("R")) { Tb.Cell(1, col).Range.Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderRight].LineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle; } if (md_Col.Bordure.Contains("H")) { Tb.Cell(1, col).Range.Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderTop].LineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle; } if (md_Col.Bordure.Contains("B")) { Tb.Cell(1, col).Range.Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderBottom].LineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle; } } } //Redimensionne les colonnes for (int col = 0; col < listeColonne.Count; col++) { Tb.Columns[col].PreferredWidthType = Microsoft.Office.Interop.Word.WdPreferredWidthType.wdPreferredWidthPercent; Tb.Columns[col].PreferredWidth = float.Parse(listeColonne[col].Taille.ToString()); } } } } } } //Sauvegarde du fichier { string Nom_Doc = string.Format("{0:yyyyMMddHHmmsssfff}", DateTime.Now); string fichier_dest = CheminTemp + "\\" + Nom_Doc + ".docx"; Doc.SaveAs(fichier_dest); if (OptionPDF) { string fichier_pdf = CheminTemp + "\\" + Nom_Doc + ".pdf"; Doc.ExportAsFixedFormat(fichier_pdf, paramExportFormat, paramOpenAfterExport, paramExportOptimizeFor, paramExportRange, paramStartPage, paramEndPage, paramExportItem, paramIncludeDocProps, paramKeepIRM, paramCreateBookmarks, paramDocStructureTags, paramBitmapMissingFonts, paramUseISO19005_1); System.Diagnostics.Process.Start(fichier_pdf); //Ouverture Doc.SaveAs(fichier_dest); App.Quit(); } else { App.Visible = true; App.Activate(); } } }