Solved

Programmatically creating Office 2013 documents (Word, Excel, PowerPoint) from template files

Posted on 2016-11-09
3
62 Views
Last Modified: 2016-11-11
I have written VSTO addins for Office 2013 (and later) apps that integrates them with a 3rd-party enterprise content management (ECM) system - providing the user with ECM analogs for all of the native file I/O operations (e.g. New, Open, Save, Save As, etc...).  That said, all of the functions proved quite simple to implement until I got to the New function (i.e. the ability to create a new document (Word, PowerPoint or Excel) from a supplied template.  In Word, this was simple:

this.Application.Documents.Add(filename);

Open in new window


Voila!  The user selects a Word template file (i.e. filename) and Word subsequently creates a Word document based on the selected template file.  Naively, I thought the PowerPoint and Excel object models would be similar to Word's - I was wrong.  There doesn't appear to be any method similar to Add (e.g. Presentations.Add, Workbooks.Add) that performs the same function.  While I did find examples on the web of creating a PowerPoint document from a specified template file, the approach taken was radically different than that required by Word, involved using the Open XML SDK and was significantly more convoluted.

Does anyone know of a simpler way (in C#) of creating both Excel and PowerPoint documents from specified template files (i.e. .xltx, .xlt, .xltm, .potx, .pot, .potm files)?  I look forward to everyone's feedback!
0
Comment
Question by:Lloyd Charlier
3 Comments
 
LVL 23

Assisted Solution

by:JSRWilson
JSRWilson earned 250 total points
ID: 41880642
You could try using Presentations.Open with Untitled: set to True
0
 
LVL 49

Accepted Solution

by:
Rgonzo1971 earned 250 total points
ID: 41880697
HI,

pls try

Microsoft.Office.Interop.PowerPoint.Presentations ps = pptApp.Presentations;
Microsoft.Office.Interop.PowerPoint.Presentation p = ps.Open(powerPointFilePath, 
            Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoTrue)

and

Microsoft.Office.Interop.Excel.Workbook wb = xlApp.Workbooks.Add(ExcelFilePath)

Open in new window

Regards
0
 

Author Closing Comment

by:Lloyd Charlier
ID: 41884037
Thanks guys - that did the trick!
0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question