F. API ドキュメンテーション
think-cellを使用すると、API を介して一部の機能をプログラムで制御できます。ここでは、利用可能なすべての API 関数の概要と、開発環境をセットアップしてマクロ、アドイン、またはそれらにアクセスするスタンドアロン プログラムを作成する方法の一般的な手順を確認できます。
F.1 はじめに
think-cell の API は Office Automation モデルに統合されているため、Visual Basic for Applications や C# などの Office をプログラミングできるどんな言語からもアクセスできます。
think-cellへのエントリポイントは、think-cellアドイン オブジェクトです。これには Application.COMAddIns
コレクションからアクセスできます。think-cell への呼び出しは常に遅延バインドされるため、追加するタイプ ライブラリや参照はありません。詳細は、Microsoftのサナレッジベースを参照してください。
一部の API 関数は、PowerPoint のthink-cellアドインオブジェクトのメソッドであり、Excel の一部のthink-cellアドイン オブジェクトのメソッドです。PowerPoint アドインへの参照には tcPpAddIn
を使用し、Excel アドインへの参照には tcXlAddIn
を使用します。
F.1.1 アプリケーション用の Visual Basic
Visual Basic for Applications (VBA) を使用してマクロを作成するには、Office ホスト アプリケーションに統合された開発環境を使用します。これには、Alt+F11 を押すことでアクセスできます。通常、マクロの定義はモジュールに含まれており、Insert > Moduleを介して追加できます。Alt+F8 を押すと、特定のドキュメントに定義されているすべてのマクロを表示できます。
think-cell アドインへのメソッド呼び出しが遅延バインディングであることを示すには、それへの参照を含む変数を Object
として宣言する必要があります。
Dim tcaddin As Object
Set tcaddin = Application.COMAddIns("thinkcell.addin").Object
Office ホスト アプリケーションのタイプ ライブラリは、既定で常に参照されます。別の Office アプリケーションのオブジェクト モデルにアクセスする必要がある場合は、そのタイプ ライブラリを参照として追加する必要があります。
たとえば、Excel シートから think-cell グラフを更新する前に、PowerPoint でマクロを使用して Excel シートのデータを操作する場合、VBA 開発環境のTools
注記: 16.0 は、Office 2016 以降のバージョン番号です。Office 2010 または 2013 の場合、それぞれ 14.0 または 15.0 オブジェクト ライブラリを使用する必要があります。Office の複数のバージョンがインストールされている場合、Referencesダイアログには、インストールされている最新バージョンのオブジェクト ライブラリのみが表示されます。以下では、Office 2016 以降を使用していることを前提としています。
Application.COMAddIns("thinkcell.addin").Object
を使用すると、現在の Office ホスト アプリケーションのthink-cell アドイン オブジェクトが常に取得されます。これは、PowerPoint または Excel のどちらで使用するかに応じて、tcPpAddIn
または tcXlAddIn
です。他の Office アプリケーションでアドイン オブジェクトへの参照を取得し、それが公開する API 関数にアクセスするには、適切なアプリケーション インスタンスを介して取得します。
たとえば、PowerPoint から tcXlAddIn
への参照を取得するには、次のようにします。
Dim xlapp As Object
Set xlapp = New Excel.Application
Dim tcXlAddIn As Object
Set tcXlAddIn = xlapp.COMAddIns("thinkcell.addin").Object
これには、Excel オブジェクト ライブラリを参照として追加する必要があることに注意してください。
すべての変数の明示的な宣言を強制する Option Explicit
ステートメントを使用することをお勧めします。これにより、一般的なプログラミング エラーを回避し、IntelliSense によって提供される提案が改善されます。Tools
F.1.2 C#
C# から think-cell API を使用して、Office ホスト アプリケーション内で実行されるアドインおよびドキュメント コード拡張を開発するとき、およびスタンドアロン アプリケーションを開発するときに使用できます。
以下では、Visual Studio 2017 以降を使用して C# で Office ソリューションを開発していることを前提としています。アドイン開発のためのより具体的なセットアップ手順については、次のセクションを参照してください。各コード サンプルでは、使用する Visual Studio プロジェクト テンプレートを示します。
think-cell アドイン オブジェクトへのメソッド呼び出しを遅延バインディングするには、think-cell アドイン オブジェクトへの参照を含む変数を dynamic
として宣言します。 これは、参照を var
として宣言するときにコンパイラによって推論される型でもあるため、次のように簡単に記述できます。
var tcPpAddIn = ppapp.COMAddIns.Item("thinkcell.addin").Object;
ここで ppapp
は、think-cell が読み込まれる PowerPoint Application
オブジェクトへの参照です。
Office アプリケーションのオブジェクト モデルにアクセスするには、そのタイプ ライブラリまたはプライマリ相互運用機能アセンブリ (PIA) をプロジェクトへの参照として追加する必要があります。可能な場合はタイプ ライブラリを追加することをお勧めします。これは、Visual Studio が対応する PIA への参照を自動的に追加するためです (使用可能な場合)。タイプ ライブラリがない場合は、タイプ ライブラリから相互運用アセンブリを生成します (こちらを参照)。
たとえば、上記の think-cell アドイン オブジェクトへの参照を取得できるようにするには、 Reference Manager ダイアログのCOM > Type Librariesタブにある Microsoft PowerPoint 16.0 Object Libraryを追加します。プロジェクト タイプに応じて、このダイアログにアクセスするには、ソリューション エクスプローラーで References、 またはSolution ExplorerにあるDependenciesを右クリックし、Add (COM) Reference選択します。
注記: 16.0 は、Office 2016 以降のバージョン番号です。COM タイプ ライブラリへの参照に対して既定で有効になっている Embed Interop Types オプションを使用することにより、この参照でコンパイルされたアプリケーションは、使用されるすべてのインターフェイスがオブジェクト モデルに存在する限り、他のバージョンの Office と下位 (および上位) 互換性があります。詳細については、こちらをご覧ください。
think-cell の API 関数は、COM HRESULT
を使用してエラーを示します。これらの一部は、対応する .NET 例外クラスに自動的にマップされます。「方法: HRESULT と例外をマップする」を参照してください。
F.1.2.1 アドインの開発
Office のアドイン、または Office ドキュメントのコード拡張機能を開発するには、 PowerPoint/Excel VSTO Add-inおよび Excel VSTO Template/Workbookプロジェクト テンプレートを使用します。これらは、Office Developer Tools for Visual Studio の一部であり、既定の構成の一部としてインストールされます。これらのツールとテンプレートが Visual Studio のインストールで利用できない場合は、たとえば、Settings⚙ > Apps > Visual Studio 2022 > Modify > Other Toolsetsへアクセスし、Office/SharePoint developmentをチェックして Modifyをクリックすることで、それらを追加できます。こちらの Microsoft のドキュメントもご覧ください。
選択したテンプレートの Office ホスト アプリケーションの PIA は、既定で常に読み込まれます。別の Office アプリケーションのオブジェクト モデルにアクセスする必要がある場合は、上記で説明したように、そのタイプ ライブラリを参照として追加する必要があります。
注記:think-cell の API は Office Web アドインからは使用できません。残念ながら現在、Microsoft では単に「Office アドイン」と呼ばれています。Office アプリケーションのオブジェクト モデルと直接対話することはできず、特に think-cell などの COM アドインと対話することはできません。
F.2 API 参照
F.2.1 要素とプレゼンテーション テンプレートを Excel データで更新する
F.2.1 要素とプレゼンテーション テンプレートを Excel データで更新する
このセクションの関数を使用して、通常はプレゼンテーション テンプレート内のプレースホルダーである think-cell 要素を Excel のデータでプログラム的に更新できます。 UpdateChart
テンプレートで割り当てられた名前で指定された think-cell 要素を、引数として渡された Excel 範囲のデータで更新します。テンプレートの作成方法については、25. オートメーション機能のご紹介 も参照してください。
PresentationFromTemplate
リンクされた Excel ワークブックのデータを使用してプレゼンテーション テンプレートをインスタンス化します。Excel リンクの作成方法については、22. Excel データ リンク も参照してください。
このセクションの関数は、Excel の think-cell アドインのメソッドです。
F.2.1.1 グラフの更新
F.2.1.1.1 署名
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 説明
この関数は、target
内の strName
という名前のすべての要素を、rgData
に含まれるデータで更新します。データがグラフで正しく解釈されるためには、範囲 rgData
が既定のデータシート レイアウトまたはその転置されたバージョンに準拠している必要があります。22.1 Excelからのグラフ作成 および 22.2 データレイアウトの調整 も参照してください。bTransposed
をそれぞれ false
または true
に設定することで、既定バージョンまたは転置バージョンのどちらを使用するかが示されます。グラフ以外の要素、たとえば表の場合、bTransposed
の値は無視されます。
target
は、 Presentation
または SlideRange
、または単一の Slide
、Master
、または CustomLayout
でなければなりません。
グラフ名 strName
は大文字と小文字を区別して整合されます。この機能は以前、25. オートメーション機能のご紹介にあるUpdateChart Name プロパティコントロールを使用してPowerPointに割り当てられていました。
正しい要素がターゲットとなるようにするには、UpdateChart Name.として渡されたオブジェクト内で、strName
がpres
に設定されている唯一の要素だけであることを確認してください。
この関数を呼び出すときに要素が何らかのExcelデータの範囲にリンクされていると、リンクが切断されます。その後、要素はいかなるExcelの範囲にもリンクされません。
F.2.1.1.3 例
これらのサンプルを使用するには、25. オートメーション機能のご紹介 の説明に従ってプレゼンテーションを準備し、C:\Samples\UpdateChart\template.pptx
として保存します。
VBA
このサンプルを使用するには、Excelワークブックのモジュールに追加します。
(詳細はF.1.1 アプリケーション用の Visual Basicを参照)Microsoft PowerPoint 16.0 Object Libraryへの参照が必要です。
ワークブックで UpdateChart_Sample
を実行すると、最初のシートの範囲 A1:D5
に含まれるデータでプレゼンテーション テンプレートのグラフが更新されます。
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#
このサンプルを使用するには、C# Console Appのプロジェクト テンプレートの Program.cs
内のコードをそれに置き換えます。
Microsoft PowerPoint 16.0 Object Library、Microsoft Excel 16.0 Object Library、およびMicrosoft Office 16.0 Object Library への参照が必要です(詳細はF.1.2 C#を参照)。
結果のアプリケーションを実行すると、プレゼンテーション テンプレートのグラフが更新され、値が 1、2、3の「系列 1」という名前の単一の系列が含まれるようになり、結果が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 テンプレートからのプレゼンテーション
F.2.1.2.1 署名
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 説明
この関数は、Excelワークブック wb
とファイル名が strTemplate
のテンプレートとの間のデータリンクを使用して、リンク先の範囲のデータでリンクされた要素を更新することにより、そのテンプレートをインスタンス化します。その結果、PowerPointインスタンス ppapp
内に新しいプレゼンテーションが作成されます。
strTemplate
は完全なパスでも相対パスでもかまいませんが、その後、Excelのブックファイル wb
の場所に関連付けられます。
Excelワークブック wb
にリンクされている strTemplate
のすべての要素は、(自動更新に設定されているかどうかに関係なく) 更新されます。結果のプレゼンテーションでは、これらの要素がさらに変更されるのを防ぐために、それらのデータ リンクが壊れています。
wb
以外のExcelワークブックにリンクされている strTemplate
の要素は変更されずにリンクされているため、この関数の結果を新しいテンプレートとして保存して次のブックでこの関数を再度呼び出すことで、複数のExcelワークブックからリンクを更新できます。
Excelリンクを使用してグラフセグメントの色または表のセルのフォーマットを制御する場合は、配色を Use Datasheet Fill on Top (3.4.2 配色を参照) または Use Datasheet... オプション (17.3 表の書式設定を参照) にそれぞれ設定できます。同様に、Excelリンクで表示形式をコントロールするには、Use Excel Formatに設定します (6.5.3 数値形式を参照)。
PresentationFromTemplate
を呼び出す前に、Excelの各セルの背景色と数値形式を設定してください。
F.2.1.2.3 例
これらのサンプルを使用するには、まず 22.1 Excelからのグラフ作成 で説明されているように、Excelワークブックの最初のシートの範囲 G1:K4
にリンクされた積み上げグラフを含むプレゼンテーションを作成します。結果のプレゼンテーションを C:\Samples\PresentationFromTemplate\template.pptx
として保存し、ワークブックを data.xlsx
として同じディレクトリに保存します。
VBA
このサンプルを使用するには、上記で準備したExcelワークブック data.xlsx
のモジュールに追加します。
(詳細はF.1.1 アプリケーション用の Visual Basicを参照)Microsoft PowerPoint 16.0 Object Libraryへの参照が必要です。
PresentationFromTemplate_Sample
を実行すると、template.pptx
に含まれるチャートの最初の系列の最初の値にリンクされているセル Sheet1!H3
の値が i=1
から 10
に変更され、その値を含むように更新されたテンプレート内のグラフで新しいプレゼンテーションが作成されます。 これはワークブックにリンクされなくなり、テンプレートと同じディレクトリに output_i.pptx
として保存します。
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#
このサンプルを使用するには、C# Console Appプロジェクトテンプレートの Program.cs
内のコードをそれに置き換えます。
Microsoft PowerPoint 16.0 Object Library、Microsoft Excel 16.0 Object Library、およびMicrosoft Office 16.0 Object Library への参照が必要です(詳細はF.1.2 C#を参照)。
結果のアプリケーションを実行すると、目に見えて Excel が開き、ワークブック data.xlsx
が読み込まれ、template.pptx
に含まれるグラフの最初の系列の最初の値にリンクされているセル H3
の値が i=1
から 10
に変更され、その値を含むように更新されたテンプレート内のグラフで新しいプレゼンテーションが作成されます。 これはワークブックにリンクされなくなり、テンプレートと同じディレクトリに output_i.pptx
として保存します。
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 スタイルの制御
このセクションの関数を使用して、プログラムでthink-cellスタイルの読み込み、検査、削除を行うことができます。 LoadStyle
スタイルファイルからスライドマスターまたは単一のレイアウトにスタイルを読み込みます。 LoadStyleForRegion
スタイルファイルからレイアウトの特定の領域にスタイルを読み込みます。 GetStyleName
スライドマスターまたはレイアウトに読み込まれたスタイルの名前を返します。 RemoveStyles
レイアウトからすべてのスタイルを削除します。
スタイルの作成と編集の詳細については、C.1 think-cell スタイルの作成 と D. スタイル ファイル形式 を参照してください。それらの読み込みに関する詳細は、C.2 スタイルファイルの読み込み を参照してください。
このセクションの関数は、PowerPoint の think-cell アドインのメソッドです。
F.2.2.1 LoadStyle
F.2.2.1.1 署名
VBA
tcPpAddIn.LoadStyle( _
CustomLayoutOrMaster As Object, _
FileName As String
)
C#
void tcPpAddIn.LoadStyle(
object CustomLayoutOrMaster,
string FileName
);
F.2.2.1.2 説明
PowerPoint から読みだされたこの機能は、FileName
のスタイルファイルをパラメータ CustomLayoutOrMaster
経由で指定されたスライドマスターまたはレイアウトに読み込みます。
CustomLayoutOrMaster
CustomLayout
または Master
でなければなりません。
地域スタイルが設定されているレイアウトに適用すると (F.2.2.2 LoadStyleForRegion を参照)、地域スタイルは削除されます。これは、地域に制限されたスタイルをロードする前に、この関数を使用してスライドの残りの部分に適用するスタイルをロードする必要があることを意味します。
スライドマスターに適用すると、そのマスターに含まれるレイアウトに読み込まれたスタイル (地域および無制限) が削除されます。これは、この関数を使用して特定のレイアウトに適用するスタイルを読み込む前に、特定のスタイルを持たない レイアウトに適用するスタイルをスライドマスターに読み込む必要があることを意味します。
F.2.2.1.3 例
VBA
このサンプルを使用するには、次のコードを PowerPoint のモジュールに追加します (詳細については、F.1.1 アプリケーション用の Visual Basic を参照してください)。
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 署名
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 説明
PowerPoint から呼び出されたこの機能は、FileName
のスタイルファイルをスライドレイアウトCustomLayout
に読み込み、適用範囲をLeft
、Top
、Width
、Height
によって指定された領域に制限します。スライドの残りの部分では、スライドマスターに読み込まれたスタイル、または以前に LoadStyle
を使用してレイアウトに読み込まれたスタイルが適用されます。
パラメータ Left
、Top
、Width
、Height
は、PowerPoint ポイントで指定されます。 Left
および Top
は、レイアウトの左端および上端から領域の左端および上端までの距離をそれぞれ指定します。通常、これらのパラメータはスライド全体の高さと幅の一部として設定します。たとえば、レイアウトの右側の 3 分の 2 をカバーする地域の場合、次のように設定します。
Left = CustomLayout.Width / 3
Top = 0
Width = CustomLayout.Width * 2 / 3
Height = CustomLayout.Height
また、スライドやレイアウトに手動で図形を追加することや、プログラムで図形のプロパティ、Left
、Top
、Width
、Height
をクエリすること、LoadStyleForRegion
と数値を使用してスタイルを図形で覆われている同じ領域に制限することもできます。
レイアウト 1 件につき think-cell は最大 2 つのスタイルをサポートします。ひとつはLoadStyle
を使用して設定し、領域に制限されていない部分すべてに適用されるスタイルで、もうひとつはLoadStyleForRegion
を使用して設定するスタイルとなります。
F.2.2.2.3 例
VBA
このサンプルを使用するには、次のコードを PowerPoint のモジュールに追加します (詳細については、F.1.1 アプリケーション用の Visual Basic を参照してください)。
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 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
think-cell 14 以降で利用可能です。
F.2.2.3.1 署名
VBA
tcPpAddIn.GetStyleName( _
CustomLayoutOrMaster As Object _
) As String
C#
string tcPpAddIn.GetStyleName(
object CustomLayoutOrMaster
);
F.2.2.3.2 説明
この関数は、CustomLayout
または Master
CustomLayoutOrMaster
に読み込まれたスタイルの名前を返します。これは、対応するスタイルファイルの <style>
要素の name
属性に指定されている名前と同じです (D.2.1 style を参照)。
スタイルが CustomLayoutOrMaster
に読み込まれていない場合は、空の文字列を返します。think-cell がアクティブな場合、スライドマスターには常にスタイルが読み込まれており、スタイルの名前を空にすることはできないことに注意してください。
CustomLayout
に対して名前が返された場合、それは F.2.2.1 LoadStyle で読み込またスタイルの名前であり、F.2.2.2 LoadStyleForRegion で読み込まれたスタイルの名前ではありません。
F.2.2.3.3 例
VBA
このサンプルを使用するには、次のコードを PowerPoint のモジュールに追加します (詳細については、F.1.1 アプリケーション用の Visual Basic を参照してください)。
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 署名
VBA
tcPpAddIn.RemoveStyles( _
CustomLayout As PowerPoint.CustomLayout _
)
C#
void tcPpAddIn.RemoveStyles(
PowerPoint.CustomLayout CustomLayout
);
F.2.2.4.2 説明
PowerPoint から呼び出されたこの機能は、スライドレイアウトCustomLayout
からすべてのスタイルを削除します。その後、スライドマスターに読み込まれたスタイルが適用されます。レイアウトにスタイルが読み込まれており、別のスタイルがレイズとの指定の領域に制限されている可能性があります。RemoveStyles
はすべてのスタイルを削除するため、この両方が削除されます。スライドマスターには常に有効なスタイルを関連付ける必要があるため、スライドマスターに読み込まれたスタイルは削除できません。別のスタイルファイルで上書きすることはできます。
F.2.2.4.3 例
VBA
このサンプルを使用するには、次のコードを PowerPoint のモジュールに追加します (詳細については、F.1.1 アプリケーション用の Visual Basic を参照してください)。
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 マリメッコ グラフィック グラフのインポート
このセクションの関数を使用すると、マリメッコ グラフィックで作成されたグラフをプログラムで think-cell にインポートして検査できます。 ImportMekkoGraphicsCharts
マリメッコ グラフィック グラフを同等の think-cell グラフに置き換えます。 GetMekkoGraphicsXML
マリメッコ グラフィック グラフの XML 定義を抽出します。
このセクションの関数は、PowerPoint の think-cell アドインのメソッドです。
F.2.3.1 ImportMekkoGraphicsCharts
think-cell 14 以降で利用可能です。
F.2.3.1.1 署名
VBA
tcPpAddIn.ImportMekkoGraphicsCharts ( _
ashp As PowerPoint.Shape() _
) As PowerPoint.Slide
C#
PowerPoint.Slide tcPpAddIn.ImportMekkoGraphicsCharts(
PowerPoint.Shape[] ashp
);
F.2.3.1.2 説明
この関数は、渡された Shape
の配列内のすべてのマリメッコ グラフィック グラフを同等の think-cell グラフに置き換えます。図形はすべて、同じスライド上になくてはなりません。スライドを変更する前に、この関数は未変更のスライドのコピーを作成し、変更されたバージョンの直後に挿入します。
この関数は、このコピーが作成されている場合、そのコピーへの参照を返します。
たとえば、配列にマリメッコ グラフィック グラフが含まれていないなどの理由で、プレゼンテーションが変更されなかった場合は、Nothing
/null
を返します。
F.2.3.1.3 例
VBA
このサンプルを使用するには、PowerPoint のモジュールに追加します (詳細については、F.1.1 アプリケーション用の Visual Basic を参照)」。
プレゼンテーションで ImportAll
を実行すると、プレゼンテーション内のスライドが調べられ、表示されているすべてのマリメッコ グラフィック グラフが同等のthink-cellグラフに置き換えられ、変更する前に、そのグラフを含む各スライドのコピーが作成されます。
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#
このサンプルを使用するには、このメソッドを C# PowerPoint VSTO Add-in プロジェクト テンプレートの ThisAddIn
クラスに追加します (詳細については、F.1.2 C# と F.1.2.1 アドインの開発 を参照)。
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()
);
}
}
次の行を ThisAddIn_Startup
メソッドに追加して、開かれているプレゼンテーションごとに ImportAll
を実行します。
Application.PresentationOpen += new PowerPoint.EApplication_PresentationOpenEventHandler(ImportAll);
F.2.3.2 GetMekkoGraphicsXML
think-cell 14 以降で利用可能です。
F.2.3.2.1 署名
VBA
tcPpAddIn.GetMekkoGraphicsXML ( _
shp As PowerPoint.Shape _
) As String
C#
string tcPpAddIn.GetMekkoGraphicsXML(
PowerPoint.Shape shp
);
F.2.3.2.2 説明
この関数は、shp
内のマリメッコ グラフィック グラフの XML を文字列として返します。渡された形状は変更されません。
shp
がマリメッコ グラフィック グラフではない場合、E_INVALIDARG (0x80070057)
エラーが発生します。
F.2.3.2.3 例
VBA
このサンプルを使用するには、次のコードを PowerPoint のモジュールに追加します (詳細については、F.1.1 アプリケーション用の Visual Basic を参照してください)。
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#
このサンプルを使用するには、Program.cs
内のConsole Appのコードをこれに置き換えてください。
(詳細はMicrosoft Office 16.0 Object Libraryを参照)Microsoft PowerPoint 16.0 Object LibraryおよびF.1.2 C# への参照が必要です。
アプリケーションを実行すると、C:\Samples\GetMekkoGraphicsXML\presentation.pptx
のプレゼンテーションが実行され、それに含まれるマリメッコ グラフィック グラフの XML がコンソールに出力されます。
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
このセクションの関数は、PowerPoint の think-cell アドインのメソッドです。
F.2.4.1 StartTableInsertion
think-cell 14 以降で利用可能です。
F.2.4.1.1 署名
VBA
tcPpAddIn.StartTableInsertion()
C#
void tcPpAddIn.StartTableInsertion();
F.2.4.1.2 説明
このメソッドを呼び出すと、PowerPoint のElements メニューで Table をクリックするのと同じ効果があります。