Click here to Skip to main content
15,890,609 members

Comments by Barry_Sharp (Top 6 by date)

Barry_Sharp 15-Jan-18 4:45am View    
Just as an FYI, you could consider avoiding the hassle that comes with COM interface by using a pure C# solution. For example, you may want to check out this PowerPoint library in C# for presentations. For instance, here is how you would create a new presentation with it:

PresentationDocument presentation = new PresentationDocument();
presentation.Save("empty-presentation.pptx");
Barry_Sharp 15-Jan-18 4:34am View    
First, you cannot suppress that MS Word message. When you set "UpdateFieldsOnOpen" it will mark the element with an "isDirty" flag which will result in MS Word asking for a confirmation before updating it.

Second, if you plan to use the below suggested macro approach, I think it would be far easier for you to have that macro already available in your template document, rather then trying to create it with OpenXML SDK.
If you must use OpenXML SDK for this then you'll need to:
- Change the format from DOCX to DOCM, with "WordprocessingDocument.ChangeDocumentType".
- Create and add "VbaProjectPart", with "WordprocessingDocument.AddNewPart".
- Create and add "VbaDataPart"...

This last requirement is a tricky part, you see inside the DOCM file macros are stored in "vbaproject.bin". That is a binary file which is completaly different to OOXML format, see Office VBA File Format Structure.

Last, as an alternative you may want to check out this Word processing library for .NET Framework. It can enable you to easily manipulate with Word files in C#. For example, see how to create and update Word TOC in C# and VB.NET.
Barry_Sharp 15-Jan-18 4:14am View    
See how to read excel file in c#, the used Load method can work with both physical file (when providing an Excel file's path) or with an in-memory file (when providing an Excel file's stream).
Barry_Sharp 24-Oct-17 2:19am View    
You mentioned that you can read the data, how exactly are you doing that, what approach are you using?
I'm certain that whatever approach you're using to read excel files in C# can also retrieve all sheet names.