Style.Copy() breaks ability to access Style with a string


#1

Either Style.Copy() has a bug or I don’t understand how to use it. I suspect the former is true. When Style.Copy() is used the ability to access the style in the styles collection by string does not work. The array resulting from the following code illustrates the suspected bug:

//Set up Aspose.Excel object
LoadAsposeLicense();
Excel oExcel = new Excel();

//Add the first style
Styles oStyles = oExcel.Styles;
int iStyleIndex = oStyles.Add();
Aspose.Excel.Style oStyle = oStyles[iStyleIndex];
//Give the style a name
oStyle.Name = “MyStyle”;

//Add the second Style and give it a name
iStyleIndex = oStyles.Add();
oStyle = oStyles[iStyleIndex];
//Copy the style
oStyle.Copy( oStyles[0] );
//Give the style a name
oStyle.Name = “MyStyle2”;
oStyle.Font.Name = “Verdana”;

//Add the third Style and give it a name
iStyleIndex = oStyles.Add();
oStyle = oStyles[iStyleIndex];
//Copy the style
oStyle.Copy( oStyles[0] );
//Give the style a name
oStyle.Name = “MyStyle3”;
oStyle.Font.Name = “Times New Roman”;

//Accessing style by string name fails
string[,] sName = new string[oStyles.Count * 2, 2];
sName[0,0] = oStyles[“MyStyle”].Name;
sName[0,1] = oStyles[“MyStyle”].Font.Name;
sName[1,0] = oStyles[“MyStyle2”].Name;
sName[1,1] = oStyles[“MyStyle2”].Font.Name;
sName[2,0] = oStyles[“MyStyle3”].Name;
sName[2,1] = oStyles[“MyStyle3”].Font.Name;

//Accessing style by int works as expected
sName[3,0] = oStyles[0].Name;
sName[3,1] = oStyles[0].Font.Name;
sName[4,0] = oStyles[1].Name;
sName[4,1] = oStyles[1].Font.Name;
sName[5,0] = oStyles[2].Name;
sName[5,1] = oStyles[2].Font.Name;


#2

By the way, I am using version 3.0


#3

Hi Philip,

Please try v3.0.2 at http://www.aspose.com/Products/Aspose.Excel/Downloads.html.


#4

Style.Copy() now works as expected. I didn’t see this fix mentioned in the release notes. Thank you for correcting the issue.