We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Cant modify data in charts

I am evaluating Aspose.Total and keep getting the following errors:

I keep getting the following 2 errors which prevent me from even compiling.

Error ‘object’ does not contain a definition for ‘Worksheets’ and no extension method ‘Worksheets’
and
Error Cannot implicitly convert type ‘object’ to ‘Aspose.Cells.Workbook’. An explicit conversion exists (are you missing a cast?)

I have bolded and italicised the source lines below.
I am using VS2008
Please


Here is my code


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Aspose.Slides;
using Aspose.Slides.Pptx;
using Aspose.Slides.Pptx.Animation;
using Aspose.Slides.Pptx.Charts;
using Aspose.Slides.Pptx.SlideShowTransition;
using Aspose.Slides.Effects;
using Aspose.Slides.Export;
using Aspose.Slides.Odp;
using Aspose.Slides.Util;
using Aspose.Cells;
using Aspose.Cells.Charts;
using Aspose.Cells.Drawing;
using Aspose.Cells.Markup;
using Aspose.Cells.Pivot;
using Aspose.Cells.Properties;
using Aspose.Cells.Rendering;
using Aspose.Cells.Tables;
using System.IO;



namespace TestExcel
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
// Add licensing
//Create a License object
Aspose.Slides.License license = new Aspose.Slides.License();
//Set the license of Aspose.Slides for .NET to avoid the evaluation limitations
license.SetLicense(“C:\Aspose.Total.lic”);


//Open PresentationEx class that contain the chart
PresentationEx pres = new PresentationEx(“c:\AsposeChart.ppt”);

//Access first slide
SlideEx sld = pres.Slides[0];

//Create chart object
ChartEx ch;

//Finding and accessing the exisisting chart
foreach(ShapeEx shape in sld.Shapes)
{
if(shape is ChartEx)
{
ch = (ChartEx)shape;


// Using Aspose.Cells to add new cell to the chart data
Aspose.Cells.Cell cell = ch.ChartData.Workbook.Worksheets[0].Cells[5, 1];
cell.PutValue(55.0);

// Take first chart series
ChartSeriesEx ser = ch.ChartData.GetSeries(0);

// And add new value (55.0) there.
ser.Values.Add(cell);

//If you want to change the data then create Workbook object
Workbook Wb= ch.ChartData.Workbook;


// Create cell with category name
cell = Wb.Worksheets[0].Cells[5, 0];
cell.PutValue(“Modified Category”);

// Add this category to our chart
ch.ChartData.AddCategory(cell, Wb.Worksheets[0]);

cell = Wb.Worksheets[0].Cells[0, 4];
cell.PutValue(“Modified series”);

// Change some data.
ser = ch.ChartData.AddSeries(cell, Wb.Worksheets[0]);
cell = Wb.Worksheets[0].Cells[1, 4];
cell.PutValue(78.5);
ser.Values.Add(cell);

// Modifying chart type
ch.Type = ChartTypeEx. ClusteredColumn;
}
}

// Save presentation with chart
pres.Write(“c:\AsposeChart_New.pptx”);





}

private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Close();
}
}
}

Hi Maria,

Thanks for your interest in Aspose.Slides.

Please change following two lines of code with the code lines mention in bold.

Aspose.Cells.Cell cell = ch.ChartData.Workbook.Worksheets[0].Cells[5, 1];
Workbook Wb = ch.ChartData.Workbook;

Aspose.Cells.Cell cell = ((Aspose.Cells.Workbook)ch.ChartData.Workbook).Worksheets[0].Cells[5, 1];
Workbook Wb = (Aspose.Cells.Workbook)ch.ChartData.Workbook;

We apologize for your inconvenience.

When I make the changes you suggested I now get the error below during runtime for this line of code

Aspose.Cells.Cell cell = ((Aspose.Cells.Workbook)ch.ChartData.Workbook).Worksheets[0].Cells[5, 1];



Error:
System.NullReferenceException was unhandled
Message=“Object reference not set to an instance of an object.
Source=“Aspose.Slides”
StackTrace:
at Aspose.Slides.Pptx.Charts.ChartDataEx.( )
at Aspose.Slides.Pptx.ChartEx.(Boolean )
at Aspose.Slides.Pptx.ChartEx.get_ChartData()
at KantarPowerPoint.Form1.button14_Click(Object sender, EventArgs e) in C:\Documents and Settings\hookst00\My Documents\Visual Studio 2008\Projects\KantarPowerPoint\KantarPowerPoint\Form1.cs:line 1164
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at KantarPowerPoint.Program.Main() in C:\Documents and Settings\hookst00\My Documents\Visual Studio 2008\Projects\KantarPowerPoint\KantarPowerPoint\Program.cs:line 18
InnerException:



Hi Maria,

Please use the latest version of Aspose.Cells for .NET 6.0.0 and Aspose.Slides for .NET 5.2.0 in your application. Please share your presentation file for investigation purpose.

Thanks.

I have a problem editing the data too, but from PowerPoint.

EDIT:
This post was moved here:
http://www.aspose.com/community/forums/473733/can-t-edit-the-chart-data-in-powerpoint/showthread.aspx#473733


Hi Kostas,


Can you please share that which version of Aspose.Slides and Aspose.Cells you have used for your investigation. Please share the sample application along with source presentation with us and I will investigate it further on my end. Please also share the PowerPoint version that you have used to reproduce the issue. Please also share that which slide has the Ole frame that you are having issue with so that I may verify that on my end.

Many Thanks,