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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

AutoFit all columns by content

Thread ID:





151169 Feb 2,2020 09:46 PM UTC Feb 3,2020 08:54 AM UTC JavaScript - EJ 2 1
Tags: Spreadsheet
Asked On February 2, 2020 09:46 PM UTC

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++)
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

Saranya Dhayalan [Syncfusion]
Replied On 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? 
Saranya D 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon