C# Automation for Impress Presentation

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
vanderk
Posts: 6
Joined: Wed Nov 02, 2016 2:42 pm

C# Automation for Impress Presentation

Post by vanderk »

I have an application that uses MS Office Interop to create a new presentation then insert other presentations into it. Then I save the file and open it in OpenOffice. I have a C# background so that was the quickest way for me to achieve what I wanted. Now I would like to try to remove the dependency on MS Office and do this with the UNO API. My C# code is below. Can anyone point me to an example that will do the same thing with the UNO API?

Code: Select all

//ppt comes from this : using ppt = Microsoft.Office.Interop.PowerPoint;
var app = new ppt.Application();

//Take the first PPT and and merge rest.
var pres = app.Presentations.Add(MsoTriState.msoTrue);

//adds blank black slide to beginning
pres.PageSetup.SlideSize = ppt.PpSlideSizeType.ppSlideSizeLetterPaper;
var firstslide = pres.Slides.Add(1, ppt.PpSlideLayout.ppLayoutCustom);
firstslide.FollowMasterBackground = MsoTriState.msoFalse;
firstslide.Background.Fill.ForeColor.RGB = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);

//COM+ memory cleanup
NAR(firstslide);
var files = new List<Presentation>();
            var msg = "";

            // if no commas only use 1 item from the list
            var filtercount = txtFilter.Text.Contains(',') ? dgvPresentation.Rows.Count : 1;
            for (var i = 0; i < filtercount; i++)
            {
                dynamic item = filtercount == 1 ? (dgvPresentation.SelectedRows.Count > 0 ? dgvPresentation.SelectedRows[0].DataBoundItem : dgvPresentation.Rows[0].DataBoundItem) : dgvPresentation.Rows[i].DataBoundItem;
                var mypres = new Presentation
                {
                    Number = item.Number,
                    Title = item.Title,
                    File =
                        Functions.AddQuotessIfRequired(Functions.ContainsInvalidFilenameChars(item.File)
                            ? item.File
                            : _presentationsPath + item.File)
                };

                msg += string.Format("{0} - {1}\r\n", mypres.Number, mypres.Title);
                files.Add(mypres);

            }

foreach (var file in files)
{
  
	pres.Slides.InsertFromFile(file.File, pres.Slides.Count);

	var newSlideNumber = (pres.Slides.Count + 1);
	var slide = pres.Slides.Add(newSlideNumber, ppt.PpSlideLayout.ppLayoutCustom);
	slide.FollowMasterBackground = MsoTriState.msoFalse;
	//adds blank black slide after each inserted presentation
	slide.Background.Fill.ForeColor.RGB = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);

	//COM+ memory cleanup
	NAR(slide);
}

pres.SaveAs(destPath, ppt.PpSaveAsFileType.ppSaveAsPresentation, MsoTriState.msoTrue);

if (launchSlideshow)
{
	pres.Close();
	//COM+ memory cleanup
	NAR(pres);
	app.Quit();
	//COM+ memory cleanup
	NAR(app);
}
OpenOffice 4.1.2 on Windows 7 and 10
Post Reply