c# - 在 C# 中从 TreeView 创建 SmartArt

标签 c# .net office-automation office-pia

有没有办法根据用户在 C# Windows 窗体应用程序中创建的 TreeView 在 Word 中创建 SmartArt 层次结构图表?

感谢您的帮助。

最佳答案

像这样尝试:

private void button2_Click(object sender, EventArgs e)
{
    Word._Application oWord;
    Word._Document oDoc;
    oWord = new Word.Application();
    oWord.Visible = true;
    oDoc = oWord.Documents.Add();

    // here try from 1 to 15 until you find the layout you are interested in...
    var myLayout = oDoc.Application.SmartArtLayouts[8];

    var smartArtShape = oDoc.Shapes.AddSmartArt(myLayout, 50, 50, 200, 200);

    smartArtShape.AlternativeText = "xxxx";
}

这将配置为使用 layout nr 8 的 SmartArt Shape 放入文档中。它没有很好的记录,我花了很多时间来寻找正确的文章和示例:

了解您不能使用 new 关键字创建 SmartArtLayout 对象,但应使用应用程序布局集合提供的任何对象,这一点非常重要... Application.SmartArtLayouts Property (Word)

这是一些背景... Creating Custom SmartArt Layouts with Office Open XML for Office 2007 and Office 2010

祝你好运:)

关于c# - 在 C# 中从 TreeView 创建 SmartArt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9268630/

相关文章:

c# - 多线程上的 WPF UI?

c# - 为什么这个方法调用不调用派生类?

c# - 如何在 ASP.NET Web Api 中配置 gzip 压缩响应?

c# - 使用 Oracle 零日期

.net - Enterprise Services 的事务和池功能是否有现代替代品?

c# - 从 C# 打开的 Outlook 新邮件窗口似乎有焦点,但我的应用程序仍然有它

c# - System.Drawing.dll 中出现类型为 'System.ApplicationException' 的未处理异常

.net - F# 库中是否有任何 "List.divideAt"HOF?

c# - C# 中的引用和意外结果

excel - 运行delphi客户端自动化程序后excel.exe保持加载状态的原因是什么?