EPPlus
EPPlus copied to clipboard
Set a fixed column width by using length units in order to print and fill the entire fill area
I would like to know how to set up using length units as column width setting units, as I need to ensure perfect filling for printing. The character length does not guarantee that I can fix it in any case.
Reference Code
// Prevent effect coverage.
for (var i = 0; i < leafNodes.Count; i++)
{
worksheet.Column(i + 1).SetAlignment(leafNodes[i].ContentAlign);
// Number of characters
if (leafNodes[i].Width != null)
worksheet.Column(i + 1).Width = leafNodes[i].Width.Value;
}
Print Preview

TextRenderer.MeasureText and this.CreateGraphics().MeasureString can't solve this. It is probably limited to winform, the value difference is very large and has no reference value.
The problem itself could probably be solved using other means, such as duplicate rows. But I would like to support column width settings for inch values.
To set the width of a column in inches you have to calculate it using the formula described in Microsofts documentation for the Open Office XML standard (https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.column?view=openxml-2.8.1, see the width property). There is no functionality in EPPlus to translate other units into this. As you can see the width value is calculated using the width of digits in the default font width some added padding. We might implement some support for this in the future, but cannot say when at this point.
Thanks, I'll look into it.
Closed due to inactivity.