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

Free Support Forum - aspose.com

Cell.SetStyle(Style style- bool explicitFlag) doesn't work as expected

The following code correctly sets the “Wrap” property to true but the VerticalAlignment of the cell (when the saved spreadsheet has been opened) is “Center” rather than “Top”:


Aspose.Cells.Style cellStyle = new Aspose.Cells.Style();
cellStyle.IsTextWrapped = true;
cellStyle.VerticalAlignment = TextAlignmentType.Top;

for (int i = 0; i < itemsSheet.Cells.Count; i++)
{
itemsSheet.Cells[i].SetStyle(cellStyle, true);
}

However, changing it to the following, it works as expected:

Aspose.Cells.Style cellStyle = new Aspose.Cells.Style();
cellStyle.IsTextWrapped = true;
cellStyle.VerticalAlignment = TextAlignmentType.Top;

StyleFlag styleFlag = new StyleFlag();
styleFlag.VerticalAlignment = true;
styleFlag.WrapText = true;

for (int i = 0; i < itemsSheet.Cells.Count; i++)
{
itemsSheet.Cells[i].SetStyle(cellStyle, styleFlag);
}

Have I misunderstood the new overloaded SetStyle method or is this a bug?

Thanks.

Hi,


I think you may simply use first overloaded version of the method:
itemsSheet.Cells[i].SetStyle(cellStyle);

instead of:
itemsSheet.Cells[i].SetStyle(cellStyle, true);

it works fine for your requirement.

Thank you.
Amjad Sahi:
Hi,

I think you may simply use first overloaded version of the method:
itemsSheet.Cells[i].SetStyle(cellStyle);

instead of:
itemsSheet.Cells[i].SetStyle(cellStyle, true);

it works fine for your requirement.

Thank you.

But wouldn't that potentially overwrite other styles that are already set? Also, this still doesn't explain why my first approach doesn't work as expected. Is it a bug?

Thanks.

Hi,


Yes, I think the two code segments shared by you in your first post should work the same but the first code segment does not perform correctly regarding alignment settings. I have logged an issue with an id: CELLSNET-30651. We will look into the issue soon.

For the time being, you may continue using my suggested approach your yours second approach.


Thank you.

Hi,

We have fixed this issue. Please download: Aspose.Cells for .NET v7.0.2.1


Thanks,

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


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

Seems like the overload version does not work for the latest version of the Aspose.Cells DLL 7.3.2.0

wsheet.Cells[0, 0].SetStyle(Style.Font.IsBold, true);

This line of code gives an error, eventhoug I am using the latest version of Aspose.Cells.

Hi,

Thanks for your posting and using Aspose.Cells for .NET.

Please download and try the latest version:
Aspose.Cells
for .NET v7.3.2.3


Please see the following code that illustrates how to use the Cell.SetStyle(Style style, bool explicitFlag) method for your needs.

I have also attached the source and output xlsx files generated by the code and screenshot for your reference.

C#


string filePath = @“F:\Shak-Data-RW\Downloads\source.xlsx”;


Workbook workbook = new Workbook(filePath);


Worksheet worksheet = workbook.Worksheets[0];


Cell cell = worksheet.Cells[“A1”];


Style style = workbook.CreateStyle();

style.Font.IsBold = true;


cell.SetStyle(style, true);


workbook.Save(filePath + “.out.xlsx”, SaveFormat.Xlsx);

Screenshot: