How to modify Powerpoint with Office.Js APIs - ms-office

I'm looking for Office.js Powerpoint add-in apis that can modify slide content properties (e.g. change all font to Calibri).
The .load() and .sync() methods to read properties (font size , color, position) of ppt content are not documented very clearly and I could not find the list of options that can be passed to the .load() method in the docs
eg: calling .load("slides") along with the .sync() loads the slides property.
context.presentation.load("slides");
await context.sync();
I'm looking for all the possible arguments of the load() methods, and all the different properties that I can fetch.

We have been adding APIs to the PowerPoint-specific JavaScript library, but we don't yet have the detailed content modification you're looking for.
There is a guidance article about load and sync (among other things) at Using the application-specific API model. For a good understanding of these methods, I also recommend Building Office Add-ins with Office.js.
You can add content to PowerPoint with the Office Common APIs. See here for the distinction between the Common and application-specific libraries and links to more information.

Related

Get content from several Pages and Sections from OneNote to Excel

I am very new to all of this so please bare with me.
I have a OneNote Notebook with several Sections each containing hundreds of pages.
I need to retrieve all the content of the pages (while keeping the structure of the page titles / section titles) and end up with that content in a somewhat usable state in Excel. Of course, doing so manually will take me weeks. That's why I'm looking for an automated/semi-automated approach.
Is there a way to do that? What do I need to look into? I haven't found an answer on the interned but I guess I may need to use the OneNote API? Maybe find a way to export the OneNote content into .csv to then process it in Excel? Maybe the OneNote content can be retrieved directly by a macro in Excel?
What would you look into to achieve my goal?
Thank you for reading.
The OneNote API/Graph API can get sections and pages
GET https://graph.microsoft.com/v1.0/me/onenote/notebooks/{id}/sections
GET https://graph.microsoft.com/v1.0/me/onenote/sections/{id}/pages$count=true&$top=100
There may be a limitation to the number of pages that can be accessed by the API (recently introduced?). Then a further call to get individual page content:
GET https://graph.microsoft.com/v1.0/me/onenote/pages/{id}/content[?includeIDs=true]
An alternative may be to use this rust OneNote notebook parser - creates html files.

Is there a way to read a word document section by section with c#

I have a word template which has multiple sections( tables, parragraphs, lists, etc.. ). The idea is that users fill the template and upload it to a asp.net application. I need the application to read the information section by section. So, is there a way to name the section of a word document and identify it by using c#?
I think it is much better to create a custom web page for filling fields there and constructing a Word document on the server-side using the Open XML SDK, see Welcome to the Open XML SDK 2.5 for Office for more information.
However, you may consider using bookmarks or content controls as a marker for sections.
Otherwise, you'll need to parse the uploaded document by searching for keywords presented in the template.

Store information of workbook and add-in

There is an Excel add-in that allow users to make comments (not the traditional comments provided by Excel) for spreadsheet cells. The add-in memorizes all the cells that have comments in a workbook.
I am wondering where these information are actually stored. Are they stored in some hidden part of the workbook? Are they stored in the server of the add-in, then how are workbooks identified?
If you're referring to an add-in that somehow "remembers" a particular Range across document open/close sessions (e.g., how the Bing Maps add-in does it), it's using Bindings beneath the covers. Bindings -- which are conceptually a lot like the user-facing Named Ranges, but are invisible and are per add-in (so no name collision risk) -- are stored in the document, just like named ranges.
As Kim points out, this is often combined with Settings to create an add-in that both binds to some ranges (with a GUID-like name, for example), and stores some metadata keyed off of the binding name.
On a side note, if you want to reference ranges only for a specific duration of time while the add-in is running but you don't need these to persist in the document, you can instead use object-tracking. It is described in great detail in the book "Building Office Add-ins using Office.js", (disclaimer: I am author of said book), in a chapter called "Using objects outside the 'linear' Excel.run or Word.run flow (e.g., in a button-click callback,in a setInterval, etc.)".
Using the Office.js API, you can use the Settings object (Office.context.document.settings) to store name/value pairs in the host document. For details about how this works, see the documentation here: https://dev.office.com/reference/add-ins/shared/settings.
As the documentation indicates, the settings that you create/save using the Settings object are saved per add-in and per document, which matches the scenario that you've described. Regarding where settings data actually gets stored, check out the answer on this other Stack Overflow post -- which describes how/where settings data is persisted for a host document. (Note: I haven't personally verified that answer, so I'd suggest that you do some testing to verify/confirm its accuracy for your scenario.)

Flexible customization - Generating word document using C#

Problem - Generate a word document from information retrieved from database.
My solution - Create a word document template add fields/tags in places where values need to be inserted. The template will require tables and charts as well. Using document reflector that comes with open office xml sdk reflect on the document template and extract the w:document section and port it to C#. The rest of the logic revolves simply around finding the fields/tags, replacing them, etc. Very simple approach but not very flexible!
Challenge - I want the user to have the ability to customize the template or the generated document output. But this will not be possible if I embed the template logic in code.
Any other possibilities - I looked around at Templating using T4 and RazorEngine but could not find any concrete examples of how to create word documents using these two technologies.
Now what is the best approach?
I would really appreciate your inputs on what is the best and most flexible way to generate word documents using C#.
I'm actually working a project where the business users are designing word template with mail merge fields and we are populating the values using a 3rd party software package Aspose Words. http://www.aspose.com/categories/.net-components/aspose.words-for-.net/default.aspx
The software includes a library for merging data from datatables into the mail merge fields in the word document.
I also wrote a customized word task pane add in that retrieves data views from the database and lists the fields in a drag/drop interface that mimics a crystal or sql report writing interface.
Probably would of been easier to just use crystal or sql reporting though...
It's certainly possible to generate the contents of an Office doc using T4 or Razor and then package it up. The TestScribe powertool for Visual Studio Test Manager does just that with T4. There is a thread by Sally Cavanagh in the Q&A on this page http://visualstudiogallery.msdn.microsoft.com/e79e4a0f-f670-47c2-9b8a-3b6f664bf4ae that suggests a way to look at the T4 templates that it uses, which might get you jump-started.
Here is sample to play word document template with C#
You could use a content control databinding approach.
XML Mapping Task Pane for Word 2007/2010 is an authoring tool.
To create an instance document, you just attach your XML data file.
If the resulting documents will be opened in Word, that is all that is required: Word will bind the data itself. If your consuming application is not Word, you might want to resolve the bindings yourself (eg via Open XML SDK).
Content control databinding isn't intended to support repeats and conditionals. For a way to do that, look at my OpenDoPE convention
Take a look at Templater. Disclamer: I'm the author.
Check out JODReports or Docmosis. They are Java based but some of the templating features and output options might be ideal. You can call the command line interfaces unless they also have something better to reach from C#.

Sharepoint. SPFile.OpenBinary() returns document with content type metadata

I have a method which downloads sharepoint documents to the local disk. I use SPFile.OpenBinary() method to get physical file, but it contains all fields of a parent DocumentLibrary. Does anybody know how to clear file (doc file) from these fields? I found only way to do it using Word interop library (method described here http://maxim-dikhtyaruk.blogspot.com/2009/05/trim-sharepoints-documents.html), but it doesn't fit my requirements cause it works only when Microsoft Office is installed on the machine...
You may want to read this to understand whats going on.
I do not know if this can be turned off or not, but it happens only with Word 2007 documents (docx).
You could do any of the following to turn this off:
Create a new content type and associate it with a document library. Use this document library from now on.
Look into some Open XML library or the Open XML SDK published by Microsoft.
This isn't a bug, it's supposed to be a feature! :-) Seriously though, you need to edit the Word document programmatically to remove these additional fields completely (I think even a content type will leave some behind).
For documents prior to Word 2007, you could use a toolkit like Aspose. I almost needed to do a similar thing once and would have used this product to do it. I'm sure there are other options out there.
For Word 2007 and higher, as SharePoint Newbie says, you should be able to use the Office Open XML formats to edit the document. Here's an MSDN intro article.

Resources