We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

AutoFit all columns by content

Dears,
Is there any property to set or method to run in order to fit all columns by once? I didn't find it so I'm trying to use
for(var j=0; j < this.model.sheets.length; j++)
{
for(var i=0; i < this.model.sheets[j].colCount; i++)
{
this.XLResize.fitWidth([i]);
this.XLResize.fitHeight([i]);
}
}
But this doesn't work well because it just fit the content by the first row, so if the second row has a longer data value it's show as overflowed

Attachment: Display_6ea58abd.rar

1 Reply

SD Saranya Dhayalan Syncfusion Team February 3, 2020 08:54 AM UTC

Hi Stheve 
 
Thank you for contacting Syncfusion support 
 
Query: Is there any property to set or method to run in order to fit all columns by once? 
 
We have checked your code snippet, fitWidth method is used to fit the width of columns in the Spreadsheet. We can achieve this in the button click. Please find the below code snippet. 
 
function btnClick(e) { 
            var xlObj = $("#Spreadsheet").data("ejSpreadsheet"), xlFormat = xlObj.XLFormat; 
            if (!xlObj.isImport) { 
                xlObj.setWidthToColumns([140, 128, 105, 100, 100, 110, 120, 120, 100]); 
 
            } 
            for (var j = 0; j < xlObj.model.sheets.length; j++) { 
                for (var i = 0; i < xlObj.model.sheets[j].colCount; i++) { 
                    xlObj.XLResize.fitWidth([i]); // To fit the columns 
                } 
            } 
        } 
 
For your convenience we have prepared a sample. Please find the below sample link: 
 
 
Please find the below Documentation link: 
 
Could you please check the above sample and get back to us if you need further assistance on this? 
 
Regards, 
Saranya D 


Loader.
Live Chat Icon For mobile
Up arrow icon