private void MonthClosed() { Microsoft.Office.Interop.PowerPoint.Application pptApp = new Microsoft.Office.Interop.PowerPoint.Application(); Microsoft.Office.Core.MsoTriState ofalse = Microsoft.Office.Core.MsoTriState.msoFalse; Microsoft.Office.Core.MsoTriState otrue = Microsoft.Office.Core.MsoTriState.msoTrue; pptApp.Visible = otrue; pptApp.Activate(); Microsoft.Office.Interop.PowerPoint.Presentations ps = pptApp.Presentations; Microsoft.Office.Interop.PowerPoint.Presentation p = ps.Open(@"F:\Mess Managment\Mess Notice\PPTFormatNotice\MonthClosed.pptx", ofalse, ofalse, otrue); System.Diagnostics.Debug.Print(p.Windows.Count.ToString()); }
/// <summary> /// Reads PPT and PPTX file types and extracts the words in each file /// Requires: The file path is in ppt or pptx format only /// </summary> /// <param name="filenameWithPath">path of PPT and PPTX document including filename</param> /// <exception cref="PlatformNotSupportedException">Thrown when the file to read is not of supported /// presentation format. </exception> /// <returns> /// A Dictionary where the Key contains the filename and the Value contains the entire wordlist /// </returns> private static Dictionary <string, List <string> > readPPTFiles(string filenameWithPath) { Contract.Requires <PlatformNotSupportedException>(System.IO.Path.GetExtension(filenameWithPath).Equals(".ppt") || System.IO.Path.GetExtension(filenameWithPath).Equals(".pptx")); List <string> result = new List <string>(); Dictionary <string, List <string> > listresult = new Dictionary <string, List <string> >(); Microsoft.Office.Interop.PowerPoint.Application PowerPoint_App = new Microsoft.Office.Interop.PowerPoint.Application(); Microsoft.Office.Interop.PowerPoint.Presentations multi_presentations = PowerPoint_App.Presentations; Microsoft.Office.Interop.PowerPoint.Presentation presentation = multi_presentations.Open(filenameWithPath); for (int i = 0; i < presentation.Slides.Count; i++) { foreach (var item in presentation.Slides[i + 1].Shapes) { var shape = (Microsoft.Office.Interop.PowerPoint.Shape)item; if (shape.HasTextFrame == MsoTriState.msoTrue) { if (shape.TextFrame.HasText == MsoTriState.msoTrue) { var textRange = shape.TextFrame.TextRange; string text = textRange.Text.ToLower().Trim().ToString(); result.AddRange(text.Split(new char[] { ' ', '\n', '\t', '\r' })); } } } } PowerPoint_App.Quit(); listresult.Add(filenameWithPath, result); return(listresult); }
private void allocPowerPoint() { if (avaPoawrPoint) { pptApp = new Microsoft.Office.Interop.PowerPoint.Application(); pptPres = pptApp.Presentations; } }
public void OpenPowerPoint() { powerpoint = new Microsoft.Office.Interop.PowerPoint.Application(); powerpoint.Visible = MsoTriState.msoTrue; //Prevent Office Assistant from displaying alert messages: bAssistantOn = powerpoint.Assistant.On; powerpoint.Assistant.On = false; presentationSet = powerpoint.Presentations; }
private void createSlideFromTemplate() { //Create a new presentation based on a template. objApp = new Microsoft.Office.Interop.PowerPoint.Application(); objApp.Visible = MsoTriState.msoTrue; objPresSet = objApp.Presentations; objPres = objPresSet.Open(strTemplate, MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue); objSlides = objPres.Slides; }
private void bunifuThinButton23_Click(object sender, EventArgs e) { Microsoft.Office.Interop.PowerPoint.Application pptApp = new Microsoft.Office.Interop.PowerPoint.Application(); Microsoft.Office.Core.MsoTriState ofalse = Microsoft.Office.Core.MsoTriState.msoFalse; Microsoft.Office.Core.MsoTriState otrue = Microsoft.Office.Core.MsoTriState.msoTrue; pptApp.Visible = otrue; pptApp.Activate(); Microsoft.Office.Interop.PowerPoint.Presentations ps = pptApp.Presentations; Microsoft.Office.Interop.PowerPoint.Presentation p = ps.Open(@"F:\Mess Managment\Mess Notice\PPTFormatNotice\PenaltyMeal.pptx", ofalse, ofalse, otrue); System.Diagnostics.Debug.Print(p.Windows.Count.ToString()); }
private void freePowerPoint() { if (avaPoawrPoint) { if (pptPres != null) { pptPres = null; } pptApp.Quit(); } }
private void button1_Click(object sender, EventArgs e) { Microsoft.Office.Interop.PowerPoint.Application pptApp = new Microsoft.Office.Interop.PowerPoint.Application(); Microsoft.Office.Core.MsoTriState ofalse = Microsoft.Office.Core.MsoTriState.msoFalse; Microsoft.Office.Core.MsoTriState otrue = Microsoft.Office.Core.MsoTriState.msoTrue; pptApp.Visible = otrue; pptApp.Activate(); Microsoft.Office.Interop.PowerPoint.Presentations ps = pptApp.Presentations; Microsoft.Office.Interop.PowerPoint.Presentation p = ps.Open(@"F:\Mess Managment\PersonalCostV.1.1.00V.pptx", ofalse, ofalse, otrue); System.Diagnostics.Debug.Print(p.Windows.Count.ToString()); MessageBox.Show(pptApp.ActiveWindow.Caption); }
public override bool PPT2HTML(string sourcePath, string targetPath, string targetRelativeDirectory) { Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType targetFileType = Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsJPG; object missing = Type.Missing; Microsoft.Office.Interop.PowerPoint.Application pptApp = null; Microsoft.Office.Interop.PowerPoint.Presentation presentation = null; try { if (!sourcePath.EndsWith(".ppt") && !sourcePath.EndsWith(".pptx")) { return(false); } if (File.Exists(targetPath)) { File.Delete(targetPath); } object target = targetPath; pptApp = new Microsoft.Office.Interop.PowerPoint.ApplicationClass(); Microsoft.Office.Interop.PowerPoint.Presentations presentations = pptApp.Presentations; presentation = presentations.Open(sourcePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse); presentation.SaveAs(targetPath, targetFileType, Microsoft.Office.Core.MsoTriState.msoTrue); } catch (Exception e) { Log.LogInfo("ppt转换html:", e); return(false); } finally { if (presentation != null) { presentation.Close(); presentation = null; } if (pptApp != null) { pptApp.Quit(); pptApp = null; } GC.Collect(); GC.WaitForPendingFinalizers(); } pptHelper(targetPath, targetRelativeDirectory); return(true); }
public static bool CreatePowerPoint() { try { //create powerpoint ppPresens = ppApp.Presentations; objPres = ppPresens.Add(); objSlides = objPres.Slides; } catch (Exception e) { Console.WriteLine("Creating PowerPoint Failed: " + fileName + "\n" + e.Message); } return(result); }
public void ClosePowerPoint() { if (powerpoint != null) { // Reenable Office Assisant, if it was on: if (bAssistantOn) { powerpoint.Assistant.On = true; powerpoint.Assistant.Visible = false; } powerpoint.Quit(); presentationSet = null; powerpoint = null; } }
protected override void OnStart(CustomForm Sender) { Microsoft.Office.Interop.PowerPoint.Application pptApp = new Microsoft.Office.Interop.PowerPoint.Application(); Microsoft.Office.Core.MsoTriState ofalse = Microsoft.Office.Core.MsoTriState.msoFalse; Microsoft.Office.Core.MsoTriState otrue = Microsoft.Office.Core.MsoTriState.msoTrue; pptApp.Visible = otrue; pptApp.Activate(); Microsoft.Office.Interop.PowerPoint.Presentations ps = pptApp.Presentations; opApp = new Microsoft.Office.Interop.PowerPoint.Application(); opApp.SlideShowNextSlide += OpApp_SlideShowNextSlide; ppPresentation = ps.Open(@"c:\a.pptx", ofalse, ofalse, otrue); settings = ppPresentation.SlideShowSettings; settings.RangeType = Microsoft.Office.Interop.PowerPoint.PpSlideShowRangeType.ppShowSlideRange; settings.StartingSlide = StartingSlide; settings.Run(); }
public override void Convert(string src, string dest, out string msg) { msg = null; try { if (string.IsNullOrEmpty(src)) { msg = "源文件不能为空"; return; } var contentType = MimeTypes.GetContentType(src); if (contentType != "application/mspowerpoint") { msg = "源文件应为powerpoint文件"; return; } if (string.IsNullOrEmpty(dest)) { msg = "目标路径不能为空"; return; } if (!File.Exists(src)) { msg = "文件不存在"; return; } if (IsPasswordProtected(src)) { msg = "存在密码"; return; } app = new Microsoft.Office.Interop.PowerPoint.Application(); presentations = app.Presentations; presentation = presentations.Open(src.ToString(), Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse); presentation.ExportAsFixedFormat(dest.ToString(), Microsoft.Office.Interop.PowerPoint.PpFixedFormatType.ppFixedFormatTypePDF); // presentation.ExportAsFixedFormat(outputFile, PowerPoint.PpFixedFormatType.ppFixedFormatTypePDF, PowerPoint.PpFixedFormatIntent.ppFixedFormatIntentScreen, MsoTriState.msoFalse, PowerPoint.PpPrintHandoutOrder.ppPrintHandoutVerticalFirst, PowerPoint.PpPrintOutputType.ppPrintOutputSlides, MsoTriState.msoFalse, null, PowerPoint.PpPrintRangeType.ppPrintAll, "", false, false, false, false, false, null); } catch (Exception e) { release(); throw new ConvertException(e.Message); } release(); }
private static string GetPPTContent(string path) { string fileExtension = Path.GetExtension(path).ToLower(); if (fileExtension.Contains("pptx")) { StringBuilder sb = new StringBuilder(); PresentationDocument pptx = PresentationDocument.Open(path, false); foreach (SlidePart slide in pptx.PresentationPart.SlideParts) { sb.Append(slide.Slide.InnerText).Append(Environment.NewLine); } return(sb.ToString()); } else { Microsoft.Office.Interop.PowerPoint.Application PowerPoint_App = new Microsoft.Office.Interop.PowerPoint.Application(); Microsoft.Office.Interop.PowerPoint.Presentations multi_presentations = PowerPoint_App.Presentations; Microsoft.Office.Interop.PowerPoint.Presentation presentation = multi_presentations.Open(path, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse); string presentation_text = ""; for (int i = 0; i < presentation.Slides.Count; i++) { foreach (var item in presentation.Slides[i + 1].Shapes) { var shape = (Microsoft.Office.Interop.PowerPoint.Shape)item; if (shape.HasTextFrame == Microsoft.Office.Core.MsoTriState.msoTrue) { if (shape.TextFrame.HasText == Microsoft.Office.Core.MsoTriState.msoTrue) { var textRange = shape.TextFrame.TextRange; var text = textRange.Text; presentation_text += text + " "; } } } } PowerPoint_App.Quit(); return(presentation_text); } }
private void btnExport_Click(object sender, EventArgs e) { lblMessage.Enabled = false; lblMessage.Text = "Parsing.."; var result = this.folderBrowser.ShowDialog(this); if (result != DialogResult.OK) { return; } var folderPath = FileIO.GetPath(folderBrowser.SelectedPath); var ext = new List <string> { ".ppt", ".pptx" }; var presos = Directory.GetFiles(folderPath, "*.*", SearchOption.TopDirectoryOnly) .Where(s => ext.Any(x => s.EndsWith(x))).ToList(); var pdfext = new List <string> { ".pdf" }; var pdfs = Directory.GetFiles(folderPath, "*.*", SearchOption.TopDirectoryOnly) .Where(s => pdfext.Any(x => s.EndsWith(x))).ToList(); if (presos.Count() == 0 && pdfs.Count() == 0) { lblMessage.Text = "no presentations or Pdfs found"; return; } var tempDir = Directory.CreateDirectory(folderPath + @"\_temp"); Microsoft.Office.Interop.PowerPoint.Application PowerPoint_App = null; if (presos.Count() != 0) { try { PowerPoint_App = PowerPointEx.ConvertToPPTX(presos, tempDir.FullName); } catch (Exception ex) { MessageBox.Show("Error initializing, close Powerpoint if it is open"); return; } } Microsoft.Office.Interop.PowerPoint.Presentations multi_presentations = PowerPoint_App.Presentations; string outFile = ""; foreach (var preso in presos) { Microsoft.Office.Interop.PowerPoint.Presentation presentation = multi_presentations.Open(preso, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse); var pptName = Path.GetFileName(preso); var underscoreIndex = pptName.IndexOf('_'); var newPptName = pptName.Remove(0, underscoreIndex + 1); if (string.IsNullOrEmpty(outFile)) { outFile = Path.GetFileNameWithoutExtension(newPptName); outFile += ".docx"; var outDir = Directory.CreateDirectory(folderPath + @"\_output"); _fullFilePath = Path.Combine(outDir.FullName, outFile); WordEx.CreateDoc(_fullFilePath); } WordEx.AddTitle(newPptName); foreach (Microsoft.Office.Interop.PowerPoint.Slide slide in presentation.Slides) { bool firstLine = true; //ParseWithOpenXML(slideId,preso); string pptx = Path.GetFileNameWithoutExtension(preso) + ".pptx"; string pptxFile = Path.Combine(tempDir.FullName, pptx); _slideInfos.Add(new SlideInfo() { Id = slide.SlideNumber, path = pptxFile }); var prevNoteText = ""; foreach (var item in slide.Shapes) { //firstLine = true; var shape = (Microsoft.Office.Interop.PowerPoint.Shape)item; if (shape.HasTextFrame == MsoTriState.msoTrue) { if (shape.TextFrame2.HasText == MsoTriState.msoTrue) { if (shape.TextFrame2.TextRange.ParagraphFormat.Bullet.Type != MsoBulletType.msoBulletNone) { List <string> bullets = new List <string>(); foreach (TextRange2 para in shape.TextFrame2.TextRange.Paragraphs) { bullets.Add(para.Text); //var bulletText = "- " + para.Text; //buffer.AppendLine(bulletText); } WordEx.AddBulletList(bullets); //string text = shape.TextFrame2.TextRange.Text; //WordEx.AddBulletList(text); } else { var text = shape.TextFrame2.TextRange.Text; //slideText += text + " "; //buffer.AppendLine(text); if (firstLine) { WordEx.AddHeader(text); firstLine = false; } else { WordEx.AddText(text); } } } else if (shape.TextFrame.HasText == MsoTriState.msoTrue) { var text = shape.TextFrame.TextRange.Text; //slideText += text + " "; //buffer.AppendLine(text); if (firstLine) { WordEx.AddHeader(text); firstLine = false; } else { WordEx.AddText(text); } } firstLine = false; } if (slide.HasNotesPage == MsoTriState.msoTrue) { //bool processedNotes = false; foreach (var note in slide.NotesPage.Shapes) { //if (processedNotes) // break; var noteShape = (Microsoft.Office.Interop.PowerPoint.Shape)note; if (noteShape.HasTextFrame == MsoTriState.msoTrue) { if (noteShape.TextFrame2.HasText == MsoTriState.msoTrue) { var text1 = noteShape.TextFrame2.TextRange.Text; if (text1 == prevNoteText || WordEx.IsNumeric(text1)) { continue; } //processedNotes = true; //go to next since notes are duplicated in interop. if (noteShape.TextFrame2.TextRange.ParagraphFormat.Bullet.Type != MsoBulletType.msoBulletNone) { List <string> bullets = new List <string>(); foreach (TextRange2 para in noteShape.TextFrame2.TextRange.Paragraphs) { bullets.Add(para.Text); } WordEx.AddBulletList(bullets, true); prevNoteText = noteShape.TextFrame2.TextRange.Text; } else { var text = noteShape.TextFrame2.TextRange.Text; WordEx.AddText(text, true); } } else if (noteShape.TextFrame.HasText == MsoTriState.msoTrue) { var text = noteShape.TextFrame.TextRange.Text; WordEx.AddText(text, true); } } } } } } presentation.Close(); //var presoSource = Path.GetFileName(preso); //string processedPreso = Path.Combine(processedDir.FullName, presoSource); //if (!File.Exists(processedPreso)) // File.Copy(preso, processedPreso); } try { PowerPointEx.Close(PowerPoint_App); AddImages(); AddPdfs(pdfs, tempDir.FullName); WordEx.Save(); lblMessage.Text = "Created Doc: " + _fullFilePath; lblMessage.Enabled = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public bool LoadDocument(string filename, string typename, ListView parent) { this.Clear(); if (!File.Exists(filename)) { return(false); } // all windows media play formats if (typename == "WMP") { this.pdfViewer.Visible = false; this.fileView.Visible = false; this.zipView.Visible = false; this.imgView.Visible = false; this.docView.Visible = false; this.webBrowser.Visible = false; if (this.b_cfw) { this.axWMP.Visible = false; this.videoPlayerCtl.URL = filename; this.videoPlayerCtl.Location = new System.Drawing.Point(this.ClientRectangle.X, this.ClientRectangle.Y); this.videoPlayerCtl.Size = this.Size; this.videoPlayerCtl.Visible = true; return(true); } if (this.b_wmp) { this.videoPlayerCtl.Visible = false; this.axWMP.URL = filename; this.axWMP.Visible = true; this.axWMP.Dock = DockStyle.Fill; return(true); } } // in case something goes wrong, we allow to fallback to b_asis and show the binary content bool asisTmp = this.b_asis; // ext drives most of the things string ext = System.IO.Path.GetExtension(filename).ToLower(); // all music if ((".mp3.wav.flac".IndexOf(ext) != -1) && this.b_mp3) { try { this.pdfViewer.Visible = false; this.fileView.Visible = false; this.zipView.Visible = false; this.imgView.Visible = false; this.webBrowser.Visible = false; this.videoPlayerCtl.Visible = false; this.docView.Visible = false; this.axWMP.Visible = true; this.axWMP.Dock = DockStyle.Fill; this.axWMP.URL = filename; asisTmp = false; } catch (System.Exception) { asisTmp = true; } } // initially I only found a way to convert Word to html (which is done here), other MSO Files conversations were found later and appear in the HTML section if ((".rtf.doc.docx".IndexOf(ext) != -1) && this.b_doc) { try { this.pdfViewer.Visible = false; this.fileView.Visible = false; this.zipView.Visible = false; this.imgView.Visible = false; this.webBrowser.Visible = false; this.videoPlayerCtl.Visible = false; this.axWMP.Visible = false; this.docView.LoadDocument(filename); this.docView.Visible = true; asisTmp = false; } catch (System.Exception) { asisTmp = true; } } else { // images if ((".ico.bmp.tif.jpg.jpeg.wmf.gif.png.exif.emf.tiff".IndexOf(ext) != -1) && this.b_img) { try { this.pdfViewer.Visible = false; this.fileView.Visible = false; this.zipView.Visible = false; this.webBrowser.Visible = false; this.docView.Visible = false; this.videoPlayerCtl.Visible = false; this.axWMP.Visible = false; this.imgView.Visible = true; this.imgView.LoadDocument(filename, parent); asisTmp = false; } catch (System.Exception) { asisTmp = true; } } else { // PDF and PowerPoint if ((".pdf.ppt.pptx.pptm.odp".IndexOf(ext) != -1) && (this.b_pdf || this.b_doc)) { // powerpoint formats via powerpoint interop converted to pdf if ((".ppt.pptx.pptm.odp".IndexOf(ext) != -1) && this.b_doc) { string outpath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "temp.pdf"); if (System.IO.File.Exists(outpath)) { System.IO.File.Delete(outpath); } try { Microsoft.Office.Interop.PowerPoint.Application app = new Microsoft.Office.Interop.PowerPoint.Application(); Microsoft.Office.Interop.PowerPoint.Presentations pres = app.Presentations; Microsoft.Office.Interop.PowerPoint.Presentation file = pres.Open(filename, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse); file.SaveCopyAs(outpath, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsPDF, Microsoft.Office.Core.MsoTriState.msoTrue); app.Quit(); filename = outpath; asisTmp = false; } catch (Exception) { asisTmp = true; } } // show pdf try { this.pdfViewer.ZoomMode = PdfViewerZoomMode.FitWidth; PdfDocument pdoc = PdfDocument.Load(filename); this.pdfViewer.Document = pdoc; this.fileView.Visible = false; this.zipView.Visible = false; this.imgView.Visible = false; this.webBrowser.Visible = false; this.docView.Visible = false; this.videoPlayerCtl.Visible = false; this.axWMP.Visible = false; this.pdfViewer.Visible = true; asisTmp = false; } catch (Exception) { asisTmp = true; } } else { // ZIP-Viewer simply shows the content of zip file if ((".zip".IndexOf(ext) != -1) && this.b_zip) { try { this.zipView.LoadZip(filename); this.pdfViewer.Visible = false; this.fileView.Visible = false; this.imgView.Visible = false; this.webBrowser.Visible = false; this.docView.Visible = false; this.videoPlayerCtl.Visible = false; this.axWMP.Visible = false; this.zipView.Visible = true; asisTmp = false; } catch (Exception) { asisTmp = true; } } else { // collector for everything, which could be converted into HTML if ((".htm.html.msg.eml.mht.xls.xlsx.xlsb.xlsm.vsd.vsdx.vsdm" /*.mpp.mpx"*/.IndexOf(ext) != -1) && (this.b_htm || this.b_doc)) { // visio via visio interop to html if ((".vsd.vsdx.vsdm".IndexOf(ext) != -1) && this.b_doc) { string outpath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "temp.html"); if (System.IO.File.Exists(outpath)) { System.IO.File.Delete(outpath); } asisTmp = true; try { Microsoft.Office.Interop.Visio.IVInvisibleApp visio = null; visio = new Microsoft.Office.Interop.Visio.InvisibleApp(); Microsoft.Office.Interop.Visio.SaveAsWeb.VisSaveAsWeb saveAsWeb = (Microsoft.Office.Interop.Visio.SaveAsWeb.VisSaveAsWeb)visio.Application.SaveAsWebObject; saveAsWeb.AttachToVisioDoc(visio.Documents.OpenEx(filename, (short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visOpenRO)); Microsoft.Office.Interop.Visio.SaveAsWeb.VisWebPageSettings webPageSettings = (Microsoft.Office.Interop.Visio.SaveAsWeb.VisWebPageSettings)saveAsWeb.WebPageSettings; webPageSettings.TargetPath = outpath; webPageSettings.PageTitle = outpath; webPageSettings.DispScreenRes = Microsoft.Office.Interop.Visio.SaveAsWeb.VISWEB_DISP_RES.res768x1024; webPageSettings.QuietMode = 1; webPageSettings.SilentMode = 1; webPageSettings.NavBar = 1; webPageSettings.PanAndZoom = 1; webPageSettings.Search = 1; webPageSettings.OpenBrowser = 0; webPageSettings.PropControl = 0; saveAsWeb.CreatePages(); this.webBrowser.Navigate(outpath); asisTmp = false; } catch (Exception) { asisTmp = true; } } // MS Project formats via project interop to xls: // - not working with 2003 Interops on a system running MS-Project 2003 (--> 2003 converter is shown) // - not working with 2007 Interops on a system running MS-Project 2003 (--> no html support in 2003) //if ((".mpp.mpx".IndexOf(ext) != -1) && b_doc) { // string outpath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "temp.xls"); // if (System.IO.File.Exists(outpath)) { // System.IO.File.Delete(outpath); // } // asisTmp = true; // try { // var app = new Microsoft.Office.Interop.MSProject.Application(); // app.Visible = false; // var proj = app.ActiveProject; // app.FileOpenx(filename, true, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.MSProject.PjPoolOpen.pjPoolReadOnly, Type.Missing, Type.Missing, Type.Missing, Type.Missing); // //app.FileOpenEx(filename, true, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.MSProject.PjPoolOpen.pjPoolReadOnly, Type.Missing, Type.Missing, Type.Missing, Type.Missing); // // save MS-Project as Excel file (MS-Project interopt has no HTML exporter) and let Excel viewer do the job // proj.SaveAs(outpath, PjFileFormat.pjXLS, 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); // app.Quit(Microsoft.Office.Interop.MSProject.PjSaveType.pjDoNotSave); // // set temporary Excel filename as "real" filename --> let Excel viewer do the work // filename = outpath; // // adjust extension --> let Excel viewer do the work // ext = System.IO.Path.GetExtension(filename).ToLower(); // asisTmp = false; // } catch (System.Reflection.TargetInvocationException x) { // asisTmp = true; // } //} // excel formats via excel interop to html if ((".xls.xlsx.xlsb.xlsm".IndexOf(ext) != -1) && this.b_doc) { string outpath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "temp.html"); if (System.IO.File.Exists(outpath)) { System.IO.File.Delete(outpath); } this.Cursor = Cursors.WaitCursor; try { // http://www.codeproject.com/Articles/507068/Microsoft-Interop-API-to-convert-the-doc-docx-dot Microsoft.Office.Interop.Excel.Application excel = null; Microsoft.Office.Interop.Excel.Workbook xls = null; excel = new Microsoft.Office.Interop.Excel.Application(); object missing = Type.Missing; object trueObject = true; excel.Visible = false; excel.DisplayAlerts = false; xls = excel.Workbooks.Open(filename, missing, trueObject, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing); object format = Microsoft.Office.Interop.Excel.XlFileFormat.xlHtml; System.Collections.IEnumerator wsEnumerator = excel.ActiveWorkbook.Worksheets.GetEnumerator(); while (wsEnumerator.MoveNext()) { this.Cursor = Cursors.WaitCursor; Microsoft.Office.Interop.Excel.Workbook wsCurrent = xls; wsCurrent.SaveAs(outpath, format, missing, missing, missing, missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, missing, missing, missing, missing, missing); } excel.Quit(); this.webBrowser.Navigate(outpath); asisTmp = false; } catch (Exception cex) { GrzTools.AutoMessageBox.Show(cex.Message, "Exception", 2000); asisTmp = true; } Cursor.Current = Cursors.Default; } // msg files are converted via MsgReader to html if (".msg".IndexOf(ext) != -1) { try { string body = ""; Reader msgReader = new Reader(); using (StreamReader streamReader = new StreamReader(filename)) { body = msgReader.ExtractMsgEmailBody(streamReader.BaseStream, true, "text/html; charset=utf-8"); } this.webBrowser.DocumentText = body; asisTmp = false; } catch (Exception) { asisTmp = true; } } // html-style formatted files if ((".htm.html.eml.mht".IndexOf(ext) != -1) && this.b_htm) { this.webBrowser.Url = new Uri(filename); asisTmp = false; } if (!asisTmp) { this.pdfViewer.Visible = false; this.fileView.Visible = false; this.zipView.Visible = false; this.imgView.Visible = false; this.docView.Visible = false; this.axWMP.Visible = false; this.videoPlayerCtl.Visible = false; this.webBrowser.Visible = true; } } } } } } // standard file view if (asisTmp) { this.fileView.LoadDocument(null, filename, parent); this.pdfViewer.Visible = false; this.zipView.Visible = false; this.imgView.Visible = false; this.webBrowser.Visible = false; this.docView.Visible = false; this.videoPlayerCtl.Visible = false; this.axWMP.Visible = false; this.fileView.Visible = true; } return(true); }
public void processFBRReport(string fbrFileLocation) { DataRow dr = dtFBR.NewRow(); dr["FILE_NAME"] = Path.GetFileName(fbrFileLocation); var stringBuilder = new StringBuilder(); Microsoft.Office.Interop.PowerPoint.Application pptApp = new Microsoft.Office.Interop.PowerPoint.Application(); Microsoft.Office.Interop.PowerPoint.Presentations pptPresentations = pptApp.Presentations; Microsoft.Office.Interop.PowerPoint.Presentation pptPresentation = pptPresentations.Open(fbrFileLocation, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse); Microsoft.Office.Interop.PowerPoint.Slides pptSlides = pptPresentation.Slides; Graphics gr = this.CreateGraphics(); var slidesCount = pptSlides.Count; int imgCrt = 0; for (int slideIndex = 1; slideIndex <= slidesCount; slideIndex++) { var slide = pptSlides[slideIndex]; foreach (Microsoft.Office.Interop.PowerPoint.Shape textShape in slide.Shapes) { if (textShape.Type == Microsoft.Office.Core.MsoShapeType.msoPicture) { listofImages.Add(textShape); imgCrt++; textShape.Export(sPowerPointFolderImg + textShape.ZOrderPosition.ToString() + "-" + ((textShape.Left * gr.DpiX) / 72).ToString("0.00") + "-" + ((textShape.Top * gr.DpiX) / 72).ToString("0.00") + "-" + ((textShape.Width * gr.DpiX) / 72).ToString("0.00") + "-" + ((textShape.Height * gr.DpiX) / 72).ToString("0.00") + ".png", Microsoft.Office.Interop.PowerPoint.PpShapeFormat.ppShapeFormatPNG, 0, 0, Microsoft.Office.Interop.PowerPoint.PpExportMode.ppScaleXY); } if (textShape.HasTextFrame == Microsoft.Office.Core.MsoTriState.msoTrue && textShape.TextFrame.HasText == Microsoft.Office.Core.MsoTriState.msoTrue) { Microsoft.Office.Interop.PowerPoint.TextRange pptTextRange = textShape.TextFrame.TextRange; if (pptTextRange != null && pptTextRange.Length > 0) { stringBuilder.Append(" " + pptTextRange.Text); if (pptTextRange.Text.StartsWith("ACTUAL CUSTOMER COMPLAINT") == true) { string tmpString = pptTextRange.Text; tmpString = pptTextRange.Text.Replace("ACTUAL CUSTOMER COMPLAINT", string.Empty); dr["ACTUAL CUSTOMER COMPLAINT"] = tmpString.Replace(",", "").Replace("\r", String.Empty); } else if (pptTextRange.Text.Trim().ToUpper().Equals("MARKET FEED BACK") == true) { } else if (pptTextRange.Text.Trim().ToUpper().StartsWith("RANK:") == true) { string tmpString = pptTextRange.Text.ToUpper(); tmpString = pptTextRange.Text.Replace("RANK:", string.Empty); var regex = new Regex(Regex.Escape("\r")); tmpString = regex.Replace(tmpString, "", 1); dr["RANK"] = tmpString; } else if (pptTextRange.Text.Trim().ToUpper().StartsWith("TRACKING #") == true) { string tmpString = pptTextRange.Text.ToUpper(); tmpString = tmpString.ToUpper().Replace("TRACKING #:", string.Empty); dr["TRACKING"] = tmpString.Replace(",", "").Replace("\r", String.Empty); } else if (pptTextRange.Text.Trim().StartsWith("This sheet is intended for quick feed back to increase associate") == true) { } else if (pptTextRange.Text.Trim().Equals("For Reference Only") == true) { } else { if (textShape.Name.ToString().Equals("Title 1") == true) { dr["TITLE"] = pptTextRange.Text.Replace(",", "").Replace("\r", String.Empty); } } System.Runtime.InteropServices.Marshal.ReleaseComObject(pptTextRange); } } if (textShape.HasTable == Microsoft.Office.Core.MsoTriState.msoTrue) { if (textShape.Table.Rows.Count > 1) { int iNumRows = textShape.Table.Rows.Count; int iNumCols = textShape.Table.Rows[1].Cells.Count; string sKey = textShape.Table.Rows[1].Cells[1].Shape.TextFrame.TextRange.Text; if ((sKey.Trim().ToUpper().Equals("VIN") == true) || (sKey.Trim().ToUpper().Equals("PART NAME") == true) || (sKey.Trim().ToUpper().Equals("CUSTOMER CONCERN:") == true) || (sKey.Trim().ToUpper().Equals("DEALER REPAIR:") == true) || (sKey.Trim().ToUpper().Equals("ADDITIONAL DETAILS:") == true) || (sKey.Trim().ToUpper().Equals("CLAIM COST:") == true) ) { //Process VIN Block for (int iCol = 1; iCol <= iNumCols; iCol++) { dr[textShape.Table.Rows[1].Cells[iCol].Shape.TextFrame.TextRange.Text] = textShape.Table.Rows[2].Cells[iCol].Shape.TextFrame.TextRange.Text.Replace(",", String.Empty).Replace("\r", String.Empty); } } if ((sKey.Trim().ToUpper().Equals("MODEL:") == true) || (sKey.Trim().ToUpper().Equals("DEPT:") == true) || (sKey.Trim().ToUpper().Equals("ISSUED DATE:") == true) || (sKey.Trim().ToUpper().Equals("ISSUER:") == true) ) { //Process VIN Block for (int iRow = 1; iRow <= iNumRows; iRow++) { dr[textShape.Table.Rows[iRow].Cells[1].Shape.TextFrame.TextRange.Text] = textShape.Table.Rows[iRow].Cells[2].Shape.TextFrame.TextRange.Text.Replace(",", ""); } } } } System.Runtime.InteropServices.Marshal.ReleaseComObject(textShape); } System.Runtime.InteropServices.Marshal.ReleaseComObject(slide); } System.Runtime.InteropServices.Marshal.ReleaseComObject(pptSlides); System.Runtime.InteropServices.Marshal.ReleaseComObject(pptPresentation); System.Runtime.InteropServices.Marshal.ReleaseComObject(pptPresentations); System.Runtime.InteropServices.Marshal.ReleaseComObject(pptApp); dtFBR.Rows.Add(dr); string[] filePaths = Directory.GetFiles(sPowerPointFolderImg); int min_left = 10000000; int min_top = 10000000; int max_bottom = 0; int max_right = 0; foreach (string filePath in filePaths) { string imagefilename = Path.GetFileNameWithoutExtension(filePath); string[] filesplit = imagefilename.Split('-'); imageInfo imgInfoObj = new imageInfo(); imgInfoObj.position = Convert.ToInt32(filesplit[0]); imgInfoObj.left = Convert.ToInt32(filesplit[1].Substring(0, filesplit[1].IndexOf('.'))); imgInfoObj.top = Convert.ToInt32(filesplit[2].Substring(0, filesplit[2].IndexOf('.'))); imgInfoObj.width = Convert.ToInt32(filesplit[3].Substring(0, filesplit[3].IndexOf('.'))); imgInfoObj.height = Convert.ToInt32(filesplit[4].Substring(0, filesplit[4].IndexOf('.'))); imgInfoObj.filename = filePath; dicImageFileInfo.Add(imgInfoObj.position, imgInfoObj); if (imgInfoObj.left < min_left) { min_left = imgInfoObj.left; } if (imgInfoObj.top < min_top) { min_top = imgInfoObj.top; } if (max_bottom < (imgInfoObj.height + imgInfoObj.top)) { max_bottom = (imgInfoObj.height + imgInfoObj.top); } if (max_right < (imgInfoObj.left + imgInfoObj.width)) { max_right = imgInfoObj.left + imgInfoObj.width; } } List <int> list = dicImageFileInfo.Keys.ToList(); list.Sort(); Bitmap target = new Bitmap(max_right - min_left + 50, max_bottom - min_top + 50); using (Graphics g = Graphics.FromImage(target)) { g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.InterpolationMode = InterpolationMode.NearestNeighbor; foreach (var key in list) { imageInfo temImgInfo = (imageInfo)dicImageFileInfo[key]; Bitmap src = Image.FromFile(temImgInfo.filename) as Bitmap; g.DrawImage(src, (temImgInfo.left - min_left), ((temImgInfo.top - min_top))); src.Dispose(); } g.Dispose(); } string sImageNameCropTemp = sPowerPointFolderImgProcessed + Path.GetFileName(fbrFileLocation) + "_MergedImages.png"; target.Save(sImageNameCropTemp); dicImageFileInfo.Clear(); target.Dispose(); gr.Dispose(); Array.ForEach(Directory.GetFiles(sPowerPointFolderImg), File.Delete); }
public static void PrintDiscountCoupon(string companyName, string discountProductName, string discountValueOnProduct) { int copiesToPrint = 1; string printTemplateFileName = @"\Assets\Docs\PrinterReceipt.pptx"; string qrCodeImageName = @"\Assets\Images\QREncode.jpg"; string printFileName = @"\Assets\Docs\printReceipt.pptx"; string printTemplateFilePath = Helper.GetAssetURI(printTemplateFileName); string qrCodeImagepath = Helper.GetAssetURI(qrCodeImageName); string printReceiptFilePath = Helper.GetAssetURI(printFileName); Microsoft.Office.Interop.PowerPoint.Presentation work = null; Microsoft.Office.Interop.PowerPoint.Application app = new Microsoft.Office.Interop.PowerPoint.Application(); try { if (File.Exists(printReceiptFilePath)) { File.Delete(printReceiptFilePath); } if (File.Exists(qrCodeImagepath)) { File.Delete(qrCodeImagepath); } Microsoft.Office.Interop.PowerPoint.Presentations presprint = app.Presentations; work = presprint.Open(printTemplateFilePath, Microsoft.Office.Core.MsoTriState.msoCTrue, Microsoft.Office.Core.MsoTriState.msoCTrue, Microsoft.Office.Core.MsoTriState.msoFalse); work.PrintOptions.PrintInBackground = Microsoft.Office.Core.MsoTriState.msoFalse; Microsoft.Office.Interop.PowerPoint.Slide slide = work.Slides[1]; foreach (var item in slide.Shapes) { var shape = (Microsoft.Office.Interop.PowerPoint.Shape)item; if (shape.HasTextFrame == MsoTriState.msoTrue) { if (shape.TextFrame.HasText == MsoTriState.msoTrue) { var textRange = shape.TextFrame.TextRange; var text = textRange.Text; if (text.Contains("10%")) { text = text.Replace("10", discountValueOnProduct); shape.TextFrame.TextRange.Text = text; } else if (text.Contains("Microsoft")) { text = text.Replace("Microsoft", companyName); shape.TextFrame.TextRange.Text = text; } else if (text.Contains("Windows Phone 8")) { text = text.Replace("Windows Phone 8", discountProductName); shape.TextFrame.TextRange.Text = text; } } } else { if (shape.Name.ToString() == "Picture 2") { shape.Delete(); //Add QRCode to print RippleCommonUtilities.HelperMethods.GenerateQRCode("http://projectripple.azurewebsites.net/Ripple.aspx", qrCodeImagepath); slide.Shapes.AddPicture(qrCodeImagepath, MsoTriState.msoFalse, MsoTriState.msoTrue, 560, 90, 80, 80); } } } work.SaveAs(printReceiptFilePath); work.PrintOut(); work.Close(); app.Quit(); //delete the PrintReceipt File File.Delete(printReceiptFilePath); //Delete the QRCOde image File.Delete(qrCodeImagepath); } catch (System.Exception ex) { work.Close(); app.Quit(); //delete the PrintReceipt File File.Delete(printReceiptFilePath); //Delete the QRCOde image File.Delete(qrCodeImagepath); RippleCommonUtilities.LoggingHelper.LogTrace(1, "Went wrong in Print Discount Coupon at Screen side: {0}", ex.Message); } }
public PowerPointControl() { // OpenFileDialog Instanz erzeugen Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); // Dateiendungs-Filter setzen dlg.DefaultExt = ".pptx"; dlg.Filter = "Powerpoint|*.ppt;*.pptx|All files|*.*"; // OpenFileDialog anzeigen Nullable<bool> result = dlg.ShowDialog(); // PowerPoint Instanz erzeugen oPPT = new Microsoft.Office.Interop.PowerPoint.Application(); // PowerPoint anzeigen oPPT.Visible = Microsoft.Office.Core.MsoTriState.msoTrue; objPresSet = oPPT.Presentations; // Wenn der Benutzer im OpenFileDialog eine Datei ausgewählt + auf OK geklickt hat if (result == true) { // Ausgewählte Datei (Präsentation) öffnen objPres = objPresSet.Open(dlg.FileName, MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue); // Präsentationsansicht öffnen objPres.SlideShowSettings.ShowPresenterView = MsoTriState.msoFalse; System.Diagnostics.Debug.WriteLine(objPres.SlideShowSettings.ShowWithAnimation); objPres.SlideShowSettings.Run(); oSlideShowView = objPres.SlideShowWindow.View; } }
private void OpenPPT() { //Create an instance of PowerPoint. oPPT = new Microsoft.Office.Interop.PowerPoint.Application(); // Show PowerPoint to the user. oPPT.Visible = Microsoft.Office.Core.MsoTriState.msoTrue; objPresSet = oPPT.Presentations; string pptFilePath = "C:\\Users\\bastisusewind\\Desktop\\Test.pptx"; //open the presentation objPres = objPresSet.Open(pptFilePath, MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue); objPres.SlideShowSettings.ShowPresenterView = MsoTriState.msoFalse; System.Diagnostics.Debug.WriteLine(objPres.SlideShowSettings.ShowWithAnimation); objPres.SlideShowSettings.Run(); oSlideShowView = objPres.SlideShowWindow.View; }