Aspose Excel to SVG adding external image placed at wrong position

I am creating a bubble chart using OpenXML and then utilizing Aspose.Cells and Aspose.Imaging for extracting the chart from excel and saving it as SVG. I am using C# with Aspose.Cells version 22.1.0 and Aspose.Imaging version 22.4.0.

Since bubble charts do not support symbols directly, I am adding Plus.png as external images. However, when the SVG is generated, the Plus.png image appears in a different location compared to its position in Excel.

Below is an image of the chart in Excel:
image.png (26.1 KB)

And here is the generated SVG using Aspose:
image.png (33.0 KB)

Any guidance on resolving this issue would be greatly appreciated.

@manojbhide
Would you like to provide your sample file and test code? we will check it soon.

@John.He Thanks for the reply, I am adding some snippets of how I add image to Aspose.Cells.Charts.Chart. I had to add external image because Aspose does not recognize the marker symbols from an excel document.

///


/// Identify the series and add external image as shape fill to it.
/// We are adding images to Aspose Chart as well due to the limitation where
/// Aspose does not recognize the marker symbols from an excel document.
///

///
///
private void AddExternalImages(Chart chart, IEnumerable externalImageSeries)
{
foreach (var image in externalImageSeries)
{
var chartSeries = chart.NSeries.Find(s => s.Name == image.ExternalMarkerImage.SeriesName);
chartSeries.Area.FillFormat.FillType = Aspose.Cells.Drawing.FillType.Texture;
chartSeries.Area.FillFormat.ImageData = File.ReadAllBytes(image.ExternalMarkerImage.ImagePath);
}
}

private FileInfo CreateSvgFromChart(Aspose.Cells.Charts.Chart chart, Aspose.Cells.Worksheet worksheet, string svgFile)
{
FileInfo newFile = new(svgFile);

 double chartWidth = 0;
 double chartHeight = 0;
 double chartWidthInch = 0;
 double chartHeightInch = 0;

 // Iterate over the range of cells to calculate the total width and height
 for (int i = chart.ChartObject.UpperLeftColumn; i <= (chart.ChartObject.LowerRightColumn); i++)
 {
     chartWidth += worksheet.Cells.GetColumnWidthPixel(i);
     chartWidthInch += worksheet.Cells.GetColumnWidthInch(i);
 }

 for (int i = chart.ChartObject.UpperLeftRow; i <= (chart.ChartObject.LowerRightRow); i++)
 {
     chartHeight += worksheet.Cells.GetRowHeightPixel(i);
     chartHeightInch += worksheet.Cells.GetRowHeightInch(i);
 }

 // Save the chart as SVG with the calculated dimensions
 ImageOrPrintOptions opts = new ()
 {
     OnePagePerSheet = true,
     // Set the custom width and height
     HorizontalResolution = (int)chartWidth,
     VerticalResolution = (int)chartHeight,
     SaveFormat = Aspose.Cells.SaveFormat.Svg,
     SVGFitToViewPort = true
 };

 chart.ChartObject.HeightInch = chartHeightInch;
 chart.ChartObject.WidthInch = chartWidthInch;

 //Resize chart Object based on height and width.
 //ReSizeChartObject(chart, chartFormat);
 chart.ToImage(newFile.FullName, opts);
 return newFile;

}

@manojbhide
Could you share a template Excel file ? We will check it soon.
And it’s better you can share the file with the marker symbols .

@simon.zhao Thanks for your reply.
Please find attached zip containing

  1. input excel(which is generated using OpenXml),
  2. Plus.png - Extenal image that I am trying to add to Aspose Chart
  3. and a sample output that is currently positioning the plus.png little off than the input excel
    sample files.zip (8.1 KB)

@manojbhide,

Thanks for the template Excel file and details.

After an initial testing, I was able to reproduce the issue as you mentioned by using the following sample code with your template file. I found external image is placed at wrong position in Excel chart to SVG rendering.

Workbook workbook = new Workbook("e:\\test2\\sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
Chart chart = worksheet.Charts[0];
 double chartWidth = 0;
 double chartHeight = 0;
 double chartWidthInch = 0;
 double chartHeightInch = 0;

 // Iterate over the range of cells to calculate the total width and height
 for (int i = chart.ChartObject.UpperLeftColumn; i <= (chart.ChartObject.LowerRightColumn); i++)
 {
     chartWidth += worksheet.Cells.GetColumnWidthPixel(i);
     chartWidthInch += worksheet.Cells.GetColumnWidthInch(i);
 }

 for (int i = chart.ChartObject.UpperLeftRow; i <= (chart.ChartObject.LowerRightRow); i++)
 {
     chartHeight += worksheet.Cells.GetRowHeightPixel(i);
     chartHeightInch += worksheet.Cells.GetRowHeightInch(i);
 }

 // Save the chart as SVG with the calculated dimensions
 ImageOrPrintOptions opts = new ()
 {
     OnePagePerSheet = true,
     // Set the custom width and height
     HorizontalResolution = (int)chartWidth,
     VerticalResolution = (int)chartHeight,
     ImageType = ImageType.Svg,
     SVGFitToViewPort = true
 };

 chart.ChartObject.HeightInch = chartHeightInch;
 chart.ChartObject.WidthInch = chartWidthInch;

 chart.ToImage("e:\\test2\\out1.svg", opts);

We require thorough evaluation of the issue. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSNET-56197

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@amjad.sahi Thanks for your reply. I verified that my company has opted for paid support, but I am unable to log in. Does access need to be initiated by a specific person within the company?

@manojbhide
Our paid support team will assist you log in Containerize.IdentityServer - Single sign-on to access all applications and services of Aspose Pty Ltd. soon.

And we will try our best to reslove this Bug of chart2image.

BTW the series is filled by image in the attached file . We can directly export the chart to svg with 24.7 though there are still two issues: image position and axis’ title position.

Could you post a template file with the marker symbols ?

Hi @manojbhide,

Please note that your company has active Business Support linked to the email address shisoftwarepurchases@broadridge.com.

The helpdesk supports sub-accounts and the owner of the subscription (shisoftwarepurchases@broadridge.com) can add you as a subaccount so you can access the Paid Support ticket system. For more information, kindly check the following guide: Paid Support Helpdesk - aspose.com

If you encounter any issues or have questions, please let me know.

Thanks!

Hi @manojbhide
We optimized for this problem and the result is the following attachment,
This is expected to take effect in version 24.8.

240714.zip (12.2 KB)

@leoluo Thanks for your reply, Could you please give me tentative release date of the version 24.8.

@manojbhide
We plan to release in the first half of August 2024. We will notify you when the next version is released.