Dealing with empty columns after excelIO.open(...)

Posted by: ablsoft on 22 May 2019, 11:58 pm EST

  • Posted 22 May 2019, 11:58 pm EST - Updated 3 October 2022, 1:51 am EST

    Hi,

    We are importing an excel document that looks like this:

    We are getting the spreadjs object using excelIO.open(file, function (spread)…,

    It is reading a bunch of empty columns to the right, up to 75, so activeSheet.getColumnCount() is 75 while it should be 10.

    Is there a way to help me at least make a programmatic count of non-empty columns? I mean, is there a way in the API to help me detect if given a column number, know whether or not that column is empty?

    Thanks

  • Posted 23 May 2019, 9:06 pm EST

    Hi,

    The issue is arising because empty cells contain cell styles like border styles, so those columns are imported too. If you do not want to import the extra column then do not modify the style of empty columns in the excel file.

    Further if you need to check if a column is empty then you need to iterate over its cells and check if contains any data. Please refer to the following code snippet:

    function isColEmpty(sheet, colIndex){
    	for(var i = 0; i < sheet.getRowCount(); i++){
    		if(sheet.getValue(i, colIndex) != null){
    			return false;
    		}
    	}
    	return true;
    }
    

    Regards

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels