Solved

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

Posted on 2016-11-09
3
50 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Office2007 Training Material Required 2 41
c# LinkButton OnClientClick 2 34
MS Printer Preview Searchs for Printers 16 23
Close form "before" open 3 28
Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

867 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now