Hi Team,
I am using Aspose Slides for .NET version 22.11.0. I am trying to read cell value & formatting details from excel source file and setting those values for dynamic Chart in pptx file.
When we try to export the result in ppt it’s working fine but with the html result custom formatting is not working.
Note: Please have a look on attached zip file which contains
- Error.png
- PPTResult.pptx
- HTMLResult.html
- ReportTemplate.pptx
OS Version: Windows 10 Enterprise 64-bit
.NET Framework version: 4.8
Sample Code
public void GetHtmlResult()
{
try
{
string path = @"C:\Users\admin\ReportTemplate.pptx";
byte[] byteFile = System.IO.File.ReadAllBytes(path);
MemoryStream reportTemplateStream = new MemoryStream(byteFile);
using (Presentation presentation = new Presentation(reportTemplateStream))
{
ISlide slide = presentation.Slides[0];
IChart currentChart = slide.Shapes[0] as IChart;
IChartDataWorkbook chartWorkbook = currentChart.ChartData.ChartDataWorkbook;
if (slide.Shapes[0].AlternativeText.Split('\n')[0].Contains("SOURCE"))
{
//This method is used to read data from source file and copy it into chartworkbook
//CopySourceDataToChartWorkBook(chartWorkbook);
foreach (ChartSeries ser in currentChart.ChartData.Series)
{
ser.Labels.DefaultDataLabelFormat.IsNumberFormatLinkedToSource = true;
foreach (IDataLabel dataLabel in ser.Labels)
{
dataLabel.DataLabelFormat.IsNumberFormatLinkedToSource = true;
}
string valueNumberFormat = string.Empty;
string xValueNumberFormat = string.Empty;
string yValueNumberFormat = string.Empty;
foreach (IChartDataPoint dp in ser.DataPoints)
{
dp.Label.DataLabelFormat.IsNumberFormatLinkedToSource = true;
if (dp != null)
{
if (dp.Value != null && dp.Value.AsCell != null)
{
valueNumberFormat = dp.Value.AsCell.CustomNumberFormat;
}
if (dp.XValue != null && dp.XValue.AsCell != null)
{
xValueNumberFormat = dp.XValue.AsCell.CustomNumberFormat;
}
if (dp.YValue != null && dp.YValue.AsCell != null)
{
yValueNumberFormat = dp.YValue.AsCell.CustomNumberFormat;
}
}
}
if (!string.IsNullOrEmpty(valueNumberFormat))
{
ser.NumberFormatOfValues = valueNumberFormat;
}
if (!string.IsNullOrEmpty(xValueNumberFormat))
{
ser.NumberFormatOfXValues = xValueNumberFormat;
}
if (!string.IsNullOrEmpty(yValueNumberFormat))
{
ser.NumberFormatOfYValues = yValueNumberFormat;
}
}
//Similarly we are setting the Horizontal Axis Number Format
//string format = ""; //Get Format from the Excel source file
//IAxis axis = currentChart.Axes.HorizontalAxis;
//axis.NumberFormat = format;
//axis.IsNumberFormatLinkedToSource = false;
}
ResponsiveHtmlController controller = new ResponsiveHtmlController();
HtmlOptions htmlOptions = new HtmlOptions
{
HtmlFormatter = HtmlFormatter.CreateCustomFormatter(controller)
};
presentation.Save(@"C:\Users\rkumarpa\source\repos\ErrorBulletChart\ErrorBulletChart\Docs\Output.html", SaveFormat.Html, htmlOptions);
}
}
catch (Exception ex)
{
}
}
Attachment.zip (293.0 KB)