EPPlus icon indicating copy to clipboard operation
EPPlus copied to clipboard

Set a fixed column width by using length units in order to print and fill the entire fill area

Open kelilive opened this issue 3 years ago • 4 comments
trafficstars

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 Print Preview

kelilive avatar Apr 29 '22 01:04 kelilive

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.

ghost avatar Apr 29 '22 02:04 ghost

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.

ghost avatar May 10 '22 01:05 ghost

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.

swmal avatar May 17 '22 14:05 swmal

Thanks, I'll look into it.

ghost avatar May 18 '22 01:05 ghost

Closed due to inactivity.

OssianEPPlus avatar Feb 08 '24 10:02 OssianEPPlus