Change chart


#1

Hello. I tried to do manipulate a chart with excels chartfunction and export it to powerpoint. I saw the code in this forum and tested it. Here it is:

Presentation pres = new Presentation(MapPath(".") + "\\Chart2.ppt");
OleObjectFrame shape = (OleObjectFrame) pres.Slides[0].Shapes[0];
byte[] xlsData = shape.ObjectData;

//open chart
MemoryStream stream1 = new MemoryStream(xlsData);
Excel excel = new Excel();
excel.Open(stream1);
excel.Worksheets[0].Cells["C3"].PutValue(150);

//Save excel back to the memorystream
MemoryStream stream2 = new MemoryStream();
excel.Save(stream2,FileFormatType.Default);

//Replace chart data in our presentation and save to ppt
shape.ObjectData = stream2.ToArray();
pres.Write(MapPath(".")+ "\\ppt2.ppt");

It didn´t get the expected result because the name of the bars disappered and also the name of the legends, and the cell "C3" did not get the number 150. Dose anyone see if I have done something wrong?

//The_L


#2

In my case it worked when I changed to Worksheets[1] instead of [0],
because my chart was on the first sheet and the data in the second.



But I also have a problem: although the value in the cell changes
correctly, other cells get their values changed randomly, with stuff
like “h9hEWsdf”. It seems to be random, sometimes I change the value on
C3 and I get trash on D5, and so on.



Very frustrating.



#3

If you use evaluation version of Aspose.Excel you should know it inserts random garbage text.