问题
I have generated the excel sheet using set of csv files using perl script.In that i need to set width of the column as auto-fit.What 'm suppose to do i've got The way to do this in the module called OLE i don't know how to do this you please help me?
回答1:
There is no way to set a file's column to "AutoFit" because that is not a setting of the file. Excel calculates this and sets a column width at run-time.
One option is to calculate the "AutoFit" width yourself based on your data, and then set the column width to the value that you calculate. This discussion gives some workaround code that does that.
Another option is to use Win32::OLE to set the column to AutoFit. How to do this is not documented in the module itself; you would have to search around the Microsoft OLE documentation to find the appropriate command.
Update: This site appears to show how to use AutoFit with Win32::OLE
.
回答2:
You could generate your Excel file with Excel::Writer::XLSX module, and adjust the column width with set_column method
回答3:
Have a look at the autofit.pl example here
来源:https://stackoverflow.com/questions/15681221/column-width-autofit-functionality-using-perl