If you call javascript window.open and pass a url to a .xls file it open on some machines in the browser window. How can you force it into Excel?
如果你调用javascript窗口。打开并将url传递给在浏览器窗口的某些机器上打开的.xls文件。你怎么能把它变成Excel呢?
11 个解决方案
#1
3
Only the users machine can "force" it into Excel. That said, 99% of the time if you send the correct mime-type and a user has Excel, then it will open in Excel assuming they approve.
只有用户机器才能“强制”它成为Excel。也就是说,99%的情况下,如果你发送了正确的mime类型并且用户有Excel,那么如果他们批准的话,它将会在Excel中打开。
And only the server can send the correct mime-type. The document type you pass to a JavaScript window.open call will have no effect on this. In fact, calling window.open will at best just open a superfluous window.
只有服务器才能发送正确的mime类型。传递给JavaScript窗口的文档类型。open call对这一点没有影响。事实上,调用窗口。打开充其量只能打开一个多余的窗口。
It's best to just link to the document with <a href="foo.xls">
. And provided your server is sending a mime-type of application/x-excel
or application/x-msexcel
this will almost always nudge the browser into opening a new window with the Excel document.
最好使用链接到文档。如果您的服务器正在发送一个mime类型的应用程序/x-excel或应用程序/x-msexcel,这几乎总是会促使浏览器使用Excel文档打开一个新的窗口。
#2
1
If it's just a static file, and you're using Apache on Linux, check for a file called /etc/mime.types, and ensure that it has the following line in there to associate the .xls file extension with the correct MIME type:
如果它只是一个静态文件,而您正在Linux上使用Apache,请检查名为/etc/ mimeme的文件。类型,并确保它具有以下一行,以将.xls文件扩展与正确的MIME类型相关联:
application/vnd.ms-excel xls
I'm guessing the location of that file might vary across systems, but it's in /etc/mime.types on my server which is running RHEL4.
我猜这个文件的位置在不同的系统中可能会有所不同,但是它在/etc/ mimeem中。在运行RHEL4的服务器上键入。
#3
0
AFAIK you can't do this with JavaScript alone. If you have some sort of scripting language on the server's side you can alter the header to force a download.
当然,仅用JavaScript是不行的。如果您在服务器端有某种脚本语言,您可以更改header以强制下载。
Here's a simple tutorial in PHP, but you can easily find one in your favorite language.
这里有一个简单的PHP教程,但是您可以很容易地找到您最喜欢的语言。
#4
0
You cannot force it into Excel. You can allow the browser to handle it whichever way it is configured to do so, or you can try to force it to download the file and let the user open if from their desktop. To force a download, search for "force download" and your server-side language (PHP, ASP.NET, JSP, etc.)
你不能强迫它成为Excel。您可以允许浏览器以任何配置的方式来处理它,或者您可以尝试强制它下载文件,并让用户从他们的桌面打开。要强制下载,请搜索“force download”和您的服务器端语言(PHP, ASP)。净、JSP、等等)。
#5
0
I don't think you can: you cannot call external programs using Javascript for security reasons. Assuming that the user has Excel installed, you may want to open the new window without the address bar to give the user "the illusion" that the file has been opened with Excel in Internet Explorer.
我认为您不能:出于安全原因,您不能使用Javascript调用外部程序。假设用户已经安装了Excel,您可能想要在没有地址栏的情况下打开新窗口,以使用户“错觉”该文件已在Internet Explorer中使用Excel打开。
#6
0
I wouldn't think this is possible from javascript due to security issues, there would be nothing stopping a rogue webpage from opening dozens of excel/word instances.
由于安全问题,我认为javascript不可能做到这一点,没有什么能阻止一个流氓网页打开几十个excel/word实例。
Could you not set a hyperlink to the url of the .xls, that way the user would get the usual download prompt to view the file.
如果不设置.xls的url的超链接,用户将获得通常的下载提示符来查看文件。
#7
0
- Set the http content type to the Excel datatype: application/vnd.ms-excel
- 将http内容类型设置为Excel数据类型:application/vnd.ms-excel
- You shouldn't need to redirect to a new window, but you will get a popup asking the user to save or open the file.
- 您不需要重定向到新窗口,但是您将得到一个弹出窗口,请求用户保存或打开该文件。
- In relation to (2): I'd worry if a browser could launch an external application and load data into it automatically without user intervention.
- 关于(2):我担心浏览器是否可以在不受用户干预的情况下启动外部应用程序并自动加载数据。
#8
0
This is a setting in each user's browser and not in something that can be set by code. So unfortunately you do not have control of that.
这是每个用户浏览器中的设置,而不是代码可以设置的设置。不幸的是你无法控制它。
#9
0
You can not, as it depends on the client machine.
您不能,因为这取决于客户端机器。
For example on Windows if you want it to always open it with Excel, not in the browser window, you have to open My Computer, Tools, Folder Options, File Types, select the XLS type, and click on Advanced. There are two checkboxes: Browse in same window and Open web documents in place. Uncheck both, close browser window, open it again and try again.
例如在Windows上,如果你想让它总是用Excel而不是浏览器窗口打开,你必须打开我的电脑,工具,文件夹选项,文件类型,选择XLS类型,然后点击高级。有两个复选框:在同一个窗口中浏览和在适当的地方打开web文档。取消检查,关闭浏览器窗口,再次打开并重试。
However as I said: it depends on the client, you can not force it.
但是正如我说的:这取决于客户,你不能强迫它。
#10
0
You can do this using LaunchinIE, an ActiveX Control that will enable HTML pages to start whatever application on the client's machine, without security warnings.
您可以使用LaunchinIE来实现这一点。LaunchinIE是一个ActiveX控件,它可以让HTML页面在客户机上启动任何应用程序,而无需发出安全警告。
Quote from the site: "At last, web pages can start Word, Excel, or any other corporate application without complaints. Securely."
引用网站上的话:“最终,web页面可以启动Word、Excel或任何其他公司应用程序,而无需抱怨。安全。”
For this you do have to install the control on the user machine and also add the URL that is allowed to execute local applications to the Windows registry.
为此,您必须在用户机器上安装控件,并将允许执行本地应用程序的URL添加到Windows注册表。
Another quote from the site: "To ensure security, LaunchinIE needs to be carefully configured client-side; due to this restriction it's only fit for intranet use."
网站上的另一段话:“为了确保安全,LaunchinIE需要仔细配置客户端;由于这个限制,它只适合内部网使用。
I use LaunchinIE in our training facility so I can use Internet Explorer as a menu which lets the user choose the machine setup. LaunchinIE then calls a batch script that configures the machine to best support the selected training.
我在我们的培训设备中使用LaunchinIE,所以我可以使用Internet Explorer作为菜单,让用户选择机器设置。LaunchinIE然后调用一个批处理脚本,该脚本配置机器以最佳地支持所选的训练。
#11
0
Here are the steps to get this pop-up back when opening a saved Excel file.
以下是打开保存的Excel文件时重新弹出的步骤。
- Right-Click on the windows [START] button and select Explore to open Windows Explorer window will open.
- 右键单击windows [START]按钮,选择Explore打开windows资源管理器窗口。
-
From the menu select Tools \ Folder Options…
• Choose the File Types tab and scroll down the list of files.
• Left-Click to highlight the XLS Microsoft Excel Worksheet file extension and click on the Advanced button.从菜单中选择Tools \文件夹选项……•选择File Types选项卡并向下滚动文件列表。•左键单击以突出显示XLS Microsoft Excel工作表文件扩展名,然后单击高级按钮。
-
In the Edit File Type window, Uncheck the “Browse in same window” option.
在“编辑文件类型”窗口中,取消“在同一窗口中浏览”选项。
-
Click OK button to accept your changes.
单击OK按钮接受更改。
-
Start a new browser session. The next time you open your Excel spreadsheet in your Inbox, you should be prompted with the following window. Be sure to leave the “Always ask before opening this type of file” as checked. Clicking the Open button should now open your file in Excel.
启动一个新的浏览器会话。下次在收件箱中打开Excel电子表格时,应该使用以下窗口提示您。请务必在打开这类文件之前留下“始终询问”。单击Open按钮,现在可以在Excel中打开文件。
#1
3
Only the users machine can "force" it into Excel. That said, 99% of the time if you send the correct mime-type and a user has Excel, then it will open in Excel assuming they approve.
只有用户机器才能“强制”它成为Excel。也就是说,99%的情况下,如果你发送了正确的mime类型并且用户有Excel,那么如果他们批准的话,它将会在Excel中打开。
And only the server can send the correct mime-type. The document type you pass to a JavaScript window.open call will have no effect on this. In fact, calling window.open will at best just open a superfluous window.
只有服务器才能发送正确的mime类型。传递给JavaScript窗口的文档类型。open call对这一点没有影响。事实上,调用窗口。打开充其量只能打开一个多余的窗口。
It's best to just link to the document with <a href="foo.xls">
. And provided your server is sending a mime-type of application/x-excel
or application/x-msexcel
this will almost always nudge the browser into opening a new window with the Excel document.
最好使用链接到文档。如果您的服务器正在发送一个mime类型的应用程序/x-excel或应用程序/x-msexcel,这几乎总是会促使浏览器使用Excel文档打开一个新的窗口。
#2
1
If it's just a static file, and you're using Apache on Linux, check for a file called /etc/mime.types, and ensure that it has the following line in there to associate the .xls file extension with the correct MIME type:
如果它只是一个静态文件,而您正在Linux上使用Apache,请检查名为/etc/ mimeme的文件。类型,并确保它具有以下一行,以将.xls文件扩展与正确的MIME类型相关联:
application/vnd.ms-excel xls
I'm guessing the location of that file might vary across systems, but it's in /etc/mime.types on my server which is running RHEL4.
我猜这个文件的位置在不同的系统中可能会有所不同,但是它在/etc/ mimeem中。在运行RHEL4的服务器上键入。
#3
0
AFAIK you can't do this with JavaScript alone. If you have some sort of scripting language on the server's side you can alter the header to force a download.
当然,仅用JavaScript是不行的。如果您在服务器端有某种脚本语言,您可以更改header以强制下载。
Here's a simple tutorial in PHP, but you can easily find one in your favorite language.
这里有一个简单的PHP教程,但是您可以很容易地找到您最喜欢的语言。
#4
0
You cannot force it into Excel. You can allow the browser to handle it whichever way it is configured to do so, or you can try to force it to download the file and let the user open if from their desktop. To force a download, search for "force download" and your server-side language (PHP, ASP.NET, JSP, etc.)
你不能强迫它成为Excel。您可以允许浏览器以任何配置的方式来处理它,或者您可以尝试强制它下载文件,并让用户从他们的桌面打开。要强制下载,请搜索“force download”和您的服务器端语言(PHP, ASP)。净、JSP、等等)。
#5
0
I don't think you can: you cannot call external programs using Javascript for security reasons. Assuming that the user has Excel installed, you may want to open the new window without the address bar to give the user "the illusion" that the file has been opened with Excel in Internet Explorer.
我认为您不能:出于安全原因,您不能使用Javascript调用外部程序。假设用户已经安装了Excel,您可能想要在没有地址栏的情况下打开新窗口,以使用户“错觉”该文件已在Internet Explorer中使用Excel打开。
#6
0
I wouldn't think this is possible from javascript due to security issues, there would be nothing stopping a rogue webpage from opening dozens of excel/word instances.
由于安全问题,我认为javascript不可能做到这一点,没有什么能阻止一个流氓网页打开几十个excel/word实例。
Could you not set a hyperlink to the url of the .xls, that way the user would get the usual download prompt to view the file.
如果不设置.xls的url的超链接,用户将获得通常的下载提示符来查看文件。
#7
0
- Set the http content type to the Excel datatype: application/vnd.ms-excel
- 将http内容类型设置为Excel数据类型:application/vnd.ms-excel
- You shouldn't need to redirect to a new window, but you will get a popup asking the user to save or open the file.
- 您不需要重定向到新窗口,但是您将得到一个弹出窗口,请求用户保存或打开该文件。
- In relation to (2): I'd worry if a browser could launch an external application and load data into it automatically without user intervention.
- 关于(2):我担心浏览器是否可以在不受用户干预的情况下启动外部应用程序并自动加载数据。
#8
0
This is a setting in each user's browser and not in something that can be set by code. So unfortunately you do not have control of that.
这是每个用户浏览器中的设置,而不是代码可以设置的设置。不幸的是你无法控制它。
#9
0
You can not, as it depends on the client machine.
您不能,因为这取决于客户端机器。
For example on Windows if you want it to always open it with Excel, not in the browser window, you have to open My Computer, Tools, Folder Options, File Types, select the XLS type, and click on Advanced. There are two checkboxes: Browse in same window and Open web documents in place. Uncheck both, close browser window, open it again and try again.
例如在Windows上,如果你想让它总是用Excel而不是浏览器窗口打开,你必须打开我的电脑,工具,文件夹选项,文件类型,选择XLS类型,然后点击高级。有两个复选框:在同一个窗口中浏览和在适当的地方打开web文档。取消检查,关闭浏览器窗口,再次打开并重试。
However as I said: it depends on the client, you can not force it.
但是正如我说的:这取决于客户,你不能强迫它。
#10
0
You can do this using LaunchinIE, an ActiveX Control that will enable HTML pages to start whatever application on the client's machine, without security warnings.
您可以使用LaunchinIE来实现这一点。LaunchinIE是一个ActiveX控件,它可以让HTML页面在客户机上启动任何应用程序,而无需发出安全警告。
Quote from the site: "At last, web pages can start Word, Excel, or any other corporate application without complaints. Securely."
引用网站上的话:“最终,web页面可以启动Word、Excel或任何其他公司应用程序,而无需抱怨。安全。”
For this you do have to install the control on the user machine and also add the URL that is allowed to execute local applications to the Windows registry.
为此,您必须在用户机器上安装控件,并将允许执行本地应用程序的URL添加到Windows注册表。
Another quote from the site: "To ensure security, LaunchinIE needs to be carefully configured client-side; due to this restriction it's only fit for intranet use."
网站上的另一段话:“为了确保安全,LaunchinIE需要仔细配置客户端;由于这个限制,它只适合内部网使用。
I use LaunchinIE in our training facility so I can use Internet Explorer as a menu which lets the user choose the machine setup. LaunchinIE then calls a batch script that configures the machine to best support the selected training.
我在我们的培训设备中使用LaunchinIE,所以我可以使用Internet Explorer作为菜单,让用户选择机器设置。LaunchinIE然后调用一个批处理脚本,该脚本配置机器以最佳地支持所选的训练。
#11
0
Here are the steps to get this pop-up back when opening a saved Excel file.
以下是打开保存的Excel文件时重新弹出的步骤。
- Right-Click on the windows [START] button and select Explore to open Windows Explorer window will open.
- 右键单击windows [START]按钮,选择Explore打开windows资源管理器窗口。
-
From the menu select Tools \ Folder Options…
• Choose the File Types tab and scroll down the list of files.
• Left-Click to highlight the XLS Microsoft Excel Worksheet file extension and click on the Advanced button.从菜单中选择Tools \文件夹选项……•选择File Types选项卡并向下滚动文件列表。•左键单击以突出显示XLS Microsoft Excel工作表文件扩展名,然后单击高级按钮。
-
In the Edit File Type window, Uncheck the “Browse in same window” option.
在“编辑文件类型”窗口中,取消“在同一窗口中浏览”选项。
-
Click OK button to accept your changes.
单击OK按钮接受更改。
-
Start a new browser session. The next time you open your Excel spreadsheet in your Inbox, you should be prompted with the following window. Be sure to leave the “Always ask before opening this type of file” as checked. Clicking the Open button should now open your file in Excel.
启动一个新的浏览器会话。下次在收件箱中打开Excel电子表格时,应该使用以下窗口提示您。请务必在打开这类文件之前留下“始终询问”。单击Open按钮,现在可以在Excel中打开文件。