Question

Is there a way to create a SmartArt Hierarchy chart in Word from a treeview that the user creates in a C# Windows Forms application?

Thanks for any help.

Was it helpful?

Solution

try like this:

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";
}

this puts in the document the SmartArt Shape configured to use the layout nr 8. It's not really well documented and I spent much time in finding the right articles and samples:

this is very important to understand that you cannot create a SmartArtLayout object with the new keyword but should use any of those provided by the Application's layout collection... Application.SmartArtLayouts Property (Word)

This is some background... Creating Custom SmartArt Layouts with Office Open XML for Office 2007 and Office 2010

Good luck :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top