private static void createPresentation(OutlineParagraph outlineParagraph, string targetFile, Action <string> fileCreated, Logger logger) { var pptApplication = new Microsoft.Office.Interop.PowerPoint.ApplicationClass(); var currentDirectory = System.IO.Directory.GetCurrentDirectory(); var targetName = System.IO.Path.GetFileNameWithoutExtension(targetFile); //var pptFileTargetPath = System.IO.Path.Combine(currentDirectory, "PPT", targetName, outlineParagraph.Text.Trim() + ".ppt"); var odpOutputfile = Path.Combine(currentDirectory, "ODP", targetName, outlineParagraph.Text.Trim() + ".odp"); if (System.IO.File.Exists(odpOutputfile)) { logger.Log($"{odpOutputfile} already exists to recreate it delete the existing version."); return; } // Create the Presentation File Presentation pptPresentation = pptApplication.Presentations.Add(MsoTriState.msoFalse); var filePath = typeof(Generator).Assembly.Location; var path = System.IO.Path.GetDirectoryName(filePath); pptPresentation.ApplyTheme(path + @"\BibleStudy.thmx"); createPresentation(outlineParagraph, pptPresentation, fileCreated); //try //{ // System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(pptFileTargetPath)); // pptPresentation.SaveAs(pptFileTargetPath); // fileCreated(pptFileTargetPath); //} //catch(Exception ex) //{ // Console.WriteLine(ex.Message); // throw; //} System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(odpOutputfile)); pptPresentation.SaveAs(odpOutputfile, PpSaveAsFileType.ppSaveAsOpenDocumentPresentation); fileCreated(odpOutputfile); pptPresentation.Close(); pptApplication.Quit(); }
private static void createPowerPoint(OutlineParagraph outlineParagraph, string targetFile) { var pptApplication = new Microsoft.Office.Interop.PowerPoint.ApplicationClass(); var rootPath = System.IO.Path.GetDirectoryName(targetFile); var targetName = System.IO.Path.GetFileNameWithoutExtension(targetFile); var pptFileTargetPath = System.IO.Path.Combine(rootPath, targetName) + $"\\" + outlineParagraph.Text.Trim() + ".ppt"; // Create the Presentation File Presentation pptPresentation = pptApplication.Presentations.Add(MsoTriState.msoFalse); var filePath = typeof(PPTGenerator).Assembly.Location; var path = System.IO.Path.GetDirectoryName(filePath); pptPresentation.ApplyTheme(path + @"\BibleStudy.thmx"); createPowerPoint(outlineParagraph, pptPresentation); Console.WriteLine(pptFileTargetPath); try { System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(pptFileTargetPath)); pptPresentation.SaveAs(pptFileTargetPath); } catch (Exception ex) { Console.WriteLine(ex.Message); throw; } var odpOutputfile = Path.Combine(rootPath, "..\\ODP", targetName, outlineParagraph.Text.Trim() + ".odp"); System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(odpOutputfile)); pptPresentation.SaveAs(odpOutputfile, PpSaveAsFileType.ppSaveAsOpenDocumentPresentation); pptPresentation.Close(); pptApplication.Quit(); }
public void AppendMultiSummary(Presentation destinationPresentation = null) { int fileIndex = Controller.Instance.Summaries.MultiSummary.OutputFileIndex; try { var thread = new Thread(delegate() { MessageFilter.Register(); int publicationsCount = Controller.Instance.Summaries.MultiSummary.PublicationNames1.Length; for (int k = 0; k < publicationsCount; k += fileIndex) { var presentationTemplatePath = MasterWizardManager.Instance.SelectedWizard.GetMultiSummaryFile(String.Format("{0}{1}", fileIndex, Controller.Instance.Summaries.MultiSummary.ShowDigitalLegend && (k == 0 || !Controller.Instance.Summaries.MultiSummary.ShowDigitalLegendOnlyFirstSlide) ? "d" : String.Empty)); if (File.Exists(presentationTemplatePath)) { Presentation presentation = PowerPointObject.Presentations.Open(FileName: presentationTemplatePath, WithWindow: MsoTriState.msoFalse); foreach (Slide slide in presentation.Slides) { foreach (Shape shape in slide.Shapes) { for (int i = 1; i <= shape.Tags.Count; i++) { switch (shape.Tags.Name(i)) { case "ADVERTISER": shape.TextFrame.TextRange.Text = Controller.Instance.Summaries.MultiSummary.BusinessName; break; case "DATETAG": shape.TextFrame.TextRange.Text = Controller.Instance.Summaries.MultiSummary.Date; break; case "DECISIONMAKER": shape.TextFrame.TextRange.Text = Controller.Instance.Summaries.MultiSummary.DecisionMaker; break; case "HEADER": shape.TextFrame.TextRange.Text = Controller.Instance.Summaries.MultiSummary.Header; break; case "FLTDT1": shape.TextFrame.TextRange.Text = Controller.Instance.Summaries.MultiSummary.FlightDates1; break; case "MLIN2": if (!((k + 1) < publicationsCount)) { shape.Visible = MsoTriState.msoFalse; } break; case "CAL2": if (!((k + 1) < publicationsCount)) { shape.Visible = MsoTriState.msoFalse; } break; case "RD2": if (!((k + 1) < publicationsCount)) { shape.Visible = MsoTriState.msoFalse; } break; case "DIGTAG": shape.TextFrame.TextRange.Text = k == 0 || !Controller.Instance.Summaries.MultiSummary.ShowDigitalLegendOnlyFirstSlide ? Controller.Instance.Summaries.MultiSummary.DigitalLegend : String.Empty; break; default: for (int j = 0; j < fileIndex; j++) { if (shape.Tags.Name(i).Equals(string.Format("MLTLOGO{0}", j + 1))) { if ((k + j) < Controller.Instance.Summaries.MultiSummary.LogoFiles.Length) { if (!string.IsNullOrEmpty(Controller.Instance.Summaries.MultiSummary.LogoFiles[k + j])) { slide.Shapes.AddPicture(FileName: Controller.Instance.Summaries.MultiSummary.LogoFiles[k + j], LinkToFile: MsoTriState.msoFalse, SaveWithDocument: MsoTriState.msoCTrue, Left: shape.Left, Top: shape.Top, Width: shape.Width, Height: shape.Height); } } shape.Visible = MsoTriState.msoFalse; } else if (shape.Tags.Name(i).Equals(string.Format("PUBTAG{0}", j + 1))) { if ((k + j) < Controller.Instance.Summaries.MultiSummary.PublicationNames1.Length) { shape.TextFrame.TextRange.Text = Controller.Instance.Summaries.MultiSummary.PublicationNames1[k + j]; shape.Width = shape.TextFrame.TextRange.BoundWidth + 10; } else { shape.Visible = MsoTriState.msoFalse; } } else if (shape.Tags.Name(i).Equals(string.Format("PUBTAG{0}B", j + 1))) { if ((k + j) < Controller.Instance.Summaries.MultiSummary.PublicationNames2.Length) { shape.TextFrame.TextRange.Text = Controller.Instance.Summaries.MultiSummary.PublicationNames2[k + j]; shape.Width = shape.TextFrame.TextRange.BoundWidth + 10; } else { shape.Visible = MsoTriState.msoFalse; } } else if (shape.Tags.Name(i).Equals(string.Format("INVTAG{0}", j + 1))) { if ((k + j) < Controller.Instance.Summaries.MultiSummary.Investments.Length && !String.IsNullOrEmpty(Controller.Instance.Summaries.MultiSummary.Investments[k + j])) { shape.TextFrame.TextRange.Text = Controller.Instance.Summaries.MultiSummary.Investments[k + j]; shape.Width = shape.TextFrame.TextRange.BoundWidth + 10; shape.Left = presentation.SlideMaster.Width - shape.Width - 20; } else { shape.Visible = MsoTriState.msoFalse; } } else if (shape.Tags.Name(i).Equals(string.Format("FLTDT2{0}", (j > 0 ? "B" : string.Empty)))) { if ((k + j) < Controller.Instance.Summaries.MultiSummary.FlightDates2.Length) { shape.TextFrame.TextRange.Text = Controller.Instance.Summaries.MultiSummary.FlightDates2[k + j]; } else { shape.Visible = MsoTriState.msoFalse; } } else if (shape.Tags.Name(i).Equals(string.Format("DATELIST{0}", j + 1))) { if ((k + j) < Controller.Instance.Summaries.MultiSummary.RunDates.Length) { shape.TextFrame.TextRange.Text = Controller.Instance.Summaries.MultiSummary.RunDates[k + j]; } else { shape.Visible = MsoTriState.msoFalse; } } else { for (int l = 0; l < 6; l++) { if (shape.Tags.Name(i).Equals(string.Format("ADSPEC{0}{1}", new object[] { (l + 1), (j > 0 ? "B" : string.Empty) }))) { if ((k + j) < Controller.Instance.Summaries.MultiSummary.AdSpecs.Length) { if (l < Controller.Instance.Summaries.MultiSummary.AdSpecs[k + j].Length) { shape.TextFrame.TextRange.Text = Controller.Instance.Summaries.MultiSummary.AdSpecs[k + j][l]; } else { shape.Visible = MsoTriState.msoFalse; } } else { shape.Visible = MsoTriState.msoFalse; } } } } } break; } } } } var selectedTheme = Controller.Instance.Summaries.MultiSummary.SelectedTheme; if (selectedTheme != null) { presentation.ApplyTheme(selectedTheme.GetThemePath()); } AppendSlide(presentation, -1, destinationPresentation); presentation.Close(); } } }); thread.Start(); while (thread.IsAlive) { Application.DoEvents(); } } catch { } finally { MessageFilter.Revoke(); } }
public void AppendMultiGridGridBased(Presentation destinationPresentation = null) { { try { var publicationLogos = Controller.Instance.Grids.MultiGrid.PublicationLogos; var publicationLogosCount = publicationLogos.Length; var thread = new Thread(delegate() { MessageFilter.Register(); var slidesCount = Controller.Instance.Grids.MultiGrid.OutputReplacementsLists.Count; var rowsCount = slidesCount > 0 ? Controller.Instance.Grids.MultiGrid.Grid[0].GetLength(0) : 0; for (var k = 0; k < slidesCount; k++) { string presentationTemplatePath = MasterWizardManager.Instance.SelectedWizard.GetMultiGridFile( Controller.Instance.Grids.MultiGrid.SelectedColumnsCount, rowsCount, Controller.Instance.Grids.MultiGrid.ShowCommentsHeader); int currentSlideRowsCount = Controller.Instance.Grids.MultiGrid.Grid[k].GetLength(0); if (File.Exists(presentationTemplatePath)) { Presentation presentation = PowerPointObject.Presentations.Open(presentationTemplatePath, WithWindow: MsoTriState.msoFalse); bool hideAdSpecsOnSlide = ((k + 1) < slidesCount && Controller.Instance.Grids.MultiGrid.ShowAdSpecsOnlyOnLastSlide) || Controller.Instance.Grids.MultiGrid.DoNotShowAdSpecs; foreach (Slide slide in presentation.Slides) { foreach (Shape shape in slide.Shapes) { for (int i = 1; i <= shape.Tags.Count; i++) { switch (shape.Tags.Name(i)) { case "SIGLINE": if (!Controller.Instance.Grids.MultiGrid.ShowSignatureLine || hideAdSpecsOnSlide) { shape.Visible = MsoTriState.msoFalse; } break; case "SIGAPPROVAL": if (!Controller.Instance.Grids.MultiGrid.ShowSignatureLine || hideAdSpecsOnSlide) { shape.Visible = MsoTriState.msoFalse; } break; default: var shapeTagName = shape.Tags.Name(i); if (k < publicationLogosCount) { for (int j = 0; j < publicationLogos[k].Length; j++) { if (shapeTagName.Equals(string.Format("LOGO{0}", j + 1))) { string fileName = publicationLogos[k][j]; if (!string.IsNullOrEmpty(fileName)) { slide.Shapes.AddPicture(FileName: fileName, LinkToFile: MsoTriState.msoFalse, SaveWithDocument: MsoTriState.msoCTrue, Left: shape.Left, Top: shape.Top, Width: shape.Width, Height: shape.Height); } shape.Visible = MsoTriState.msoFalse; } } } else { if (shapeTagName.Contains("LOGO")) { shape.Visible = MsoTriState.msoFalse; } } break; } } if (shape.HasTable != MsoTriState.msoTrue) { continue; } var table = shape.Table; var tableRowsCount = table.Rows.Count; var tableColumnsCount = table.Columns.Count; for (var i = 1; i <= tableRowsCount; i++) { for (var j = 1; j <= tableColumnsCount; j++) { var tableShape = table.Cell(i, j).Shape; if (tableShape.HasTextFrame != MsoTriState.msoTrue) { continue; } var cellKey = tableShape.TextFrame.TextRange.Text.Trim(); if (!Controller.Instance.Grids.MultiGrid.OutputReplacementsLists[k].Keys.Contains(cellKey)) { continue; } var cellText = Controller.Instance.Grids.MultiGrid.OutputReplacementsLists[k][cellKey]; if (!cellText.Equals("Merge")) { tableShape.TextFrame.TextRange.Text = cellText; Controller.Instance.Grids.MultiGrid.OutputReplacementsLists[k].Remove(cellKey); } else { tableShape.TextFrame.TextRange.Text = String.Empty; var nextColumnIndex = j - 1; if (nextColumnIndex >= tableColumnsCount) { continue; } table.Cell(i, j).Merge(table.Cell(i, nextColumnIndex)); table.Cell(i, j).Shape.TextFrame.TextRange.ParagraphFormat.Alignment = PpParagraphAlignment.ppAlignLeft; } } } var deletedRows = 0; var dataStart = 4 + currentSlideRowsCount * (Controller.Instance.Grids.DetailedGrid.ShowCommentsHeader ? 2 : 1); var dataEnd = tableRowsCount - 1; for (var i = dataStart; i <= dataEnd; i++) { table.Rows[i - deletedRows].Delete(); deletedRows++; } tableRowsCount = table.Rows.Count; deletedRows = 0; for (var i = 1; i <= tableRowsCount; i++) { var tableShape = table.Cell(i - deletedRows, 1).Shape; if (tableShape.HasTextFrame != MsoTriState.msoTrue) { continue; } var cellText = tableShape.TextFrame.TextRange.Text.Trim(); if (!cellText.Equals("MergeComment")) { continue; } table.Rows[i - deletedRows].Delete(); deletedRows++; } } } var selectedTheme = Controller.Instance.Grids.MultiGrid.SelectedTheme; if (selectedTheme != null) { presentation.ApplyTheme(selectedTheme.GetThemePath()); } AppendSlide(presentation, -1, destinationPresentation); presentation.Close(); } } }); thread.Start(); while (thread.IsAlive) { Application.DoEvents(); } } catch { } finally { MessageFilter.Revoke(); } } }