Bold style overwrites strikeout font style

Hi,
I want to add bold font style to an existing striked out text part, but the IsBold flag resets the IsStrikeout flag of the cell font.
It seems to me that it is an bug, isn’t it?

If I turn around the calls, so that the bold flag is set first and the strikeout flag is set at last, it works fine, but I have to keep the existing format style.

I have written a little console application that explains the failure:

C#

using Aspose.Cells;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var workbook = new Workbook();
            var worksheet = workbook.Worksheets[0];
            worksheet.Name = "Test";
            worksheet.Cells["A1"].Value = "Test combined font style bold and strikeout";

            // First testcase: first call sets the IsBold property, second call sets the IsStrikeout property
            // this is what i have expected.
            var cell = worksheet.Cells["A2"];
            var text = "Bold StrikethroughBold Bold";
            cell.Value = text;
            cell.Characters(0, text.Length).Font.IsBold = true;
            cell.Characters(5, "StrikethroughBold".Length).Font.IsStrikeout = true;

            // Second testcase: just turn around the call sequence of IsStrikeout and IsBold
            var cell2 = worksheet.Cells["A3"];
            var text2 = "Bold StrikethroughBold Bold failed";
            cell2.Value = text2;
            cell2.Characters(5, "StrikethroughBold".Length).Font.IsStrikeout = true;
            cell2.Characters(0, text2.Length).Font.IsBold = true;

            workbook.Save("Test Bold Bug.xlsx", SaveFormat.Xlsx);
        }
    }
}

Thank you for your help
Michael

@M_Heres

Thanks for using Aspose APIs.

Please keep the longer one first and shorter one after that and it will work fine. Please see the following sample code, its output Excel file and screenshot.

Bold after Strikeout and Strikeout after Bold both are working fine.

Download Link:
Output Excel File.zip (6.3 KB)

C#

Workbook wb = new Workbook();

Worksheet ws = wb.Worksheets[0];

Cell c = ws.Cells["B5"];
c.PutValue("BBBB123456789");
        
c.Characters(0, 8).Font.IsBold = true;
c.Characters(0, 4).Font.IsStrikeout = true;

//--------------------------------------
//--------------------------------------

c = ws.Cells["B9"];
c.PutValue("BBBB123456789");

c.Characters(0, 8).Font.IsStrikeout = true;
c.Characters(0, 4).Font.IsBold = true;

//Save the workbook
wb.Save("output.xlsx");

Screenshot:

Hello again,
Thanks for your quick answer.
My problem is, that I have to keep the previous format without knowing if there is already another (shorter) formatted text in a cell, if I only want format a part of the text in bold style additionally.

To change the order is no solution for me, if i work on an existing text with formats.
So I have to analyse every single character of a cell to find out, which formats are set on it in order to find the longest sequence to begin with formatting?

In Excel you can also activate an deacivate the strikeout property for a shorter text part without loosing the bold format of a greater text sequence.

Greetings
Michael

@M_Heres

Thanks for your posting and using Aspose APIs.

This feature needs to be fixed or improved. We have logged it in our database for investigation and for a fix. Once, there is some news for you, we will let you know asap.

This issue has been logged as

  • CELLSNET-45842 - FontSettings are overwriting each other while MS Excel keeps both of them

@M_Heres

Thanks for using Aspose APIs.

This is to inform you that we have fixed your issue CELLSNET-45842 now. We will soon provide the fix after performing QA and including other enhancements and fixes.

@M_Heres

Thanks for using Aspose APIs.

Please download and try the following and let us know your feedback.

The issues you have found earlier (filed as CELLSNET-45842) have been fixed in this Aspose.Cells for .NET 18.1 update.

Please also check the following article: