Workbook.CreateStyle() Issue

Hello,


We are having an issue with the method CreateStyle from the class Workbook. It seems that when we create a new style, and set it to bold, the whole workbook will have the text bold.

Sample code:

private static void Main()
{

var excelDocument = new Workbook(“TestFiles\Test Aspose.xlsx”);

GetCellsBoldStyle(excelDocument);

Console.WriteLine(excelDocument.Worksheets[1].Cells[“A3”].GetStyle().Font.IsBold);

excelDocument.Save(“c:\result.xlsx”);

Console.ReadLine();
}


private static Style GetCellsBoldStyle(Workbook workbook)
{
Style boldStyle;

if (workbook.GetNamedStyle(StyleBold) == null)
{
var newStyleName = workbook.CreateStyle().Name;
boldStyle = workbook.GetNamedStyle(newStyleName);
boldStyle.Name = StyleBold;
boldStyle.Font.IsBold = true;
}
else
{
boldStyle = workbook.GetNamedStyle(StyleBold);
}

return boldStyle;
}

The workbook is attached.

Best regards,
Andrei Moisei
IBM Romania

Hi Andrei,

Thanks for your posting and using Aspose.Cells.

We were able to reproduce this issue using the latest version: Aspose.Cells
for .NET v8.3.2.3
after running your sample code. When create a new style and set it to bold, the whole workbook will have the text bold.

We have logged this issue in our database for investigation. We will look into it and fix this issue. Once, the issue is resolved or we have some other update for you, we will let you know asap.

This issue has been logged as

  • CELLSNET-43408 - When create a new style and set it to bold, the whole workbook will have the text bold

I have attached the output Excel file generated by your code for a reference.

Hi,

Well, if you create a style with workbook.CreateStyle(), the name of the style should be null. Could you explain why you want to get the named style by the empty name?
e.g.
Sample code:

if (workbook.GetNamedStyle(StyleBold) == null)
{

var newStyleName = workbook.CreateStyle().Name;

boldStyle = workbook.GetNamedStyle(newStyleName);

boldStyle.Name = StyleBold;

boldStyle.Font.IsBold = true;

}

And we will return null in the next fix if the name is null when calling workbook.GetNamedStyle method.

Thank you.

Hi Amjad,

Actually we missed something in our demo code, StyleBold is a string constant:

private const string StyleBold = “CRMBoldStyle”;

Basically we want to check if there is a style named “CRMBoldStyle”, if it’s not defined we create it. This is how GetCellsBoldStyle method looked like before Workbook.Styles becoming obsolete:

private static Style GetCellsBoldStyle(Workbook workbook)
{
Style boldStyle;

if (workbook.Styles.Count == 0 || workbook.Styles[StyleBold] == null)
{
int styleIndex = workbook.Styles.Add();
boldStyle = workbook.Styles[styleIndex];
boldStyle.Name = StyleBold;
boldStyle.Font.IsBold = true;
}
else
{
boldStyle = workbook.Styles[StyleBold];
}

return boldStyle;
}


Best regards,
Aurelian Iordache
Software Developer
IBM Romania

Hi,


Thanks for providing us further details.

I have logged your concerns and details against your issue “CELLSNET-43408” into our database. Also, we have fixed your original issue now. We will further evaluate your requirements too and may provide the fix within the next 2-3 days or so.

Once we have any update on it, we will let you know here.


Thank you.

Hi,

Thanks for your using Aspose.Cells.

Please download and try the latest fix: Aspose.Cells for .NET v8.3.2.4 and let us know your feedback.

If the name is null, Workbook.GetNamedStyle() method will return null.

The issues you have found earlier (filed as CELLSNET-43408) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.