internal static void ExportPowerPointAndRemoveObjects() { PowerPoint.Presentation presentation = Globals.ThisAddIn.Application.ActivePresentation; SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "PowerPoint Presentation|*.pptx|PowerPoint 97-2003 Presentation|*.ppt"; saveFileDialog.Title = "Save as an unnotated File"; saveFileDialog.InitialDirectory = presentation.Path; saveFileDialog.RestoreDirectory = true; saveFileDialog.FileName = presentation.Name.Replace(".pptx", "") + "-unnotated"; DialogResult result = saveFileDialog.ShowDialog(); if (saveFileDialog.FileName != "") { switch (result) { case DialogResult.OK: presentation.SaveCopyAs(saveFileDialog.FileName); Globals.ThisAddIn.Application.Presentations.Open(saveFileDialog.FileName, WithWindow: Office.MsoTriState.msoTrue); RemoveObjects(false); Globals.ThisAddIn.Application.ActivePresentation.Save(); //Globals.ThisAddIn.Application.ActivePresentation.Close(); break; case DialogResult.Cancel: break; } } }
public ImportPowerPointView(string _fileName) { HelperClass helperClass = new HelperClass(); InitializeComponent(); _documentMain = new ElearningDocument(); app = new pp.Application(); presentationFile = _fileName; presentation = app.Presentations.Open(_fileName, office.MsoTriState.msoTrue, office.MsoTriState.msoTrue, office.MsoTriState.msoFalse); if (System.IO.Path.GetExtension(_fileName) == ".ppt") { presentationFile = System.IO.Path.Combine((System.Windows.Application.Current as IAppGlobal).DocumentTempFolder, DateTime.Now.Ticks.ToString() + ".pptx"); presentation.SaveCopyAs(presentationFile, pp.PpSaveAsFileType.ppSaveAsOpenXMLPresentation, office.MsoTriState.msoCTrue); } Utils.tlw = 1024 / presentation.PageSetup.SlideWidth; Utils.tlh = 576 / presentation.PageSetup.SlideHeight; Utils.LstSlide = presentation.Slides; Opening oForm = new Opening(); oForm.ShowDialog(); this.DataContext = viewmodel; if (DataContext != null) { if ((DataContext as ImportPowerPointViewModel).CloseForm == null) { (DataContext as ImportPowerPointViewModel).CloseForm = new Action(Close); } } }
private void ComprobarCorrectoIncorrectoPowerPoint(object sender, EventArgs e) { int numeroDePregunta = arrayOrdenPreguntas[contadorDeAvance - 1]; PreguntasPowerPoint preguntasPowerPoint = new PreguntasPowerPoint(); if (numeroDePregunta == 10 || numeroDePregunta == 22) //propiedades de impresion { var temp = ppt.PrintOptions; string numeroCopias = ppt.PrintOptions.NumberOfCopies.ToString(); string slidesPorHoja = ppt.PrintOptions.OutputType.ToString(); string color = ppt.PrintOptions.PrintColorType.ToString(); string rango = ppt.PrintOptions.RangeType.ToString(); string intercalar = ppt.PrintOptions.Collate.ToString(); preguntasPowerPoint.PropiedadesDeImpresion(numeroCopias, slidesPorHoja, color, rango, intercalar); } string ruta = Application.StartupPath + @"\Documentos\Temp\Ejercicio.pptx"; if (System.IO.File.Exists(ruta)) { System.IO.File.Delete(ruta); } try { ppt.SaveCopyAs(ruta, PowerPoint.PpSaveAsFileType.ppSaveAsDefault, Microsoft.Office.Core.MsoTriState.msoFalse); CerrarPowerPoints(); guardarCorrecto = true; } catch (Exception) { BtnReset_Click(sender, e); } if (guardarCorrecto) { preguntasPowerPoint.Pregunta(numeroDePregunta, examenIdExamen); } }
static void Main(string[] args) { string filepath = args[0]; string cwd = Directory.GetCurrentDirectory(); try { filepath = Path.GetFullPath(filepath); PowerPoint.Application ppt = new PowerPoint.Application(); PowerPoint.Presentation p = ppt.Presentations.Open(filepath); string dst = cwd + @"/" + getPDFName(Path.GetFileName(filepath)); p.SaveCopyAs(dst, PowerPoint.PpSaveAsFileType.ppSaveAsPDF); p.Close(); ppt.Quit(); } catch (Exception e) { Console.Error.WriteLine(e.Message); } }
private void Publish(IGroup group) { PPT.Application app = app = new PPT.Application(); PPT.Presentation pres = app.ActivePresentation; string fileName = Path.GetFileName(pres.FullName); if (!Path.HasExtension(fileName)) { fileName = Path.ChangeExtension(fileName, "pptx"); } if (group.ContainsFile(fileName)) { if (group.FullPath == Path.GetDirectoryName(pres.FullName)) { MessageBox.Show("You can't publish file in the folder where it is already located."); return; } DialogResult res = MessageBox.Show("File with the same name exists. Replace?", "Slides Gallery", MessageBoxButtons.OKCancel); if (res == System.Windows.Forms.DialogResult.Cancel) { return; } if (res == System.Windows.Forms.DialogResult.No) { //TODO: Get new name? return; } else { } } group.DeleteFile(fileName); string newFilePath = Path.Combine(group.FullPath, Path.GetFileName(fileName)); pres.SaveCopyAs(newFilePath); IFile file = group.AddFile(fileName); pres.ReleaseCOM(); pres = null; app.ReleaseCOM(); app = null; if (file != null) { if (treeBuilder == null) { LoadLibraryData(); } treeBuilder.AddFile(file); ReloadDataSource(); } }
private void Form1_Load(object sender, EventArgs e) { pptNS.ApplicationClass powerpointApplication = null; pptNS.Presentation pptPresentation = null; pptNS.Slide pptSlide = null; pptNS.ShapeRange shapeRange = null; pptNS.Shape oTxtShape = null; pptNS.Shape oShape = null; pptNS.Shape oPicShape = null; xlNS.ApplicationClass excelApplication = null; xlNS.Workbook excelWorkBook = null; xlNS.Worksheet targetSheet = null; xlNS.ChartObjects chartObjects = null; xlNS.ChartObject existingChartObject = null; xlNS.Range destRange = null; string paramPresentationPath = @"D:\test\Test Slide.pptx"; string paramWorkbookPath = @"D:\test\NPS.xlsx"; object paramMissing = Type.Missing; try { // Create an instance of PowerPoint. powerpointApplication = new pptNS.ApplicationClass(); // Create an instance Excel. excelApplication = new xlNS.ApplicationClass(); // Open the Excel workbook containing the worksheet with the chart // data. excelWorkBook = excelApplication.Workbooks.Open(paramWorkbookPath, paramMissing, paramMissing, paramMissing, paramMissing, paramMissing, paramMissing, paramMissing, paramMissing, paramMissing, paramMissing, paramMissing, paramMissing, paramMissing, paramMissing); // Get the worksheet that contains the chart. targetSheet = (xlNS.Worksheet)(excelWorkBook.Worksheets["Spain"]); // Get the ChartObjects collection for the sheet. chartObjects = (xlNS.ChartObjects)(targetSheet.ChartObjects(paramMissing)); // Create a PowerPoint presentation. pptPresentation = powerpointApplication.Presentations.Add( Microsoft.Office.Core.MsoTriState.msoTrue); // Add a blank slide to the presentation. pptSlide = pptPresentation.Slides.Add(1, pptNS.PpSlideLayout.ppLayoutBlank); // capture range //var writeRange = targetSheet.Range["A1:B15"]; destRange = targetSheet.get_Range("A1:B21"); oTxtShape = pptSlide.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, Left: 70, Top: 30, Width: 550, Height: 340); oTxtShape.TextFrame.TextRange.Text = "GB NPS 03/01/2017 to 26/01/2017"; oTxtShape.TextEffect.FontName = "Arial"; oTxtShape.TextEffect.FontSize = 32; oTxtShape.TextEffect.FontBold = Microsoft.Office.Core.MsoTriState.msoTrue; oTxtShape.TextEffect.Alignment = Microsoft.Office.Core.MsoTextEffectAlignment.msoTextEffectAlignmentCentered; System.Array myvalues = (System.Array)destRange.Cells.Value; List <Tuple <string, string> > cellData = GetData(myvalues); int iRows = cellData.Count + 1; int iColumns = 2; int row = 2; oShape = pptSlide.Shapes.AddTable(iRows, iColumns, 500, 110, 160, 120); oShape.Table.ApplyStyle("{5940675A-B579-460E-94D1-54222C63F5DA}"); //oShape.Table.ApplyStyle("{0660B408-B3CF-4A94-85FC-2B1E0A45F4A2}"); // table style guide https://msdn.microsoft.com/en-us/library/office/hh273476(v=office.14).aspx oShape.Table.Cell(1, 1).Merge(oShape.Table.Cell(1, 2)); //oShape.Table.Cell(1, 1).Shape.TextFrame.TextRange.Text = "Spain Data 01/01/2017 to 20/01/2017"; //oShape.Table.Cell(1, 1).Shape.TextFrame.TextRange.Font.Name = "Verdana"; //oShape.Table.Cell(1, 1).Shape.TextFrame.TextRange.Font.Size = 8; foreach (Tuple <string, string> item in cellData) { string strdate = item.Item1; string strValue = item.Item2; oShape.Table.Cell(row, 1).Shape.TextFrame.TextRange.Text = strdate; oShape.Table.Cell(row, 1).Shape.TextFrame.TextRange.Font.Name = "Arial"; oShape.Table.Cell(row, 1).Shape.TextFrame.TextRange.Font.Size = 10; oShape.Table.Cell(row, 2).Shape.TextFrame.TextRange.Text = (strValue.StartsWith("0") ? "0%" : (strValue + "0%")); oShape.Table.Cell(row, 2).Shape.TextFrame.TextRange.Font.Name = "Arial"; oShape.Table.Cell(row, 2).Shape.TextFrame.TextRange.Font.Size = 10; //if (row == 1) //{ // oShape.Table.Cell(row, 1).Shape.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(208, 208, 208).ToArgb(); // oShape.Table.Cell(row, 1).Shape.Fill.Visible = Microsoft.Office.Core.MsoTriState.msoTrue; // oShape.Table.Cell(row, 2).Shape.Fill.ForeColor.RGB = System.Drawing.Color.FromArgb(208, 208, 208).ToArgb(); // oShape.Table.Cell(row, 2).Shape.Fill.Visible = Microsoft.Office.Core.MsoTriState.msoTrue; //} row++; } oShape.Top = 100; oShape.Left = 30; oPicShape = pptSlide.Shapes.AddPicture(@"D:\test\chart.png", Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, 200, 100, 500, 300); //copy range //destRange.Copy(); // Paste the chart into the PowerPoint presentation. //shapeRange = pptSlide.Shapes.Paste(); //var table = pptSlide.Shapes.AddTable(); // Position the chart on the slide. //shapeRange.Left = 60; //shapeRange.Top = 100; // Get or capture the chart to copy. //existingChartObject = (xlNS.ChartObject)(chartObjects.Item(1)); // Copy the chart from the Excel worksheet to the clipboard. //existingChartObject.Copy(); // Paste the chart into the PowerPoint presentation. //shapeRange = pptSlide.Shapes.Paste(); //Position the chart on the slide. //shapeRange.Left = 90; //shapeRange.Top = 100; // Save the presentation. pptPresentation.SaveAs(paramPresentationPath, pptNS.PpSaveAsFileType.ppSaveAsOpenXMLPresentation, Microsoft.Office.Core.MsoTriState.msoTrue); pptPresentation.SaveCopyAs(String.Format(@"D:\test\Export", "video_of_presentation"), pptNS.PpSaveAsFileType.ppSaveAsEMF, Microsoft.Office.Core.MsoTriState.msoCTrue); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { // Release the PowerPoint slide object. shapeRange = null; pptSlide = null; // Close and release the Presentation object. if (pptPresentation != null) { pptPresentation.Close(); pptPresentation = null; } // Quit PowerPoint and release the ApplicationClass object. if (powerpointApplication != null) { powerpointApplication.Quit(); powerpointApplication = null; } // Release the Excel objects. targetSheet = null; chartObjects = null; existingChartObject = null; // Close and release the Excel Workbook object. if (excelWorkBook != null) { excelWorkBook.Close(false, paramMissing, paramMissing); excelWorkBook = null; } // Quit Excel and release the ApplicationClass object. if (excelApplication != null) { excelApplication.Quit(); excelApplication = null; } GC.Collect(); GC.WaitForPendingFinalizers(); } }
static void Main(string[] args) { string out_format = "PDF"; bool optimize_for_screen = false; List <string> files = (new OptionSet { { "xps", v => { if (v != null) { out_format = "XPS"; } } }, { "pdf", v => { if (v != null) { out_format = "PDF"; } } }, { "screen", v => { if (v != null) { optimize_for_screen = true; } } } }).Parse(args); var rx_ppt = new Regex(@"\.(pptx|ppt|pptm|ppsx|pps|ppsm|potx|pot|potm|odp)$", RegexOptions.IgnoreCase); var rx_doc = new Regex(@"\.(docx|docm|dotx|dotm|doc|dot|htm|html|rtf|mht|mhtml|xml|odt)$", RegexOptions.IgnoreCase); PowerPoint.Application ppt = null; Word.Application wrd = null; foreach (var i in files) { try { var file = Path.GetFullPath(i); if (rx_ppt.IsMatch(file)) { if (ppt == null) { ppt = new PowerPoint.Application(); } PowerPoint.Presentation p = ppt.Presentations.Open(file, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse); string dst = getAvailableFileName(out_format == "PDF" ? getPDFName(file) : getXPSName(file)); p.SaveCopyAs(dst, out_format == "PDF" ? PowerPoint.PpSaveAsFileType.ppSaveAsPDF : PowerPoint.PpSaveAsFileType.ppSaveAsXPS, MsoTriState.msoTrue); p.Close(); } else if (rx_doc.IsMatch(file)) { if (wrd == null) { wrd = new Word.Application(); } Word.Document d = wrd.Documents.Open(file, false, true); string dst = getAvailableFileName(out_format == "PDF" ? getPDFName(file) : getXPSName(file)); d.ExportAsFixedFormat(dst, out_format == "PDF" ? Word.WdExportFormat.wdExportFormatPDF : Word.WdExportFormat.wdExportFormatXPS, false, optimize_for_screen ? Word.WdExportOptimizeFor.wdExportOptimizeForOnScreen : Word.WdExportOptimizeFor.wdExportOptimizeForPrint); d.Close(false); } else { Console.Error.WriteLine("Unknown file type: " + i); } } catch (Exception e) { Console.Error.WriteLine(e.Message); } } ppt?.Quit(); wrd?.Quit(); }