I currently have a 1 page report which uses purely Aspose.Diagram. There was been a request from my users to add a chart/table to the 2nd page of the report, which will give them a different representation of the data shown on the first page.
Now, as far as creating a table on the 2nd page, should I continue and use Aspose.diagram for that, or should I incorporate a different Aspose component to handle this part of my project.
Thanks,
Nick
Hi Nick,
Thank you for contacting support. You can drag and drop a grid shape in the Visio drawing. It is a group shape and we can iterate through the sub shapes to set each cell value. Please refer to these help topics: Add a Table to a Drawing [Microsoft URL: Manual Way], Adding a new Shape in the Visio and Connect Sub-shapes of the Groups
Please let us know in case of any confusion or questions.
Imran-
I cannot get the color of the Grid to change.
I have the current code:
// Add master with stencil file path and master name
string masterName = “Grid”;
diagram.AddMaster(CHARTSHAPES_VISIO, masterName);
Shape gridShape = new Shape();
gridShape.Fill.FillForegnd.Value = “#DEC2B8”;
gridShape.Fill.FillBkgnd.Value = “#DEC2B8”;
diagram.Pages[1].AddShape(gridShape, “Grid”);
yet, the color of the Grid remains unchanged on the output file.
Imran,
In addition to not having any success changing the color of the grid, I cannot target the individual rows/columns of the grid per your suggestion.
When I try to get SubShapes of the “parent” grid, I can’t seem to figure out how to do this properly - the resulting collections are always null.
Shape gridShape = new Shape();
gridShape.Fill.FillForegnd.Value = “#DEC2B8”;
gridShape.Fill.FillBkgnd.Value = “#DEC2B8”;
var connectedShapes = gridShape.ConnectedShapes(ConnectedShapesFlags.ConnectedShapesAllNodes, null);
var connections = gridShape.Connections;
var shapes = gridShape.Shapes;
connectedShapes, connections and shapes variables all remain null after method calls.
Please advise to how I can iterate the Grid’s cells.
Thanks
Hi Nick,
nvielbig:
yet, the color of the Grid remains unchanged on the output file.
Thank you for the inquiry. Please provide us your complete code, source stencil and Visio drawing (if any). It'll help us to replicate the exact scenario.
nvielbig:
When I try to get SubShapes of the "parent" grid, I can't seem to figure out how to do this properly - the resulting collections are always null.
connectedShapes, connections and shapes variables all remain null after method calls.
The ConnectedShapes method returns IDs of the shapes connected through the connectors. We can iterate through the sub shapes of a group shape as below:
[.NET, C#]
// load a diagram
Diagram diagram = new Diagram(@"C:\AD\test828\Drawing1.vsdx");
// get a grid shape by ID
Shape gridShape = diagram.Pages[0].Shapes.GetShape(1);
// iterate through the sub shapes
foreach (Shape shape in gridShape.Shapes)
{
shape.Text.Value.Clear();
shape.Text.Value.Add(new Txt("New Text"));
}
// save diagram
diagram.Save(@"C:\AD\test828\Out001.vsdx", SaveFileFormat.VSDX);
Imran, thank you for your response.
The bolded loop in the code below will never be run for me. gridShape.Shapes is a null collection, and therefore no looping will occur. Is there a reason that my Grid doesn't have a Shapes property for the cells within?
The ConnectedShapes method returns IDs of the shapes connected through the connectors. We can iterate through the sub shapes of a group shape as below:
[.NET, C#]
// load a diagram
Diagram diagram = new Diagram(@"C:\AD\test828\Drawing1.vsdx");
// get a grid shape by ID
Shape gridShape = diagram.Pages[0].Shapes.GetShape(1);
// iterate through the sub shapes
foreach (Shape shape in gridShape.Shapes)
{
shape.Text.Value.Clear();
shape.Text.Value.Add(new Txt("New Text"));
}
// save diagram
diagram.Save(@"C:\AD\test828\Out001.vsdx", SaveFileFormat.VSDX);
Hi Nick,
Thank you for the inquiry. Please use the latest version 16.11.0 of Aspose.Diagram for .NET API and run the code example as below. It works fine at our end. We’ve attached output VSDX and stencil file for your kind reference.
[.NET, C#]
// load a diagram
Diagram diagram = new Diagram();
// get page by name
Page page = diagram.Pages[0];
// add master with stencil file path and master name
string masterName = “Grid”;
diagram.AddMaster(@“C:\AD\test828\Charting Shapes.vssx”, masterName);
// page indexing starts from 0
int PageIndex = 0;
double pinX = 5.25, pinY = 4.5;
// add a new rectangle shape
long gridID = diagram.AddShape(pinX, pinY, masterName, PageIndex);
Shape gridShape = page.Shapes.GetShape(gridID);
// iterate through the sub shapes
foreach (Shape shape in gridShape.Shapes)
{
shape.Text.Value.Clear();
shape.Text.Value.Add(new Txt(“New Text”));
}
// save diagram
diagram.Save(@“C:\AD\test828\Out.vsdx”, SaveFileFormat.VSDX);
Thanks for your reply Imran.
I have started going another route with this project, but should I come back to using Aspose Diagram for this part of the project, I will refer to your notes.
Regards
Hi Nick,
Thank you for the inquiry. You can use Aspose.Diagram API anytime in your application project and let us know if you come across any problem. We’ll help you appropriately.