- Home
- Forum
- ASP.NET MVC - EJ 2
- how can I read a xlsx from a url
how can I read a xlsx from a url
@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
SIGN IN To post a reply.
11 Replies
SD
Saranya Dhayalan
Syncfusion Team
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
RI
Ricardo
January 7, 2020 04:17 PM UTC
thanks but now it shows me this issue
Attachment: document_excel_a35bbf9.zip
I mean it works with couchDB database
Attachment: document_excel_a35bbf9.zip
SD
Saranya Dhayalan
Syncfusion Team
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
RI
Ricardo
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
Attachment: document_excel__1_b85faa93.zip
SD
Saranya Dhayalan
Syncfusion Team
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
RI
Ricardo
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?
SD
Saranya Dhayalan
Syncfusion Team
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.
Sample link: https://www.syncfusion.com/downloads/support/forum/150423/ze/SpreadsheetLoadFromURLCORS676660697
Regards,
Saranya D
RI
Ricardo
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
Attachment: document_excel_83d0ac34.zip
SD
Saranya Dhayalan
Syncfusion Team
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
RI
Ricardo
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
Attachment: document_excel_5d862795.zip
MV
Madhan Venkateshan
Syncfusion Team
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
SIGN IN To post a reply.
- 11 Replies
- 3 Participants
-
RI Ricardo
- Jan 6, 2020 11:58 PM UTC
- Jan 17, 2020 10:51 AM UTC