cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

problem with load of xlsx file

LS_9776545
9-Granite

problem with load of xlsx file

Hi everyone, 

in my project I want to load information from an xls or xlsx file. 

My idea is to: 

1. load xlxs/xls file 

2. convert to json file 

3. use the json 

 

I tried to setup this piece of code, that is actually running for *.txt or *.json file: 

//\\ ** CARICAMENTO LISTA RICAMBI ** //\\
$scope.app.cad.loadXLSfile=function(fileName){ 
var xmlhttp = new XMLHttpRequest(); //apertura del file sequenze
xmlhttp.onreadystatechange = function() {
	if (this.readyState == 4 && this.status == 200) {
		
      	console.log(">> this: "+ this)
      	listaRicambi = JSON.parse(this.response)
        console.log(listaRicambi) // repair_sequence è il nome dell'oggetto indicato nel file .txt formattato con grammatica json
    	
    }       
};
xmlhttp.open("GET", "app/resources/Uploaded/" + fileName + ".xlsx", true);
xmlhttp.send();
}

So, when I inspect the preview mode console print some error like: 

Uncaught SyntaxError: Unexpected token P in JSON at position 0
    at JSON.parse (<anonymous>)
    at XMLHttpRequest.xmlhttp.onreadystatechange (app.js?v1611219048987:568)

 

Any idea?

 

Thank you so much. 

1 REPLY 1

I think the approach as your tried is good, but I suspect it  will not work in this case.

If you mean xlsx file - is an EXCEL file - I do not think that we could parse this with the basic javaScript functionality e.g. JSON.parse(). So far I know this file is binary so that I do not know such parser could be used . Such parser should "understand" the excel functionality.(in generally could be possible)

What you can do : you can try to export your excel file to csv file and then try to convert the csv format – in case that this is some table values.

Also excel may be, could support some xml export format where you can find some existing xml parse to json.

Announcements

Topics available:
AR/VR for Data Optimization AR/VR for Security and Control AR/VR for Inspection