F. API documentation

think-cell allows you to programatically control some functionality through an API. Here you can find an overview over all available API functions, and general instruction for how to setup your development environment to write macros, add-ins, or standalone programs that access them.

Contents

F.1
Getting started
F.2
API reference

F.1 Getting started

think-cell's API is integrated into the Office Automation model, so it can be accessed from any language with which you can program Office, such as Visual Basic for Applications (VBA) or C#.

The entry point into think-cell is the think-cell add-in object. It can be accessed via the Application.COMAddIns collection. Calls into think-cell are always late-bound, thus there is no type library or reference to add. See Microsoft’s knowledge base for an explanation:

Using early binding and late binding in Automation

Some API functions are methods of the think-cell add-in object in PowerPoint, and some of the think-cell add-in object in Excel. We will use tcPpAddIn for references to the PowerPoint add-in, and tcXlAddIn for references to the Excel add-in.

F.1.1 Visual Basic for Applications

To write macros using Visual Basic for Applications (VBA), you use the development environment integrated into the Office host application. This can be accessed by pressing Alt+F11. The definition of a macro is usually contained in a module, which you can add via Insert > Module. You can view all macros defined for a given document by pressing Alt+F8.

To indicate that method calls into the think-cell add-in are late-bound, you need to declare the variable containing the reference to it as Object:

Dim tcaddin As Object 
Set tcaddin = Application.COMAddIns("thinkcell.addin").Object

The type library for the Office host application is always referenced by default. If you need to access the object model of another Office application, you need to add its type library as a reference.

For example, if you want to use a macro in PowerPoint to manipulate data in an Excel sheet before updating a think-cell chart from it, you need to manually add the Microsoft Excel 16.0 Object Library via the Tools Tools Menu icon. > References dialog in the VBA development environment.

Note: 16.0 is the version number of Office 2016 and later. For Office 2010 or 2013, you need to use the 14.0 or 15.0 object libraries, respectively. If you have multiple versions of Office installed, the References dialog will only show the object libraries of the latest version installed. We will assume in the following that you are using Office 2016 or later.

Using Application.COMAddIns("thinkcell.addin").Object will always get you the think-cell add-in object of the current Office host application, that is tcPpAddIn or tcXlAddIn, depending on whether you use it in PowerPoint or Excel. To acquire a reference to the add-in object in the other Office application, and access the API functions it exposes, acquire it through an appropriate application instance.

For example, to acquire a reference to tcXlAddIn from PowerPoint:

Dim xlapp As Object
Set xlapp = New Excel.Application

Dim tcXlAddIn As Object
Set tcXlAddIn = xlapp.COMAddIns("thinkcell.addin").Object

Note that this requires the Excel object library to be added as as a reference.

We recommend using the Option Explicit statement, which forces the explicit declaration of all variables, thereby helping to avoid common programming errors and improving the suggestions provided by IntelliSense. You can have it automatically added to all modules by activating Tools Tools Menu icon. > Options > Code Settings > Require Variable Declaration. It is included in all our code samples.

F.1.2 C#

You can use the think-cell API from C# when developing add-ins and document code extensions running inside an Office host application, as well as when developing standalone applications.

We will assume in the following that you are using Visual Studio 2017 or later to develop Office solutions in C#. Refer to the next section for more specific setup instructions for add-in development. With each of our code samples, we will indicate which Visual Studio project template to use.

To make method calls to the think-cell add-in object late-bound, declare the variable containing the reference to the think-cell add-in object as dynamic; this is also the type inferred by the compiler when declaring the reference as var, so that you can simply write:

var tcPpAddIn = ppapp.COMAddIns.Item("thinkcell.addin").Object;

Here ppapp is a reference to a PowerPoint Application object in which think-cell is loaded.

To access the object model of an Office application, you need to add either its type library or its primary interop assembly (PIA) as a reference to your project. We recommend adding the type library if possible, since Visual Studio will automatically add a reference to the corresponding PIA, if one is available, or generate an interop assembly from the type library if there is none (see here).

For example, to be able to get the reference to the think-cell add-in object as above, you would add the Microsoft PowerPoint 16.0 Object Library found in the COM > Type Libraries tab of the Reference Manager dialog. Depending on your project type, this dialog is accessed either by right-clicking References or Dependencies in the Solution Explorer and selecting Add (COM) Reference.

Note: 16.0 is the version number of Office 2016 and later. By using the Embed Interop Types option, which is enabled by default for a reference to a COM type library, an application compiled with this reference will be backward (and forward) compatible with other versions of Office as long as all interfaces used exist in their object model. See here for more information.

think-cell's API functions indicate errors using COM HRESULTs. Some of these are automatically mapped onto corresponding .NET exception classes, see How to: Map HRESULTs and Exceptions .

F.1.2.1 Add-in development

To develop add-ins for Office, or code extensions for Office documents, you use the PowerPoint/Excel VSTO Add-in and Excel VSTO Template/Workbook project templates. These are part of the Office Developer Tools for Visual Studio, which are installed as part of the default configuration. Should these tools and templates not be available in your Visual Studio installation, you can add them, for example, by going to Settings > Apps > Visual Studio 2022 > Modify > Other Toolsets, checking Office/SharePoint development and clicking Modify. See also Microsoft's documentation here and here.

The PIA for the Office host application of the selected template is always loaded by default. If you need to access the object model of another Office application, you need to add its type library as a reference as explained above.

Note: think-cell's API cannot be used from Office Web Add-Ins—unfortunately now simply called "Office Add-ins" by Microsoft—as they cannot interact with the Office application's object model directly, and in particular cannot interact with COM add-ins such as think-cell.

F.2 API reference

F.2.1 Updating elements and presentation templates with Excel data

F.2.2 Controlling styles

F.2.3 Importing Mekko Graphics charts

F.2.4 Miscellaneous

F.2.1 Updating elements and presentation templates with Excel data

The functions in this section can be used to programatically update think-cell elements, usually placeholders in a presentation template, with data from Excel. UpdateChart updates think-cell elements, specified by a name assigned to it in the template, with data from an Excel range passed as an argument. See also 24. Introduction to automation for how to prepare the template.

PresentationFromTemplate instantiates a presentation template with data from a linked Excel workbook. See also 21. Excel data links for how to create Excel links.

The functions in this section are methods of the think-cell add-in in Excel.

F.2.1.1 UpdateChart

F.2.1.1.1 Signature
VBA
tcXlAddIn.UpdateChart( _ 
    target As Object, _ 
    strName As String, _ 
    rgData As Excel.Range, _ 
    bTransposed As Boolean _ 
)
C#
void tcXlAddIn.UpdateChart(
    object target,
    string strName,
    Excel.Range rgData,
    bool bTransposed
);
F.2.1.1.2 Description

This function updates all elements in target with name strName with the data contained in rgData. For the data to be interpreted correctly for charts, the range rgData must conform to their configured datasheet layout, or its transposed version, see also 21.1 Creating a chart from Excel and 21.2 Fitting the data layout. Whether the default or the transposed version is to be used is indicated by setting bTransposed to false or true, respectively. For elements other than charts, tables for example, the value of bTransposed is ignored.

target must be a Presentation or SlideRange, or a single Slide, Master or CustomLayout.

The name strName is matched case-insensitively. It must have been previously assigned in PowerPoint using the UpdateChart Name property control as described in 24. Introduction to automation.

To ensure that the correct elements are targeted, make sure that they are the only ones with their UpdateChart Name set to strName in the object passed as pres.

If a targeted element is linked to an Excel data range when invoking this function, the link is broken. Afterwards, the element will not be linked to any Excel range.

F.2.1.1.3 Examples

To use these samples, prepare a presentation as described in 24. Introduction to automation, and save it as C:\Samples\UpdateChart\template.pptx.

VBA

To use this sample add it to a module in an Excel workbook.

It requires a reference to the Microsoft PowerPoint 16.0 Object Library (see F.1.1 Visual Basic for Applications for details).

Running UpdateChart_Sample in a workbook will update the chart in the presentation template with the data contained in range A1:D5 of its first sheet.

Option Explicit 
 
Sub UpdateChart_Sample() 

    ' Get the range containing the new data 
    Dim rng As Excel.Range 
    Set rng = ActiveWorkbook.Sheets(1).Range("A1:D5") 

    ' Get the think-cell add-in object 
    Dim tcXlAddIn As Object 
    Set tcXlAddIn = Application.COMAddIns("thinkcell.addin").Object 

    ' Get a PowerPoint instance. Hold on to this 
    ' object as long as you want to access the 
    ' generated presentations. There can only be a 
    ' single PowerPoint instance. If there is no 
    ' PowerPoint running, one will be started. 
    ' Otherwise the existing one is used.

    Dim ppapp As Object 
    Set ppapp = New PowerPoint.Application 

    Dim pres As PowerPoint.Presentation 

    ' PowerPoint window visible 
    ' Set pres = ppapp.Presentations.Open( _ 
    '  Filename:="C:\\Samples\\UpdateChart\\template.pptx", _
    '  Untitled:=msoTrue) 

    ' PowerPoint window invisible 

    Set pres = ppapp.Presentations.Open( _
    Filename:="C:\\Samples\\UpdateChart\\template.pptx", _
    Untitled:=msoTrue, _
    WithWindow:=msoFalse)

    Call tcXlAddIn.UpdateChart(pres, "Chart1", rng, False) 

    ' Save the updated presentation 
    pres.SaveAs ("C:\\Samples\\UpdateChart\\template_updated.pptx") 
    pres.Close 

    ppapp.Quit 
End Sub
C#

To use this sample, replace the code in Program.cs of the C# Console App project template with it.

It requires references to the Microsoft PowerPoint 16.0 Object Library, the Microsoft Excel 16.0 Object Library and the Microsoft Office 16.0 Object Library (see F.1.2 C# for details).

Running the resulting application will update the chart in the presentation template to contain a single series named "Series 1" with values 1, 2, 3, and save the result as template_updated.pptx.

using Excel = Microsoft.Office.Interop.Excel;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Office = Microsoft.Office.Core;

namespace ConsoleApplication_UpdateChart
{
    class Program
    {
        static void Main()
        {
            Excel.Application xlapp = new Excel.Application { Visible = true };

            Excel.Workbook workbook = xlapp.Workbooks.Add(1);
            Excel.Worksheet worksheet = (Excel.Worksheet)workbook.Sheets[1];
            worksheet.Cells[3, 1] = "Series 1";
            worksheet.Cells[3, 2] = 1;
            worksheet.Cells[3, 3] = 2;
            worksheet.Cells[3, 4] = 3;

            PowerPoint.Application ppapp = new PowerPoint.Application();
            PowerPoint.Presentation presentation = ppapp.Presentations.Open(
                    "C:\\Samples\\UpdateChart\\template.pptx",
                    Office.MsoTriState.msoFalse,
                    Office.MsoTriState.msoTrue
            );

            var tcXlAddIn = xlapp.COMAddIns.Item("thinkcell.addin").Object;
            tcXlAddIn.UpdateChart(
                presentation,
                "Chart1",
                worksheet.get_Range("A1", "D3"),
                false
            );

            presentation.SaveAs("C:\\Samples\\UpdateChart\\template_updated.pptx");
            presentation.Close();
            ppapp.Quit();

            workbook.Close(false);
            xlapp.Quit();
        }
    }
}

F.2.1.2 PresentationFromTemplate

F.2.1.2.1 Signature
VBA
tcXlAddIn.PresentationFromTemplate( _ 
    wb As Excel.Workbook, _ 
    strTemplate As String, _ 
    ppapp As PowerPoint.Application _ 
) As PowerPoint.Presentation
C#
PowerPoint.Presentation tcXlAddIn.PresentationFromTemplate(
    Excel.Workbook wb,
    string strTemplate,
    PowerPoint.Application ppapp
);
F.2.1.2.2 Description

This function uses the data links between the Excel workbook wb and the template with filename strTemplate to instantiate that template by updating the linked elements with the data from the ranges they are linked to. The result is a new presentation within the PowerPoint instance ppapp.

strTemplate can either be a full path or a relative path, which is then taken to be relative to the location of the Excel workbook file wb.

All elements in strTemplate that are linked to the Excel workbook wb are updated (regardless whether they are set to auto-update or not). In the resulting presentation, their data links are broken to prevent further changes to these elements.

Elements in strTemplate which are linked to Excel workbooks other than wb are left unchanged and still linked, so it is possible to update links from multiple Excel workbooks by saving the result of this function as a new template and then calling this function again with the next workbook.

If you want to control the colors of chart segments or the formatting of table cells with the Excel link, you can set the color scheme to Use Datasheet Fill on Top (see 3.8.2 Color scheme) or the Use Datasheet... options (see 17.3 Formatting a table), respectively. Likewise, to control the number format with the Excel link, set it to Use Excel Format (see 6.5.3 Number format).

Make sure to set the relevant formatting options and the number format of the respective cells in Excel before calling PresentationFromTemplate.

F.2.1.2.3 Examples

To use these samples, first create a presentation containing a stacked chart linked to the range G1:K4 of the first sheet in an Excel workbook as explained in 21.1 Creating a chart from Excel. Save the resulting presentation as C:\Samples\PresentationFromTemplate\template.pptx and the workbook as data.xlsx in the same directory.

VBA

To use this sample, add it to a module in the Excel workbook data.xlsx prepared as explained above.

It requires a reference to the Microsoft PowerPoint 16.0 Object Library (see F.1.1 Visual Basic for Applications for details).

Running PresentationFromTemplate_Sample will change the value in cell Sheet1!H3, which is linked to the first value of the first series of the chart contained in template.pptx, from i=1 to 10, create a new presentation with the chart in the template updated to contain that value, and which is not linked to the workbook anymore, and save it as output_i.pptx in the same directory as the template.

Option Explicit

Sub PresentationFromTemplate_Sample()
    ' Get the range to modify. It is more efficient
    ' to do this once rather than within the loop.
    Dim rng As Excel.Range
    Set rng = ActiveWorkbook.Sheets(1).Cells(3, 8)

    ' Get the think-cell add-in object
    Dim tcXlAddIn As Object
    Set tcXlAddIn = Application.COMAddIns("thinkcell.addin").Object

    ' Get a PowerPoint instance. Hold on to this
    ' object as long as you want to access the
    ' generated presentations. There can only be a
    ' single PowerPoint instance. If there is no
    ' PowerPoint running, one will be started.
    ' Otherwise the existing one is used.
    Dim ppapp As Object
    Set ppapp = New PowerPoint.Application

    Dim i As Integer
    For i = 1 To 10
        ' Modify the range value.
        ' Note: Avoid selecting the cell prior to
        ' changing it. It is very slow and has
        ' undesirable side-effects.
        ' BAD:
        ' rng.Select
        ' ActiveWindow.Selection.Value = 0
        ' GOOD:
        rng.Value = i

        ' Generate a new presentation based on the
        ' linked template.
        Dim pres As PowerPoint.Presentation
        Set pres = tcXlAddIn.PresentationFromTemplate( _
            Excel.ActiveWorkbook, "template.pptx", ppapp _
        )

        ' If you want to modify the new presentation
        ' before saving it this is the place to do it.
        
        ' Save the new presentation
        pres.SaveAs "C:\Samples\PresentationFromTemplate\output_" & i & ".pptx"
        
        ' Explicitly close the presentation when we
        ' are done with it to free its memory.
        ' Letting the object go out of scope is not
        ' sufficient.
        pres.Close
    Next
End Sub
C#

To use this sample replace the code in Program.cs of the C# Console App project template with it.

It requires references to the Microsoft PowerPoint 16.0 Object Library, the Microsoft Excel 16.0 Object Library and the Microsoft Office 16.0 Object Library (see F.1.2 C# for details).

Running the resulting application will visibly open Excel, load the workbook data.xlsx, change the value in cell H3, which is linked to the first value of the first series of the chart contained in template.pptx, from i=1 to 10, create a new presentation with the chart in the template updated to contain that value, and which is not linked to the workbook anymore, and save it as output_i.pptx in the same directory as the template.

using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Excel = Microsoft.Office.Interop.Excel;

namespace ConsoleApplication_PresentationFromTemplate
{
    class Program
    {
        static void Main()
        {
            var xlapp = new Excel.Application { Visible = true };
            var tcXlAddIn = xlapp.COMAddIns.Item("thinkcell.addin").Object;
            var workbook = xlapp.Workbooks.Open("C:\\Samples\\PresentationFromTemplate\\data.xlsx");
            var ppapp = new PowerPoint.Application();
            for (var i = 1; i <= 10; ++i)
            {
                workbook.Sheets[1].Cells[3, 8] = i;

                PowerPoint.Presentation presentation = tcXlAddIn.PresentationFromTemplate(
                    workbook,
                    "C:\\Samples\\PresentationFromTemplate\\template.pptx",
                    ppapp
                );

                presentation.SaveAs("C:\\Samples\\PresentationFromTemplate\\output_" + i + ".pptx");
                presentation.Close();
            }
            ppapp.Quit();
            workbook.Close(false);
            xlapp.Quit();
        }
    }
}

F.2.2 Controlling styles

The functions in this section can be used to programmatically load, inspect, and remove think-cell styles. LoadStyle loads a style from a style file into a master slide or a single custom layout. LoadStyleForRegion loads a style from a style file into a specific region of a custom layout. GetStyleName returns the name of the style loaded into a master or custom layout. RemoveStyles removes all styles from a custom layout.

See C.1 Creating a think-cell style and D. Style file format for more information on creating and editing styles. See C.2 Loading style files for more information on loading them.

The functions in this section are methods of the think-cell add-in in PowerPoint.

F.2.2.1 LoadStyle

F.2.2.1.1 Signature
VBA
tcPpAddIn.LoadStyle( _ 
    CustomLayoutOrMaster As Object, _ 
    FileName As String 
)
C#
void tcPpAddIn.LoadStyle(
    object CustomLayoutOrMaster,
    string FileName
);
F.2.2.1.2 Description

This function loads the style contained in the style file at FileName into a master or custom layout, specified via the parameter CustomLayoutOrMaster.

CustomLayoutOrMaster must be a CustomLayout or Master.

When applied to a custom layout where a regional style has been set (see F.2.2.2 LoadStyleForRegion), the regional style will be removed. This means that you need to load the style that should apply on the rest of the slide using this function before you load a style restricted to a region.

When applied to a master, any styles loaded into the custom layouts contained in that master, regional and unrestricted, will be removed. This means that you need to load the style that should apply to custom layouts without a specific style into the master before loading a style applying to a specific custom layout using this function.

F.2.2.1.3 Examples
VBA

To use this sample, add the following code to a module in PowerPoint (see F.1.1 Visual Basic for Applications for details).

Option Explicit
 
Sub LoadStyle_Sample() 

    ' Get the think-cell add-in object 
    Dim tcPpAddIn As Object 
    Set tcPpAddIn = Application.COMAddIns("thinkcell.addin").Object 

    Dim master As Master
    Set master = Application.ActivePresentation.Designs(1).SlideMaster

    Dim style As String
    style = "C:\some\path\styles\style.xml"

    Call tcPpAddIn.LoadStyle(master, style)
End Sub

F.2.2.2 LoadStyleForRegion

F.2.2.2.1 Signature
VBA
tcPpAddIn.LoadStyleForRegion( _ 
    CustomLayout As PowerPoint.CustomLayout, _ 
    FileName As String, _
    Left as Single, _
    Top as Single, _
    Width as Single, _
    Height as Single _
)
C#
void tcPpAddIn.LoadStyleForRegion(
    PowerPoint.CustomLayout CustomLayout,
    string FileName,
    float Left,
    float Top,
    float Width,
    float Height
);
F.2.2.2.2 Description

This function loads the style file at FileName into the custom layout CustomLayout and restricts it to a region given by Left, Top, Width, Height. On the rest of the slide, the style loaded into the master, or the one previously loaded into the custom layout with LoadStyle applies.

The parameters Left, Top, Width, Height are given in PowerPoint points. Left and Top specify the distance of the left and top edges of the region from the left and top edges of the custom layout, respectively. Usually you will set them as fractions of the total slide height and width. For example, for a region covering the right two thirds of the custom layout, you would set

Left = CustomLayout.Width / 3
Top = 0
Width = CustomLayout.Width * 2 / 3
Height = CustomLayout.Height

You can also manually add a shape to a slide or custom layout, query its properties Left, Top, Width, Height programmatically and use the values with LoadStyleForRegion to restrict the style to the same region covered by the shape.

think-cell supports a maximum of two styles per custom layout. One is set with LoadStyle and covers everything not restricted to a region, the other is set with LoadStyleForRegion.

F.2.2.2.3 Examples
VBA

To use this sample, add the following code to a module in PowerPoint (see F.1.1 Visual Basic for Applications for details).

Option Explicit
 
Sub LoadStyleForRegion_Sample() 

    ' Get the think-cell add-in object 
    Dim tcPpAddIn As Object 
    Set tcPpAddIn = Application.COMAddIns("thinkcell.addin").Object 

    Dim layout As CustomLayout
    Set layout = Application.ActivePresentation.Designs(1).SlideMaster.CustomLayouts(2)

    ' Define a region covering the left half of the custom layout
    Dim left, top, width, height As Single
    left = 0
    top = 0
    width = layout.Width / 2
    height = layout.Height

    Dim style As String
    style = "C:\some\path\styles\style.xml"

    Call tcPpAddIn.LoadStyleForRegion(layout, style, left, top, width, height)
End Sub

F.2.2.3 GetStyleName

Supported in think-cell 13 and later.

F.2.2.3.1 Signature
VBA
tcPpAddIn.GetStyleName( _ 
    CustomLayoutOrMaster As Object _ 
) As String
C#
string tcPpAddIn.GetStyleName(
    object CustomLayoutOrMaster
);
F.2.2.3.2 Description

This function returns the name of the style loaded into the CustomLayout or Master CustomLayoutOrMaster. This is the same name that is specified in the name attribute of the <style> element of the corresponding style file (see D.2.1 style).

It returns an empty string when no style is loaded into CustomLayoutOrMaster. Note that a master always has a style loaded into it when think-cell is active and that the name of a style cannot be empty.

If a name is returned for a CustomLayout, it is the name of the style loaded into it with F.2.2.1 LoadStyle, not of the one loaded with F.2.2.2 LoadStyleForRegion, if any.

F.2.2.3.3 Examples
VBA

To use this sample, add the following code to a module in PowerPoint (see F.1.1 Visual Basic for Applications for details).

Option Explicit

Sub GetStyleName_Sample()

    ' Get the think-cell add-in object 
    Dim tcPpAddIn As Object
    Set tcPpAddIn = Application.COMAddIns("thinkcell.addin").Object
    
    ' Get the Master of the first slide of the current presentation
    Dim master As Master
    Set master = Application.ActivePresentation.Slides(1).Master
    
    ' Print the name of the style loaded to the debug console
    Dim name As String
    name = tcPpAddIn.GetStyleName(master)
    Debug.Print name
End Sub

F.2.2.4 RemoveStyles

F.2.2.4.1 Signature
VBA
tcPpAddIn.RemoveStyles( _ 
    CustomLayout As PowerPoint.CustomLayout _ 
)
C#
void tcPpAddIn.RemoveStyles(
    PowerPoint.CustomLayout CustomLayout
);
F.2.2.4.2 Description

This function removes all styles from the custom layout CustomLayout. Afterwards, the style loaded into the master applies. Potentially, there can be a style loaded into the custom layout and another style restricted to a specific region of the custom layout. As RemoveStyles removes all styles, both will be removed. The style loaded into a master cannot be removed, as there always needs to be a valid style associated with a master. It can be overwritten with a different style file.

F.2.2.4.3 Examples
VBA

To use this sample, add the following code to a module in PowerPoint (see F.1.1 Visual Basic for Applications for details).

Option Explicit
 
Sub RemoveStyles_Sample() 

    ' Get the think-cell add-in object 
    Dim tcPpAddIn As Object 
    Set tcPpAddIn = Application.COMAddIns("thinkcell.addin").Object 

    Dim layout As CustomLayout
    Set layout = Application.ActivePresentation.Designs(1).SlideMaster.CustomLayouts(2)

    Call tcPpAddIn.RemoveStyles(layout)
End Sub

F.2.3 Importing Mekko Graphics charts

The functions in this section can be used to programmatically import and inspect charts created with Mekko Graphics to think-cell. ImportMekkoGraphicsCharts replaces Mekko Graphics charts with equivalent think-cell charts. GetMekkoGraphicsXML extracts the XML definition of a Mekko Graphics chart.

The functions in this section are methods of the think-cell add-in in PowerPoint.

F.2.3.1 ImportMekkoGraphicsCharts

Supported in think-cell 13 and later.

F.2.3.1.1 Signature
VBA
tcPpAddIn.ImportMekkoGraphicsCharts ( _
    ashp As PowerPoint.Shape() _
) As PowerPoint.Slide
C#
PowerPoint.Slide tcPpAddIn.ImportMekkoGraphicsCharts(
    PowerPoint.Shape[] ashp
);
F.2.3.1.2 Description

This function replaces all Mekko Graphics charts in the array of Shapes passed to it with an equivalent think-cell chart. The shapes must all be on the same slide. Before modifying the slide, the function will make a copy of the unmodified slide and insert it directly after the modified version.

The function returns a reference to this copy, if one was made.

It returns Nothing/null, if the presentation was not modified, for example because the array did not contain any Mekko Graphics charts.

F.2.3.1.3 Examples
VBA

To use this sample, add it to a module in PowerPoint (see F.1.1 Visual Basic for Applications for details).

Running ImportAll on a presentation will go through the slides in the presentation and replace all visible Mekko Graphics charts with equivalent think-cell charts, making a copy of each slide containing one before modifying it.

Option Explicit

Sub ImportAll()

    ' Get reference to think-cell Object

    Dim tcPpAddIn As Object
    Set tcPpAddIn = Application.COMAddIns("thinkcell.addin").Object

    ' Iterate over copy of original Slides to avoid
    ' iterating over copies inserted by ImportMekkoGraphicsCharts again

    Dim SlidesCopy As New Collection
    Dim Slide As PowerPoint.Slide
    For Each Slide In ActivePresentation.Slides
        SlidesCopy.Add Slide
    Next Slide
    
    For Each Slide In SlidesCopy
    
        ' Construct Array containing only visible shapes on slide
        
        Dim visibleShapes() As PowerPoint.Shape
        ReDim visibleShapes(1 To Slide.Shapes.Count)
        Dim shapeIndex As Long
        For shapeIndex = 1 To Slide.Shapes.Count
            If Slide.Shapes(shapeIndex).Visible Then
                Set visibleShapes(shapeIndex) = Slide.Shapes(shapeIndex)
            End If
        Next shapeIndex
        
        ' Pass Array to ImportMekkoGraphics and store return value
        
        Dim CopySlide As PowerPoint.Slide
        Set CopySlide = tcPpAddIn.ImportMekkoGraphicsCharts(visibleShapes)
        
        ' If Slide was modified...
        If Not CopySlide Is Nothing Then
        ' ... do things with copy of unmodified slide
        End If
    Next Slide
End Sub
C#

To use this sample, add this method to the ThisAddIn class of the C# PowerPoint VSTO Add-in project template (see F.1.2 C# and F.1.2.1 Add-in development for details).

private void ImportAll(PowerPoint.Presentation presentation)
    {
        var tcPpAddIn = presentation.Application.COMAddIns.Item("thinkcell.addin").Object;
        foreach (PowerPoint.Slide slide in presentation.Slides.Cast<PowerPoint.Slide>().ToList())
        {
            PowerPoint.Slide slideCopy = tcPpAddIn.ImportMekkoGraphicsCharts(
                slide.Shapes.Cast<PowerPoint.Shape>().ToArray()
            );
        }
    }

Add the following line to the ThisAddIn_Startup method to run ImportAll on each presentation that is opened:

Application.PresentationOpen += new PowerPoint.EApplication_PresentationOpenEventHandler(ImportAll);

F.2.3.2 GetMekkoGraphicsXML

Supported in think-cell 13 and later.

F.2.3.2.1 Signature
VBA
tcPpAddIn.GetMekkoGraphicsXML ( _
    shp As PowerPoint.Shape _
) As String
C#
string tcPpAddIn.GetMekkoGraphicsXML(
    PowerPoint.Shape shp
);
F.2.3.2.2 Description

This function returns the XML of the Mekko Graphics chart in shp as a string. It does not modify the shape passed to it.

If shp is not a Mekko Graphics chart, an E_INVALIDARG (0x80070057) error is raised.

F.2.3.2.3 Examples
VBA

To use this sample, add the following code to a module in PowerPoint (see F.1.1 Visual Basic for Applications for details).

Option Explicit

Sub GetMekkoGraphicsXMLOfAllShapes()

    ' Get reference to think-cell Object

    Dim tcPpAddIn As Object
    Set tcPpAddIn = Application.COMAddIns("thinkcell.addin").Object

    ' Go through the slides in the presentation and
    ' output the XML of each Mekko Graphics chart on the slide
    ' to the debug console

    Dim slide As PowerPoint.slide
    For Each slide In Application.ActivePresentation.Slides
        Dim shape As PowerPoint.shape
        For Each shape In slide.Shapes
            Debug.Print tcPpAddIn.GetMekkoGraphicsXML(shape)
        Next shape
    Next slide
End Sub
C#

To use this sample replace the code in Program.cs of a Console App with it.

It requires references to the Microsoft PowerPoint 16.0 Object Library and Microsoft Office 16.0 Object Library (see F.1.2 C# for details).

Running the application will go through the presentation in C:\Samples\GetMekkoGraphicsXML\presentation.pptx and print the XML of the Mekko Graphics charts contained in it to the console.

using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Office = Microsoft.Office.Core;

namespace Sample
{
    class Program
    {
        static void Main()
        {
            var ppapp = new PowerPoint.Application();
            var presentation = ppapp.Presentations.Open(
                "C:\\Samples\\GetMekkoGraphicsXML\\presentation.pptx",
                /*ReadOnly*/Office.MsoTriState.msoTrue,
                /*Untitled*/Office.MsoTriState.msoTrue,
                /*WithWindow*/Office.MsoTriState.msoFalse
            );

            var tcPpAddIn = ppapp.COMAddIns.Item("thinkcell.addin").Object;
            foreach (PowerPoint.Slide slide in presentation.Slides)
            {
                foreach (PowerPoint.Shape shape in slide.Shapes)
                {
                    string xml = tcPpAddIn.GetMekkoGraphicsXML(shape);
                    Console.WriteLine(xml);
                }
            }

            presentation.Close();
            ppapp.Quit();
        }
    }
}

F.2.4 Miscellaneous

The functions in this section are methods of the think-cell add-in in PowerPoint.

F.2.4.1 StartTableInsertion

Supported in think-cell 13 and later.

F.2.4.1.1 Signature
VBA
tcPpAddIn.StartTableInsertion()
C#
void tcPpAddIn.StartTableInsertion();
F.2.4.1.2 Description

Calling this method has the same effect as clicking Table in the Elements menu in PowerPoint.

Share