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

Inconsistency in retrieving of font informations of richText #752

Open
michaelschroeder2 opened this issue Nov 29, 2022 · 2 comments
Open
Labels
enhancement New feature or request

Comments

@michaelschroeder2
Copy link

michaelschroeder2 commented Nov 29, 2022

Issue: The first richText entry of a cell does not contain information regarding the font if its the same as the cell.
All other richText entries of the cell contain these informations, even if they are the same as the cell. Note, the font is not null, its just an object with only default values such as empty string, 0, false, ...

Note: This can be bypassed with checking the cell if something is empty. Though not something major, it would be nice, if it would be consistent.

Sample File:
Markups.xlsx

Sample Code:

using OfficeOpenXml;
using System;
using System.IO;

namespace GetColors
{
	class Program
	{
		static void Main(string[] args)
		{
			ExcelPackage.LicenseContext = LicenseContext.NonCommercial;

			var fileName = "Markups.xlsx";
			if (!File.Exists(fileName))
			{
				Console.WriteLine("File does not exist.");
				Console.ReadKey();
				return;
			}

			using (var excelPackage = new ExcelPackage(new FileInfo(fileName)))
			{
				for (int row = 1; row <= excelPackage.Workbook.Worksheets[0].Dimension.End.Row; row++)
				{
					if (excelPackage.Workbook.Worksheets[0].Cells[row, 1].Text == "") continue;

					var cell = excelPackage.Workbook.Worksheets[0].Cells[row, 3];

					Console.WriteLine($"\n--> {excelPackage.Workbook.Worksheets[0].Cells[row, 1].Text}");
					Console.Write($"Cell Font: [{cell.Style.Font.Name}], Size: [{cell.Style.Font.Size}]");
					if (cell.Style.Font.Bold) Console.Write(", Bold");
					Console.WriteLine();

					foreach (var richText in cell.RichText)
					{
						Console.Write($"RichText {richText.Text} Font: [{richText.FontName}], Size: [{richText.Size}]");
						if (richText.Bold) Console.Write(", Bold");
						Console.WriteLine();
					}
				}

				Console.ReadKey();
			}
		}
	}
}

Result:
image

@JanKallman
Copy link
Contributor

Thanks, we'll have a look at this.

@JanKallman
Copy link
Contributor

Yes, EPPlus will return the font specified in the rich text xml. If blank the cells style could be returned instead.
Changing this will be a behavior change, so I will add this as an enhancement for a future major.

@JanKallman JanKallman added the enhancement New feature or request label Dec 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants