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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

how can I read a xlsx from a url

Thread ID:

Created:

Updated:

Platform:

Replies:

150423 Jan 6,2020 11:58 PM UTC Jan 17,2020 10:51 AM UTC ASP.NET MVC - EJ 2 11
loading
Tags: Spreadsheet
Ricardo
Asked On January 6, 2020 11:58 PM UTC

@model string


@Html.EJS().Spreadsheet("spreadsheet").Created("onCreated").Render()

<script>


     var fileName = "@Model";

    var documenteditor;

    function onCreated(args) {

        var container = document.getElementById("spreadsheet").ej2_instances[0];
        documenteditor = container.documentEditor;
        documenteditor.resize();

        $.ajax({
            url: "@Url.Action("OpenWord", "Download", new { area = "OperacionesGenerales" }, Request.Url.Scheme)",
            data: { fileName },
            beforeSend: function () {
                //Showloading();
            },
            success: function (doc) {
                //$("#descarga").html(doc);
                console.log(doc)
                documenteditor.open(doc);
            },
            error: function (jqXHR, textStatus, errorThrown) {
                console.log(jqXHR);
                console.log(textStatus);
                console.log(errorThrown);
                alert("error");
            },
            complete: function () {

            }
        })
    }


</script>

@Html.EJS().ScriptManager()


I wold like to read a xlsx form a url but it doesnt work and I do not have the server function If you could give a sample it would be greatfull thanks for the attention


Saranya Dhayalan [Syncfusion]
Replied On January 7, 2020 11:00 AM UTC

Hi Ricardo, 
 
Good day to you. 
 
We would like to suggest you use XMLHttpRequest to get the file in the server and you can load it to the Spreadsheet control using open method. Please refer the below code snippets. 
 
Index.cshtml 
@Html.EJS().Spreadsheet("spreadsheet").Created("onCreated").OpenUrl("Home/Open").SaveUrl("Home/Save").Render() 
<script> 
    function onCreated() { 
        var spreadsheetObj = ej.base.getComponent(document.getElementById('spreadsheet'), 'spreadsheet'); 
        var request = new XMLHttpRequest(); 
        request.responseType = "blob"; 
        request.onload = () => { 
            var file = new File([request.response], "Sample1.xlsx"); 
            spreadsheetObj.open({ file: file }); 
        } 
        request.open("GET", "/Files/Sample1.xlsx"); // To Get the file from the URL 
        request.send(); 
    } 
</script> 
 
 
For your convenience, we have prepared a sample. Please find the below sample link 
Sample link:  
 
 
Could you please check the above sample link and get back to us, if you need any further assistance on this? 
 
Regards, 
Saranya D 


Ricardo
Replied On January 7, 2020 04:17 PM UTC

thanks but now it shows me this issue

I mean it works with couchDB database

Attachment: document_excel_a35bbf9.zip

Saranya Dhayalan [Syncfusion]
Replied On January 8, 2020 10:41 AM UTC

Hi Ricardo, 
  
Good day to you. 
  
We have checked your issue. We are not able to reproduce it in our end. Could you please confirm whether you are using the below code snippets for open method in the controller? The reported issue may occur when improper type returned by the Open method. 
  
public ActionResult Open(OpenRequest openRequest) 
  { 
            return Content(Workbook.Open(openRequest)); 
   } 
  
Please check your issue with the above code snippets, if the issue persists,  
 
1.       Please share your controller code snippets  
2.       Please share the dummy excel file for reproducing the issue. 
 
  
Could you please provide the above requested information, based on that we will check and provide you a better solution quickly. 
 
Regards, 
Saranya D 


Ricardo
Replied On January 9, 2020 07:26 PM UTC

ok it works with local files but I need It reads a url document but it shows me a message in the console and do not show the info from the document

Attachment: document_excel__1_b85faa93.zip

Saranya Dhayalan [Syncfusion]
Replied On January 10, 2020 11:54 AM UTC

Hi Ricardo, 
  
Good day to you. 
  
We have checked your issue and the request you are trying to get the file and it is prevented by your server, you need to enable CORS in your server to resolve your issue. We suggest you add the below code snippets in web.config file to resolve your issue. Please check the below link for further details. 
  
Web.config 
<system.webServer> 
<httpProtocol> 
<customHeaders> 
<add name="Access-Control-Allow-Origin" value="*" /> 
</customHeaders> 
</httpProtocol> 
</system.webServer> 
  
Please find the below link 
  
  
Please let me know if you have any questions. 
 
Regards, 
Saranya D 


Ricardo
Replied On January 10, 2020 10:30 PM UTC

I tried the solution, even with a nuget package which is specialized in COR access and it did not work 

Don´t you have any example in mvc 5 with COR access?

Saranya Dhayalan [Syncfusion]
Replied On January 13, 2020 08:43 AM UTC

Hi Ricardo, 
  
Good day to you. 
  
We have prepared a MVC5 sample with enabled CORS in web.config and you can access “Sample1.xlsx” file placed in the Files folder in another domain, please check with below attached sample whether it resolve your issue, if still persist, please replicate your issue in the sample, So that we can sort out and provide you the better solution quickly. 
  
  
Regards, 
Saranya D 


Ricardo
Replied On January 13, 2020 04:13 PM UTC

thanks a lot and sorry if I am bothering you but now it shows me an exception in the image I am sending to you

Attachment: document_excel_83d0ac34.zip

Saranya Dhayalan [Syncfusion]
Replied On January 14, 2020 12:25 PM UTC

Hi Ricardo,  
 
We have checked your reported issue, we suspect this issue will occur because the Syncfusion. Xlsio dll doesn’t refer. So could you please add this dll(same version) to resolve your problem. 
 
Please check the below link: 
 
 
Could you please check the above sample and get back to us, if you need further assistance on this? 
Regards, 
Saranya D 


Ricardo
Replied On January 14, 2020 08:43 PM UTC

thanks again but know it shows me that the request is dangerous for the client 

Attachment: document_excel_5d862795.zip

Madhan Venkateshan [Syncfusion]
Replied On January 17, 2020 10:51 AM UTC

Hi Ricardo, 
 
Good day to you. 
 
We suspect the issue may arise when the url contains potential dangerous characters (< > * % & : \ ?) which may be used in XSS attacks. We suggest you to add the requestValidationMode or add the invalid characters in the requestPathInvalidCharacters attribute in web.config file to resolve your issue and please check the below stackoverflow link for futher details. 
 
Web.config 
  <system.web> 
<httpRuntime requestValidationMode="2.0" requestPathInvalidCharacters="put your invalid character here" /> 
  </system.web> 
 
 
 
 
Please check the above link, if the issue still persist, please share the issue reproducible sample. So that we can sort out and provide you the better solution quickly.  
 
Regards, 
Madhan V 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon