The situation is the following:
I am using SQL Server Reporting Service to produce a report that is exported to Word 2010. The report itself comes out as a set of nested tables. I need to be able to reach in to one of these inner tables and add a Text Box to a specific cell in the table.
I need to do this in a way that I can do it I a loop, to loop through all of the rows in the specific table. The table can have n rows, and this cell needs to be modified in each of them. The problem, therefore is twofold. I need to be able to index into the correct table and get a pointer to the specific cell, and then I need to modify the contents of the cell to have a single text box control in it. It is my understanding that you use the shapes collection to add the text box itself, but I don't know how to get a reference to the specific cell of the specific table, and find the shapes collection that is associated with it.
Any help on this would be greatly appreciated.
I am using this code to try and iterate the tables in the document, but there is no "HasTable" property, just one for "HasChart" and "HasSmartArt"
Dim Shp As Shape
For Each Shp In ThisDocument.InlineShapes
If Shp.HasTable Then
MsgBox "Found Table"
End If
Next Shp
This code will add a text box but I don't see how to get this to be in the right column of the table I am working with, nor does this give me a way t index through all of the rows in the table adding the text box:
ActiveDocument.Shapes.AddTextbox _
Orientation:=msoTextOrientationHorizontal, _
Left:=lLeft,
Top:=6, _
Width:=72, _
Height:=12
I have tried the following and it doesn't seem to help:
Dim tbl As Word.Table For Each tbl In ActiveDocument.Tables
tbl.Columns.Select If tbl.Tables.Count > 0 Then tbl.Tables(1).Select ActiveDocument.Shapes.AddTextbox Orientation:=msoTextOrientationHorizontal, _ Left:=tbl.Tables(1).Columns.Borders.DistanceFromLeft, _ Top:=tbl.Tables(1).Columns.Borders.DistanceFromTop, _ Width:=72, _ Height:=12 End If Next tbl
This will add the text box, but it doesn't put it in the right cell.
The Visual Tree in XAML is a hierarchical data structure that contains all the visual elements of a XAML page. You can walk it recursively looking for specific nodes, and then modify the content of the given node once you find that. That is what I am trying to do here, but I am not seeing that kind of structure
InlineShapescollection. Iterate that collection checking for whether each shape's.HasTable = Trueproperty, and then you should be able to work with the table that way. - David Zemens