如何在用javascript下载excel文件后打开它?
我使用以下代码下载excel文件(.xls): JavaScript代码:如何在用javascript下载excel文件后打开它?,javascript,c#,jquery,excel,Javascript,C#,Jquery,Excel,我使用以下代码下载excel文件(.xls): JavaScript代码: window.location=result.filename 下载后,我想自动打开一个excel文件,无需单击它。我想要JavaScript代码自动打开excel文件 我用下面的函数代码进行了测试。但它只在Internet Explorer中运行,而不是在Mozilla、Chrome function openExcelFile(strFilePath) { var objExcel; objExcel = new A
window.location=result.filename代码>
下载后,我想自动打开一个excel文件,无需单击它。我想要JavaScript代码自动打开excel文件
我用下面的函数代码进行了测试。但它只在Internet Explorer中运行,而不是在Mozilla、Chrome
function openExcelFile(strFilePath) {
var objExcel;
objExcel = new ActiveXObject("Excel.Application");
objExcel.Visible = true;
objExcel.Workbooks.Open(strFilePath);
}
通过使用上述代码,excel文件在Internet Explorer中下载后将自动打开
我想JavaScript代码打开excel文件自动下载后,在所有浏览器的工作
public ActionResult GetFile(string path)
{
string extension = new FileInfo(path).Extension;
if (extension != null || extension != string.Empty)
{
switch (extension)
{
case ".xls":
return File(path, "application/vnd.ms-excel");
case ".xlsx":
return File(path, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
}
}
return View("Index");
}
如何实现此目的?将excel文件路径传递给控制器。它可以在所有浏览器上正常工作
public ActionResult GetFile(string path)
{
string extension = new FileInfo(path).Extension;
if (extension != null || extension != string.Empty)
{
switch (extension)
{
case ".xls":
return File(path, "application/vnd.ms-excel");
case ".xlsx":
return File(path, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
}
}
return View("Index");
}
mozilla或chrome没有打开excel文件时是否显示任何错误无法在mozilla、chrome中打开excel文件…显示错误。因为ActiveXObject在chrome、mozilla中不受支持。如何获取用户保存文件的路径?我使用此代码。我得到“你的浏览器不支持这个”。因为ActiveXObject在chrome中不支持,所以mozilla。我想打开所有浏览器都自动支持的excel文件。请帮帮我。@NivithaG对不起。chrome和firefox中不支持ActiveXObject。为什么您可以通过c代码从服务器端下载并显示excel工作表。我如何通过c代码mvc从服务器端下载并显示excel工作表?您如何在项目中加载excel工作表