6

I have a MVC ActionResult controller that download the file.

If is PDF then using this JS code

var $obj = $('<object>');
$obj.attr("type", "application/pdf");
$obj.attr("data", myurl);                            
$("#id").append($obj);

Then i can preview the PDF in my app.

I want something similar for XLSX or XLS files.

If i hit the url i get the file but i cannot display it.

I tried with

<iframe src="https://docs.google.com/gview?url=myurl"></iframe>

but doesnt work.

Any ideas?

georgeawg
  • 48,608
  • 13
  • 72
  • 95
GomuGomuNoRocket
  • 771
  • 2
  • 11
  • 37
  • 1
    You can preview the PDF because you have the according browser plugin installed. If you want the same for an Excel spreadsheet, you need a browser plugin to handle this. – Filburt Jun 25 '19 at 10:59
  • so, without make anyone to install a plugin, i cannot display excel? – GomuGomuNoRocket Jun 25 '19 at 11:02
  • 1
    First see if you can directly open an XLS or XLSX file in your browser. If the browser doesn't know what to do with that file then it won't be able to display it anyway. (And even if your browser does, that doesn't mean other users will.) – David Jun 25 '19 at 11:02
  • If i hit my url, then the file is downloading, so i guess my server side knows – GomuGomuNoRocket Jun 25 '19 at 11:04
  • 2
    There is a javascript plugin to do this. https://github.com/SheetJS/js-xlsx – Steve Jun 25 '19 at 11:11
  • 1
    @GomuGomuNoRocket That's right. Without a browser plugin, users will be prompted to save the file download. – Filburt Jun 25 '19 at 11:18

0 Answers0