Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2016-11-09
3
Medium Priority
?
107 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 23

Assisted Solution

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

Accepted Solution

by:
Rgonzo1971 earned 1000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

715 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