为什么我的Excel另存为对话框显示不正确? [英] Why is my Excel Save As Dialog Box not appearing correctly?

查看:141
本文介绍了为什么我的Excel另存为对话框显示不正确?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨:

我使用ASP.NET和C#(代码隐藏)开发了一个SharePoint WebPart。

需要做的一件事是启动Excel另存为对话框,以便用户可以保存Excel文件。



在SharePoint Server框中,此功能可正常运行。当我单击导出时,按预期显示Excel另存为对话框。

但是,从客户端计算机(例如我的),此功能无法正常工作。当我单击导出时,Excel另存为对话框不会出现。



启动此对话框的代码片段...



 xlApp.DisplayAlerts = false; 
//xlWorkBook.Save();

Microsoft.Office.Interop.Excel.Dialog dialog = xlApp.Dialogs [Microsoft.Office.Interop.Excel.XlBuiltInDialog.xlDialogSaveAs];
dialog.Show(Type.Missing,// document_text
Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookDefault,// type_num
Type.Missing,// prot_pwd
Type .Missing,// backup
Type.Missing,// write_res_pwd
Type.Missing,// read_only_rec
Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type。缺失,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing, Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing);
xlApp.DisplayAlerts = true;





你知道造成这种差异的原因是什么吗?我应该调查一些特别的事情吗?

感谢您的帮助,

-Krishna

解决方案

您编写的代码是在服务器上本地运行Excel。它不通过HTTP传递文件。如果你想通过HTTP传递它,你希望浏览器显示另存为对话框,而不是Excel。



 MemoryStream ms =  new  MemoryStream(); 
xlWorkBook.Save(ms,FileFormatType.Default);
ms.Seek( 0 ,SeekOrigin.Begin);
byte [] buffer = new byte [( int )ms.Length];
buffer = ms.ToArray();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader( Content-Disposition string .Format( attachment; filename = {0},fileName));
HttpContext.Current.Response.ContentType =);
HttpContext.Current.Response.BinaryWrite(fileData);
HttpContext.Current.Response.End();



你好TM:



感谢您的回复。很抱歉我延迟回复..我正在开发一个不同的项目,但现在已经重新分配给了这个..



你用过aspose来编写码?因为XlWorkBook对象上的Save()方法没有正常的参数。如果我试图超载它,我收到错误消息。



有没有办法在不使用aspose的情况下执行此操作?



感谢您的帮助,

-Krishna


对话框显示回浏览器是否有解决方案对话框显示在浏览器前面。

Hi:
I have developed a SharePoint WebPart using ASP.NET and C# (code behind).
One of the things that needs to be done is to launch the Excel Save As dialog so that the user can save the Excel file.

On the SharePoint Server box, this functionality works correctly. When I click "Export", as expected the Excel "Save As" dialog appears.
However, from a client machine (such as mine), this functionality does not work correctly. When I click "Export", the Excel "Save As" dialog box does NOT appear.

Code snippet where this dialog is being launched…

xlApp.DisplayAlerts = false;
//xlWorkBook.Save();

Microsoft.Office.Interop.Excel.Dialog dialog = xlApp.Dialogs[Microsoft.Office.Interop.Excel.XlBuiltInDialog.xlDialogSaveAs];
dialog.Show(Type.Missing, // document_text
Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookDefault, // type_num
Type.Missing, // prot_pwd
Type.Missing, // backup
Type.Missing, // write_res_pwd
Type.Missing, // read_only_rec
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
xlApp.DisplayAlerts = true;



Do you know what could be causing this difference? Are there some particular things I should investigate?
Thanks for your help,
-Krishna

解决方案

The code you wrote is running Excel locally on the server. It is not delivering the file over HTTP. If you want to deliver it over HTTP you would want the browser to display the save as dialog, not Excel.

MemoryStream ms = new MemoryStream();
xlWorkBook.Save(ms,FileFormatType.Default);
ms.Seek(0, SeekOrigin.Begin);   
byte[] buffer = new byte[(int)ms.Length];
buffer = ms.ToArray();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", fileName));
HttpContext.Current.Response.ContentType = );
HttpContext.Current.Response.BinaryWrite(fileData);
HttpContext.Current.Response.End();



Hi T.M:

Thanks for your reply. Sorry for my delay in responding..I was working on a different project, but have now been re-assigned to this..

Have you used aspose to write the code? Because the Save() method on the XlWorkBook object takes no parameters normally. If I try to overload it , I get error messages.

Is there a way to do this without using aspose?

Thanks for your help,
-Krishna


dialog is showing back to the browser is there solution dialog is showing front to the browser.


这篇关于为什么我的Excel另存为对话框显示不正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆