Using LibXL to create an Excel file, is it possible to AutoFit the column Widths?
Using LibXL to create an Excel file, is it possible to AutoFit the column Widths?
Alspaugh,
Reading the documentation I would think it is xlFormatShrinkToSize that should be used.
Regards,
Data Access Worldwide
Vincent Oorsprong
I found the procedure AutofitColumnWidth but it doesn't seem to work.
Alspaugh,
According to a post at stackoverflow the Excel file format does not have an AutoFit option so it can't be done automatically
The AutoFitColumnWidth method calls the LibXL xlSheetSetCol function and as documented passes -1 which means "Value -1 is used for autofit column widths". Did you call this before or after filling the sheet with data? Not sure what is expected by LibXL.
Regards,
Data Access Worldwide
Vincent Oorsprong
Using the terms from the libXL demo program that comes with LibXl in order for me to use xlSheetSetCol I have to use the Low Level function and procedures. I had built my program around the higher level function. I just tried using the low level function like in example DemoGenerateReceipt_LL_BP and it works. So I am re-writing my program to use the low level functions.
Thanks for your help
Correction it didn't work. I forgot to remove some kludgy code before I updated using xlSheetSetCol. After removing the kludge xlSheetSetCol didn't work. If you can show me how to make it work in any of the Demo files that come with LibXL that would be great.
I came across this problem some time ago and was never able to resolve it successfully
Fundamentally Excel does not expose a way to do this accurately and various internet formulas are close but no cigar
Initially it seems like such a simple thing but unless Excel gives you a way to call it's engine to get an answer you can't do it because there are so many different factors including angled text/mixed fonts etc in a cell that would dictate how autofit wide it should be
When importing via an ODF format file Excel does not honour the BestFit attribute
Success consists of going from failure to failure without loss of enthusiasm - Winston Churchill
Thanks for the reply. It is a big help knowing it is not possible. I can stop trying What I ended up doing is using the piColumnWidth and checking the number of characters in the data for the column. If it is bigger then the previous length then I update the column size. Kludgy but works.