How open a page and open an excel file directly with ExcelMobileSample

Posted by: avloenen on 11 July 2019, 9:31 pm EST

  • Posted 11 July 2019, 9:31 pm EST

    Hello,

    I am using now ExcelMobileSample with js for testing the product.

    I want to open a page in my browser and open a excel file directly.

    So a open the index.html with a parameter after the “?”.(file:path/index.html?excelfile=path\excel.xlsx)

    In sample.js i created this function:

    function getexcelfile()
    {
    	var parameters = location.search.substring(1).split("&");
    	var temp = parameters[0].split("=");
    	excelfile = unescape(temp[1]);
    	
    	if (excelfile !== "undefined") 
    	{
           // what cann i do here?
    	}
    	else 
    	{
    		initSpread();
    	}
    }
    

    I hope than someone has the answer.

    My gratitude.

    André van Loenen

  • Posted 15 July 2019, 5:37 pm EST

    Hi André,

    Could you please confirm if the file you are trying to open is on the client machine or the server?

    If the file is on the client machine then we cannot automatically open it on load because due to the security reasons browsers do not allow web apps to access files on the client machine without the user interaction like using input element.

    However, if the file is on the server then first we need to load the file on the client using XHR or fetch request and then use the excelIo module to load the file. Please refer to the following code snippet which demonstrates the same and let us know if you face any issues:

    fetch("server_url_of_xlsx_file.xlsx")
        .then(res => res.blob())
        .then((blob) => {
    	var excelIo = new GC.Spread.Excel.IO();
            excelIo.open(blob, (wbjson) => {
                workbook.fromJSON(wbjson);
            });
        });
    

    Regards

  • Posted 15 July 2019, 5:59 pm EST

    Hello sharad.tomer,

    I am testing it on now the client and not on the server.

    I will do it on the server.

    Tanks for the answer.

    André van Loenen

  • Posted 23 July 2019, 6:26 pm EST

    This is what I have done:

    The internet page:

    http:///index.html?ExcelFile=.xlsx

    In javascript:

    function GetExcelFile() {

    var parameters = location.search.substring(1).split(“&”);

    var temp = parameters[0].split(“=”);

    ExcelFile = unescape(temp[1]);

    if (ExcelFile == "undefined")  {
        alert("No file found :( ");
    }
    

    }

    function ImportFileFromServer() {

    var excelUrl = "../Files/" + ExcelFile;
    var oReq = new XMLHttpRequest();
    oReq.open('get', excelUrl, true);
    oReq.responseType = 'blob';
    oReq.onload = function () {
        var blob = oReq.response;
        excelIO.open(blob, LoadSpread, function (message) {
            console.log(message);
        });
    };
    oReq.send(null);
    

    }

    function LoadSpread(json) {

    jsonData = json;

    spread.fromJSON(json);

    }

    GetExcelFile();

    if (ExcelFile !== “undefined”)

    ImportFileFromServer();

  • Posted 24 July 2019, 3:26 pm EST

    Thank you for sharing your approach with us. It seems like your issue has been resolved. Please let us know if you face any further issues.

Need extra support?

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

Learn More

Forum Channels