导入 Mekko Graphics 图表

将 Mekko Graphics 图表及其数据便捷地导入 thinkcell。

将 Mekko Graphics 图表导入 thinkcell

Import Mekko Graphics to thinkcell 工具会将 Mekko Graphics 图表转换为 thinkcell 图表。使用 thinkcell 导入工具无需安装 Mekko Graphics。

要将 Mekko Graphics 图表导入 thinkcell,请按以下步骤操作:

  1. 在 PowerPoint 中,选择幻灯片上的一个或多个 Mekko Graphics 图表,或选择包含 Mekko Graphics 图表的幻灯片。
  2. 在功能区中,选择 thinkcell > Elements > Tools 工具菜单图标 > Import Mekko Graphics to thinkcell 或 Insert > thinkcell > Tools 工具菜单图标 > Import Mekko Graphics to thinkcell。

选择 Import Mekko Graphics to thinkcell 后,thinkcell 会将你选择的 Mekko Graphics 图表替换为 thinkcell 图表。所有其他幻灯片内容保持不变。每张替换了 Mekko Graphics 图表的幻灯片之后,thinkcell 都会插入一张包含原始 Mekko Graphics 图表的备份幻灯片。

你可以将大多数 Mekko Graphics 图表导入 thinkcell,但以下情况除外:

  • 甘特图、浮动条形图和水平浮动条形图
  • 其他 Mekko Graphics 元素,例如 Harvey balls

如果某个 Mekko Graphics 图表或元素无法导入,thinkcell 会显示一条消息。

导入包含数据行或列的图表

如果 Mekko Graphics 图表包含数据行或列,thinkcell 会将该图表导入为带数据表的 thinkcell 图表(请参阅 带数据表的图表)。Mekko Graphics 图表可能会在数据表和图表中同时表示相同数据。thinkcell 目前不支持在数据表和图表中同时表示相同数据。如果 Mekko Graphics 图表在数据表和图表中表示相同数据,thinkcell 将在导入该图表时不带数据表。

设置导入图表的样式和格式

thinkcell 不会导入 Mekko Graphics 图表的样式和格式。不过,导入 Mekko Graphics 图表后,你可以轻松地在 thinkcell 中重新创建该图表的样式和格式。

设置图表样式

当 thinkcell 导入 Mekko Graphics 图表时,导入的图表会采用当前 thinkcell 样式文件的样式和格式(请参阅 设置 thinkcell 样式文件)。你可以像设置其他 thinkcell 图表一样设置导入图表的格式和样式(请参阅 设置图表样式和格式)。

下图展示了如何使用图表的上下文菜单为导入的图表添加 Y 轴。

Use thinkcell's context menu to add axis

设置数字格式

Mekko Graphics 图表中的大多数数字格式不会导入到 thinkcell 图表中。你可以在 thinkcell 中轻松更改数字格式(请参阅 设置图表标签格式)。

下图展示了如何使用迷你工具栏,将原始 Mekko Graphics 图表的货币数字格式应用到导入的图表。

建议比较 Mekko Graphics 图表和导入的图表,确保它们保持一致。在原始幻灯片和备份幻灯片之间切换进行比较,并对导入的图表进行必要更改。对导入的图表满意后,可以删除备份幻灯片。

编辑导入的图表数据

thinkcell 会将 Mekko Graphics 图表中的数据导入到导入图表的数据表中。你可以像编辑任何其他 thinkcell 图表一样编辑导入图表的数据(请参阅 元素数据表简介)。

显示隐藏的系列或类别

thinkcell 会将 Mekko Graphics 图表中隐藏系列或类别的数据作为隐藏行或列导入到导入图表的数据表中。要在导入的图表中显示隐藏的系列或类别,请在图表数据表中选择包含隐藏数据的列或行,右键单击所选内容,然后选择 Unhide。了解更多信息,请参阅 Microsoft 支持。

自动化导入流程

仅限 Windows

在 Windows 上,你可以使用 thinkcell API 函数以编程方式将 Mekko Graphics 图表导入 thinkcell,或检查这些图表。ImportMekkoGraphicsCharts 会将 Mekko Graphics 图表替换为 thinkcell 图表。GetMekkoGraphicsXML 会提取 Mekko Graphics 图表的 XML 定义。

ImportMekkoGraphicsCharts

说明

此函数会将传入的形状数组中的所有 Mekko Graphics 图表替换为等效的 thinkcell 图表。所有形状必须位于同一张幻灯片上。在修改幻灯片之前,该函数会复制一份未修改的幻灯片,并将其直接插入到修改后版本的后面。

如果幻灯片未被修改,例如数组中不包含任何 Mekko Graphics 图表,则该函数返回 Nothing/null。否则,该函数返回未修改幻灯片副本的引用。

VBA

签名
tcPpAddIn.ImportMekkoGraphicsCharts ( _
    ashp As PowerPoint.Shape() _
) As PowerPoint.Slide
示例

要使用此示例,请将其添加到 PowerPoint 中的一个模块。要了解更多信息,请参阅 Visual Basic for Applications。

在演示文稿上运行 ImportAll 会遍历该演示文稿中的幻灯片,并将所有可见的 Mekko Graphics 图表替换为等效的 thinkcell 图表;在修改每张包含 Mekko Graphics 图表的幻灯片之前,都会先创建该幻灯片的副本。

Option Explicit

Sub ImportAll()

    ' Get reference to thinkcell 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#

签名
PowerPoint.Slide tcPpAddIn.ImportMekkoGraphicsCharts(
    PowerPoint.Shape[] ashp
);
示例

要使用此示例,请在 C# PowerPoint VSTO Add-in 项目模板中,将此方法添加到 ThisAddIn 类。要了解更多信息,请参阅 C# 和 加载项开发。

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()
            );
        }
    }

要在每个已打开的演示文稿上运行 ImportAll,请将以下行添加到 ThisAddIn_Startup 方法。

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

GetMekkoGraphicsXML

说明

此函数以字符串形式返回 shp 中 Mekko Graphics 图表的 XML 代码。它不会修改传入的形状。

如果 shp 不是 Mekko Graphics 图表,则会引发 E_INVALIDARG (0x80070057) 错误。

VBA

签名
tcPpAddIn.GetMekkoGraphicsXML ( _
    shp As PowerPoint.Shape _
) As String
示例

要使用此示例,请将以下代码添加到 PowerPoint 中的一个模块。要了解更多信息,请参阅 Visual Basic for Applications。

Option Explicit

Sub GetMekkoGraphicsXMLOfAllShapes()

    ' Get reference to thinkcell 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
            On Error Resume Next ' skip over shapes that are not Mekko Graphics charts
            Debug.Print tcPpAddIn.GetMekkoGraphicsXML(shape)
        Next shape
    Next slide
End Sub

C#

签名
string tcPpAddIn.GetMekkoGraphicsXML(
    PowerPoint.Shape shp
);
示例

要使用此示例,请将 Console App 的 Program.cs 中的代码替换为该示例。

此示例需要引用 Microsoft PowerPoint 16.0 Object Library 和 Microsoft Office 16.0 Object Library(详情请参阅 C#)。

运行该应用程序会遍历 C:\Samples\GetMekkoGraphicsXML\presentation.pptx 中的演示文稿,并将该演示文稿所含 Mekko Graphics 图表的 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();
        }
    }
}

需要排查问题吗?

查看我们的知识库