Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using ClosedXML, mixed font style in cell is lost #1330

Open
2 of 3 tasks
tarockx opened this issue Jan 3, 2020 · 6 comments
Open
2 of 3 tasks

Using ClosedXML, mixed font style in cell is lost #1330

tarockx opened this issue Jan 3, 2020 · 6 comments

Comments

@tarockx
Copy link

tarockx commented Jan 3, 2020

Do you want to request a feature or report a bug?

  • Bug
  • Feature

Version of ClosedXML
Tested both 0.94.2 and 0.95.0-beta2

What is the current behavior?

I have an XLSX file (attached as test.xlsx) that has a cell with mixed font inside it (cell A1). As you can see, the cell has some words in different font styles/colors:
image

If I open and save this file using ClosedXML (even without doing anything else), the mixed formatting is lost:
image

As you can see, weirdly, the entire cell seems to acquire the style of the first piece of text (bold font in this case)

What is the expected behavior or new feature?

Cell styles should not be modified (especially since I didn't even do any modifications to the document, just opened and closed it)

Reproducibility

I just opened and then saved the document with ClosedXML, like this:

static void Main(string[] args)
        {
            using (var ms = new MemoryStream(File.ReadAllBytes("test.xlsx")))
            {
                using (var workbook = new XLWorkbook(ms))
                {
                    workbook.SaveAs("test_out.xlsx");
                }

            }
        }

Further info

By having a look manually at the files inside the XLSX archive before and after saving it with ClosedXML, it seems it is "merging" various <r> elements, each one with its own style, into a single element without the style, as shown here:

image

@igitur
Copy link
Member

igitur commented Jan 6, 2020

Hi,

Your input file contains an interesting case: inline mixed-style content. How was this generated in the first place? I've never seen it. Unfortunately ClosedXML doesn't support this yet, but we can add it. At the moment normal and mixed-styles are supported for shared strings and only normal (non-mixed) inline strings are supported.

We'll add it to our to-do list.

Thanks for filling out the issue template well.

@tarockx
Copy link
Author

tarockx commented Jan 6, 2020

Hi, and thanks for your reply.
The file was generated by Microsoft's Reporting Services engine, its basically what you get when you generate a report in Excel format from either Microsoft sequel server reporting services (SSRS) or the Microsoft's Report Viewer C# library.

@igitur
Copy link
Member

igitur commented Jan 6, 2020

So I'm guessing that you don't really care whether the strings are stored in the shared string part or whether they're inline, right? If you don't care, the easy solution is that ClosedXML just always saves rich text content as shared strings. @Pankraty ?

@tarockx
Copy link
Author

tarockx commented Jan 6, 2020

Yeah, honestly I don't really care how the document is formatted internally as long as it works 😅️ and thanks again for your quick responses and support, you guys are awesome

@Pankraty
Copy link
Member

Pankraty commented Jan 6, 2020

@igitur I don't see reasons against.

@InvincibleDRT
Copy link

@Pankraty @igitur @tarockx Is this issue resolved? I am having a similar issue. I am rather trying to create an excel file with mixed formatting in a cell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants