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

Errors with resizing

Define Spreadsheet as such

<ejs-spreadsheet id="spreadsheet3" height="750px" allowResizing="true" style="height:1000px" saveUrl="/ForecastInput/SaveToServer" allowSave="true" showRibbon="false" frozenColumns="4" allowFormulaBar="false" allowInsert="false" openUrl="/ForecastInput/Open" created="onCreated" allowOpen="true" beforeOpen="beforeOpen">


Try this line.

 var xlObj = $("#spreadsheet3").data("ejSpreadsheet"), xlFormat = xlObj.XLFormat;

                for (var j = 0; j < xlObj.sheets.length; j++) {

                    for (var i = 0; i < xlObj.sheets[j].colCount; i++) {

                        xlObj.XLResize.fitWidth([i]); // To fit the columns


Cannot read properties of undefined (reading 'XLFormat')

and this one.

var xlObj = $("#spreadsheet3").data("ejSpreadsheet"), xlFormat = xlObj.XLFormat;

            if (!xlObj.isImport) {

                xlObj.setWidthToColumns([140, 128, 105, 100, 100, 110, 120, 120, 100]);


Cannot read properties of undefined (reading 'XLFormat')

3 Replies

SP Sangeetha Priya Murugan Syncfusion Team March 10, 2023 12:34 PM UTC

Hi Stephen,

Based on your provided codes you have rendered the EJ2 spreadsheet but in the script, you have called the EJ1 methods using the EJ1 Spreadsheet instance. So, only the error may occur in your end, and we have modified the sample based on your requirement using EJ2 methods as shown below.

Code Block:


<ejs-spreadsheet id="spreadsheet3" height="750px" allowResizing="true" saveUrl="/ForecastInput/SaveToServer" allowSave="true" showRibbon="false" showFormulaBar="false" allowInsert="false" openUrl="/ForecastInput/Open" created="onCreated" allowOpen="true">


        <e-spreadsheet-sheet frozenColumns="4">








    function onCreated() {

// EJ2 Spreadsheet instance

        var spreadsheet = ej.base.getComponent(document.getElementById('spreadsheet3'), 'spreadsheet');


        spreadsheet.setColumnsWidth(100, ["A:M"]); // To set width for columns.



Please find the attached sample below.

API Links: https://ej2.syncfusion.com/javascript/documentation/api/spreadsheet#autofit



Documentation Link:


Demo Link: https://ej2.syncfusion.com/aspnetcore/Spreadsheet/DefaultFunctionalities#/fluent

Attachment: coresample_b87ff294.zip

SW Stephen Welborn March 10, 2023 03:51 PM UTC

ej2.min.js:10 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'previousElementSibling')

var spreadsheetObj = ej.base.getComponent(document.getElementById('spreadsheet3'), 'spreadsheet');

 spreadsheetObj.setColumnsWidth(100, ["A:M"]); // To set width for columns.  This is where the error occurs.


SP Sangeetha Priya Murugan Syncfusion Team March 13, 2023 09:21 AM UTC

Hi Stephen,

Your reported issue doesn’t occur on our end, and the spreadsheet is rendered properly with the applied width using the setColumnsWidth method. Please find the video demonstration attached below, and we suspect that you have referred to the older scripts and CSS in your application. So, please go through our previous sample thoroughly and render the spreadsheet as it is. If you are still having the same issue, please replicate your issue in our previously provided sample and send it back to us, and based on that, we can be able to check and proceed further.

Attachment: setcolej2_b99ce7ea.zip

Live Chat Icon For mobile
Up arrow icon