How to save an Excel file on the server from the client

Posted by: avloenen on 23 July 2019, 5:58 am EST

  • Posted 23 July 2019, 5:58 am EST

    Hello,

    I want to open and save a Excel files from the client on the server.

    I managed to open an excel file on the server.

    But I cannot save the file on the server on. Here I can only export/download the excel file to the client.

    Is it also possible to save an Excel file on the server?

    I have added my example.

    please your help!

    thanks in advance

    André van Loenen

    Sampleloadfile.zip

  • Posted 24 July 2019, 12:22 am EST

    Hi André,

    Since the SpreadJS is a client-side control it cannot save files directly on the server. What you need to do is generate the blob for excel file and send the generated blob to the server using XHR or fetch API and finally, the server should listen to this request and save the file. Please refer to the following code snippet:

    // generate excel file
    var json = spread.toJSON({includeBindingSource: true});
    excelIO.save(json, function (blob) {
    	var excelFile = blob;
    	// make xhr request to send excel file to server
    	var xhr = new XMLHttpRequest();
    	xhr.open("POST", "server_url_to_handle_file_upload", true);      
    	xhr.onload = function(){
    		// uploaded to server
    	}
    	xhr.send(excelFile);
    }, function (e) {	
    	console.log("error", e);
    });
    

    Regards

Need extra support?

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

Learn More

Forum Channels