table.AddRows fails

Hi,

I tried to create a simple table and after that add some rows.
If the table has only one row, table.AddRow() fails.

// doesn work
Table table = slide.Shapes.AddTable(400, 400, 5000, 3000, 2, 1);
table.GetCell(0, 0).TextFrame.Paragraphs[0].Portions[0].Text = “SampleText”;
table.AddRow();

// works fine
// AddRow() works if I create a table with 2 rows.
Table table = slide.Shapes.AddTable(400, 400, 5000, 3000, 2, 2);
table.GetCell(0, 0).TextFrame.Paragraphs[0].Portions[0].Text = “SampleText”;
table.AddRow();

Anybody an idea whats wrong?

Thanks,

Carsten

I receive the following exception:

Unable to construct record instance
Index was outside the bounds of the array.

“System.Exception: Error reading bytes —> System.Exception: Unable to construct record instance —> System.IndexOutOfRangeException: Index was outside the bounds of the array.\r\n at xed09de6bc728e32e.xdad01059cad7d884.x043aafba68f5c559(Byte[] x4a3f0a05c02f235f, Int32 x374ea4fe62468d0f, Int32 x0ceec69a97f73617)\r\n at xed09de6bc728e32e.xdad01059cad7d884.GetInt(Byte[] data, Int32 offset)\r\n at xc790564b1178bc76.x0bd29a0cad2dc0b5.FillFields(Byte[] data, Int32 size)\r\n at xc790564b1178bc76.x0bd29a0cad2dc0b5…ctor(Object root, Int16 id, Int32 size, Byte[] data, x5e38cc5265877626 stf)\r\n at xc790564b1178bc76.x0dbf0843d765d329.xe6b192050061ba71(Object xc301afa072787492, Int16 x6ed4ed9ed59eb694, Int16 xed5ae97b5b9a9be9, Int32 x0ceec69a97f73617, Byte[] x4a3f0a05c02f235f, x5e38cc5265877626 x058c1f0dc3767903)\r\n — End of inner exception stack trace —\r\n at xc790564b1178bc76.x0dbf0843d765d329.xe6b192050061ba71(Object xc301afa072787492, Int16 x6ed4ed9ed59eb694, Int16 xed5ae97b5b9a9be9, Int32 x0ceec69a97f73617, Byte[] x4a3f0a05c02f235f, x5e38cc5265877626 x058c1f0dc3767903)\r\n at xc790564b1178bc76.xfa1cc77c6e99afb5.x6fe0dc13a93aac68(Object xc301afa072787492, Stream x1d684aa0d87e815e)\r\n — End of inner exception stack trace —\r\n at xc790564b1178bc76.xfa1cc77c6e99afb5.x6fe0dc13a93aac68(Object xc301afa072787492, Stream x1d684aa0d87e815e)\r\n at xc790564b1178bc76.xfa1cc77c6e99afb5.FillFields(Byte[] data, Int32 size)\r\n at xc790564b1178bc76.xe3e99d3417159bec…ctor(Object root, Int16 id, Int32 size, Byte[] data)\r\n at xc790564b1178bc76.x00de6ac49b76bf35…ctor(Object root, Int16 id, Int32 size, Byte[] data)\r\n at xc790564b1178bc76.xfa1cc77c6e99afb5…ctor(Object root, Int16 id, Int32 size, Byte[] data)\r\n at xbabfecbc0b52b350.x60a83a1c77a6b0d0.DoRead(BinaryReader reader)\r\n at xbabfecbc0b52b350.xddf6304144fd3863.x06b0e25aa6ad68a9(xebb8e4f90b5c1d33 x6b0ad9f73c48ad53, BinaryReader xe134235b3526fa75)\r\n at xbabfecbc0b52b350.xeb990b4cb5dd2e44.x2785b0923dba0723(Object xc301afa072787492, BinaryReader xe134235b3526fa75)\r\n at xbabfecbc0b52b350.x0adf58e975454349.x06b0e25aa6ad68a9(Object xc301afa072787492, BinaryReader xe134235b3526fa75, Int32 x961016a387451f05)\r\n at xbabfecbc0b52b350.x21ad3b7fe343bc74.DoRead(BinaryReader reader)\r\n at xbabfecbc0b52b350.xddf6304144fd3863.x06b0e25aa6ad68a9(xebb8e4f90b5c1d33 x6b0ad9f73c48ad53, BinaryReader xe134235b3526fa75)\r\n at xbabfecbc0b52b350.xddf6304144fd3863.x06b0e25aa6ad68a9(Object xc301afa072787492, BinaryReader xe134235b3526fa75)\r\n at Aspose.PowerPoint.Table.AddRow()\r\n at TestApplication.TestApplication…ctor() in d:\apps\aspose.powerpoint\demos\c#\testapplication\testapplication.cs:line 65\r\n at TestApplication.TestApplication.Main(String[] args) in d:\apps\aspose.powerpoint\demos\c#\testapplication\testapplication.cs:line 23” string

You code is ok. It’s a problem with filling internal cache.
I will publish hot fix tomorrow.

Thanks Alexey for answer,

Another question (or possibly bug???) about tables.

I create a new table with 4 columns and 2 rows and try to set the columnWidth.
But it works only for the number of rows, in that example i can set the ColumnWith for the first two columns.


Table table = slide.Shapes.AddTable(300, 300, 2000, 1000, 4, 2);
for (int i=0; i<4; i++)
{
table.SetColumnWidth(i, 300);
}

Following exception occurs:
Wrong column index
System.Object {System.IndexOutOfRangeException} System.Object


And a question about AlternativeText:

slide.Shapes[0].AlternativeText

the property is read-only. Is there any chance to change the text?



Thanks,

Carsten

Dear Carsten,

I couldn’t reproduce your problem with last version. Please check 1.9.3 hot fix.

If you really need r/w access to AlternativeText we can implement it.

Thanks,

version 1.9.3 fixed the problem with setting column width Smile.

It would be helpful if you can implement r/w to AlternativeText, but only if the effort is not too high.

Carsten

Dear Carsten,

It’s not too difficult to implement r/w for AlternativeText but
could you tell me what you think about Tags at first?

You can read and write any number of custom text properties to each shape and slide.
These properties can be easily accessed from Aspose.PowerPoint and from MS PowerPoint.

Dear alcrus,

I am not sure what tags are. Can you give an example? I can create tags with Aspose for each shape, but I am not able to find them in Powerpoint.
When I search for “tag” in help of Powerpoint, i get only AlternativeText or SmartTags (is an Aspose-Tag a SmartTag?).
In Aspose help I found only "Represents a collection of a tags. ", but not what a tag is.

Here the way I create tags with Aspose:

slide.Shapes[textBoxIndex].Tags.Add(“TagName”, “TagValue”);


Carsten

Ah sorry, I found documentation of tags.

http://blogs.msdn.com/andrew_may/archive/2004/12/07/277696.aspx
"Tags are one of the rare pieces of the PowerPoint object model that doesn’t have a counterpart in the application’s user interface. Tags are a totally programmatic feature: you can’t get or set Tags objects except through code"

you wrote:
"These properties can be easily accessed from Aspose.PowerPoint and from MS PowerPoint."
Do I need an add-in to edit these tags in Powerpoint?


Carsten

another question about tags

adding tags to a textbox works fine.

i tried to add tags to table and i get always null reference exception

Table table = slide.Shapes.AddTable(300, 300, 500, 500, 2, 2);
table.Tags.Add("name", "value");

Dear Carsten,

Yes, this problem exists for dynamically created objects.
It will be fixed in the next hot fix.

Dear Alexey,

I have another problem with tables, again with AddRows().


if I create a new table in my code, AddRow() works

Table table = slide.Shapes.AddTable(300, 300, 500, 500, 10, 1);
table.AddRow(); // works fine


But if I use a table (with 10 columns) of a template, i receive a NullReferenceException.

Table ppTable = null;
for (int i=0; i<slide4.Shapes.Count; i++)
{
if (slide4.ShapesIdea is Table)
ppTable = (Table)slide4.ShapesIdea;
}
if (ppTable != null)
ppTable.AddRow(); // Object reference not set to an instance of an object.


And did you override Operator == for FontEntity?
i tried to check whether an instance of FontEntity is null or not
if (fontEntity == null) // throws a null reference exception
{

}

Carsten

hmm, Idea should be [ i ] Smile

Dear Carsten,

Is it a simple table or with merged cels?
Can you send me any example?

Yes, I overrided Operator== for FontEntity. Exception will be fixed.

Hi Alexey,

have a look at the presentation “test.ppt”. I can add rows to table on slide3, but not on slide2 (both are simple tables with 10 columns).

TestApplication.cs shows the way i add rows.

Carsten