Hi Team,
Can we draw this smartart using aspose cells from scratch?
Radial Cluster SmartArt.zip (22.7 KB)
Short answer
Aspose.Cells cannot create a SmartArt object (e.g., a Radial Cluster) from scratch. It can only work with SmartArt that already exists in a workbook. To get the desired result you have three practical alternatives:
| Option | How it works | When to use it |
|---|---|---|
| Use a prepared template | Create the Radial Cluster SmartArt manually in Excel, save the file, and let Aspose.Cells populate it with data (using Smart Markers). | You need an editable SmartArt in the final workbook and only have to fill it programmatically. |
| Emulate the visual with a chart | Build a radar (or polar) chart that looks similar to the Radial Cluster. Aspose.Cells fully supports chart creation and styling. | A chart‑based representation is acceptable. |
| Create SmartArt with Aspose.Slides and embed it as an image | Generate the SmartArt in a PowerPoint slide with Aspose.Slides, export the slide (or the SmartArt) as PNG/JPEG, then insert that picture into the Excel sheet with Aspose.Cells. | You only need a static visual that matches the SmartArt design. |
Below are minimal, tested code snippets for each approach (C# /.NET; equivalent APIs exist for Java, Python, etc.).
1. Fill an existing SmartArt template (Smart Markers)
using Aspose.Cells;
using System.Collections.Generic;
using System.Data;
class Program
{
static void Main()
{
// 1. Load the workbook that already contains the Radial Cluster SmartArt.
var wb = new Workbook("RadialClusterTemplate.xlsx");
// 2. Prepare the data that will be bound to the SmartArt.
var dt = new DataTable("Data");
dt.Columns.Add("Product", typeof(string));
dt.Columns.Add("Index", typeof(int));
dt.Rows.Add("P1", 120);
dt.Rows.Add("P2", 135);
dt.Rows.Add("P3", 210);
dt.Rows.Add("P4", 165);
dt.Rows.Add("P5", 130);
// 3. Put the table into a DataSet.
var ds = new DataSet();
ds.Tables.Add(dt);
// 4. Process SmartMarkers – the SmartArt will be updated automatically.
wb.WorkbookDesigner.Process(ds);
// 5. Save the result.
wb.Save("RadialClusterFilled.xlsx");
}
}
Key points
- The SmartArt must already exist in the template workbook.
- Place SmartMarker expressions (e.g.,
${Data.Product},${Data.Index}) in the cells that drive the SmartArt. WorkbookDesigner.Processupdates the SmartArt with the supplied data.
2. Build a radar chart that resembles a Radial Cluster
using Aspose.Cells;
using System.Drawing;
class Program
{
static void Main()
{
var wb = new Workbook();
var ws = wb.Worksheets[0];
// Sample data
ws.Cells["A1"].PutValue("Product");
ws.Cells["B1"].PutValue("Index");
string[] products = { "P1", "P2", "P3", "P4", "P5" };
int[] indexes = { 120, 135, 210, 165, 130 };
for (int i = 0; i < products.Length; i++)
{
ws.Cells[i + 2, 0].PutValue(products[i]); // Column A
ws.Cells[i + 2, 1].PutValue(indexes[i]); // Column B
}
// Add a radar chart
int chartIdx = ws.Charts.Add(ChartType.Radar, 5, 0, 25, 10);
var chart = ws.Charts[chartIdx];
chart.NSeries.Add("B2:B6", true);
chart.NSeries.CategoryData = "A2:A6";
// Optional styling to make it look more like SmartArt
chart.Title.Text = "Radial Cluster (Radar)";
chart.Title.Font.Color = Color.DarkBlue;
chart.PlotArea.AreaBorder.IsVisible = false;
wb.Save("RadialClusterRadar.xlsx");
}
}
A radar chart is fully supported by Aspose.Cells and can be styled (colors, markers, data labels) to approximate the appearance of the SmartArt.
3. Generate SmartArt with Aspose.Slides and embed it as a picture
using Aspose.Slides;
using Aspose.Cells;
using System.IO;
class Program
{
static void Main()
{
// 1️⃣ Create the SmartArt in a PowerPoint slide.
var pres = new Presentation();
var slide = pres.Slides[0];
var smartArt = slide.Shapes.AddSmartArt(0, 0, 500, 400,
SmartArtLayoutType.RadialCluster);
// (Optionally fill the SmartArt with data here.)
// 2️⃣ Export the slide (or just the SmartArt) as PNG.
using (var imgStream = new MemoryStream())
{
pres.Save(imgStream, Aspose.Slides.Export.SaveFormat.Png);
imgStream.Position = 0;
// 3️⃣ Insert the image into an Excel workbook.
var wb = new Workbook();
var ws = wb.Worksheets[0];
int pictureIdx = ws.Pictures.Add(2, 2, imgStream);
ws.Pictures[pictureIdx].Height = 300; // adjust as needed
wb.Save("RadialClusterWithImage.xlsx");
}
}
}
This method gives you the exact SmartArt design (created by the full SmartArt engine) but the result in Excel is a static image, not an editable SmartArt object.
Recommendation
| Need | Best approach |
|---|---|
| Editable SmartArt inside the workbook | Start from a template that already contains the SmartArt and populate it with Smart Markers (Option 1). |
| Static visual that matches the design | Create the SmartArt with Aspose.Slides and embed it as an image (Option 3). |
| Acceptable to use a chart instead of SmartArt | Build a radar chart directly with Aspose.Cells (Option 2). |
Bottom line: Aspose.Cells alone cannot create a Radial Cluster SmartArt from scratch. Use a pre‑populated template, a radar chart, or combine Aspose.Slides with Aspose.Cells as shown above.
Aspose.Cells does not currently support creating SmartArts from scratch in one step. However, you can manually create SmartArts in MS Excel, and Aspose.Cells can read, preserve, or slightly modify these shapes from a template file. Alternatively, you can add individual shapes, such as rectangles, lines, etc., to design a structure resembling SmartArt. For more details on adding shapes, refer to the documentation on drawing shapes.