Solved

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

Posted on 2016-11-09
3
32 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
Comment Utility
You could try using Presentations.Open with Untitled: set to True
0
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 250 total points
Comment Utility
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
Comment Utility
Thanks guys - that did the trick!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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 viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
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…

763 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

6 Experts available now in Live!

Get 1:1 Help Now