salvois / LargeXlsx

A .net library to write large Excel files in XLSX format with low memory consumption using streamed write.
Other
204 stars 34 forks source link

Anyway to autosize columns? #55

Open ronnyek opened 1 week ago

ronnyek commented 1 week ago

I generate xlsx files, and all works well, but by default columns are minimal width, and I don't have anyway to know what is ideal length.

I'm wondering if there is anyway I can automatically size them based on the text content within?

vitaliy-nerdysoft commented 1 day ago

@ronnyek, That`s the only reason I need a library for Excel native file generation. Please let me know if you found a solution for that?

dgosbell commented 13 hours ago

In this library you need to specify the column widths when creating the worksheet see https://github.com/salvois/LargeXlsx?tab=readme-ov-file#column-formatting so to set the size based on the content you would need to loop through your data and calculate the string width based off the formatting using a technique like one of the ones suggested here https://stackoverflow.com/questions/263614/calculate-the-display-width-of-a-string-in-c to find the maximum size. There is no magic autosize setting.