Hi,
I want to remove a chart's data format at slide .Template.pptx slide index 3. ( Sample pptx file: https://docs.google.com/presentation/d/ ... ue&sd=true )
Data Behind Chart
It should look like:
Data
Slide
IChart chart = presentation.Slides[0].Shapes[0] as IChart;
chart.Series[0].DataLabels.LabelValueVisible = true;
chart.Series[0].DataLabels.PercentValueVisible = false;
chart.Series[0].DataLabels.NumberFormat = "#,##0.00";
chart.Series[0].DataLabels.HasDataSource = false;
//Load a PowerPoint document
Presentation ppt = new Presentation();
ppt.LoadFromFile("template.pptx");
//Get the third slide
ISlide slide = ppt.Slides[2];
//loop through shapes
foreach (IShape shape in slide.Shapes)
{
//if the shape is chart
if (shape is IChart)
{
IChart chart = shape as IChart;
if (chart.Type.Equals(ChartType.BarClustered))
{
for (int i = 0; i < 5; i++)
{
//change numberformat of chart datasource
chart.ChartData[i, 1].NumberFormat = "#,##0.00";
//change numberformat of chart datalabel
chart.Series[0].DataLabels.LabelValueVisible = true;
chart.Series[0].DataLabels.PercentValueVisible = false;
chart.Series[0].DataLabels.NumberFormat = "#,##0.00";
chart.Series[0].DataLabels.HasDataSource = false;
}
}
}
}
ppt.SaveToFile("result.pptx", FileFormat.Pptx2013);
chart.ChartData[i, 1].NumberFormat = "#,##0.00";
chart.ChartData[i, 1].NumberFormat = "G/ General";
chart.ChartData[i, 1].NumberFormat = "G/ General";
using Spire.Presentation;
using System.Linq;
using Spire.Presentation.Charts;
using System;
namespace PptxTesterPaidVersion
{
class Program
{
static void Main(string[] args)
{
TestChartDataLabels();
}
private static void TestChartDataLabels()
{
//Load template presentation
Presentation templatePresentation = new Presentation();
templatePresentation.LoadFromFile("template-chart-data-label.pptx");
//Create New Presentation
Spire.Presentation.Presentation presentation = new Spire.Presentation.Presentation();
presentation.Slides.RemoveAt(0);
//Get slide from template presentation. index:1
ISlide cloneSlide = templatePresentation.Slides.ToArray().ElementAtOrDefault(0);
//---
//Get Chart
IChart chart = cloneSlide.Shapes.ToArray().FirstOrDefault(x => x.Name == "Chart 20") as IChart;
if (chart.Type.Equals(ChartType.BarClustered))
{
for (int i = 0; i < 5; i++)
{
//change numberformat of chart datasource
chart.ChartData[i, 1].NumberFormat = "G/ General";
//change numberformat of chart datalabel
chart.Series[0].DataLabels.LabelValueVisible = true;
chart.Series[0].DataLabels.PercentValueVisible = false;
chart.Series[0].DataLabels.NumberFormat = "G/ General";
chart.Series[0].DataLabels.HasDataSource = false;
}
}
int seriesCount = 1;
int categoryCount = 2;
chart.ChartData.Clear(0, 0, categoryCount + 1, seriesCount + 1);
chart.ChartData[0, 1].Text = "Total";
chart.ChartData[1, 0].Text = "Cat A";
chart.ChartData[2, 0].Text = "Cat B";
chart.ChartData[3, 0].Text = "Cat C";
chart.ChartData[4, 0].Text = "Cat D";
chart.ChartData[5, 0].Text = "Cat E";
chart.ChartData[1, 1].NumberValue = 43.15;
chart.ChartData[2, 1].NumberValue = 44.13;
chart.ChartData[3, 1].NumberValue = 44.22;
chart.ChartData[4, 1].NumberValue = 47.14;
chart.ChartData[5, 1].NumberValue = 32.36;
presentation.Slides.Append(cloneSlide);
//Save and launch to view the PPTX document.
presentation.SaveToFile("TestChartDataLabels_03.pptx", Spire.Presentation.FileFormat.Pptx2013);
}
public static string GetColumnName(int index)
{
const string letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var value = "";
if (index >= letters.Length)
value += letters[index / letters.Length - 1];
value += letters[index % letters.Length];
return value;
}
}
}
var numberFormat = chart.ChartData[j,1].NumberFormat;