为什么导出到vb.net中的excel代码不能在Server上工作,当它在本地机器上工作时。 [英] Why Export to excel code in vb.net not working on Server ,when its working on local machine.?

查看:134
本文介绍了为什么导出到vb.net中的excel代码不能在Server上工作,当它在本地机器上工作时。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用vb.net在VS 2005中完成了导出到Excel,我的代码在本地机器上运行良好但是我把我的代码放在我的服务器上的相同代码不工作。



当我点击Excel导出按钮时,目标文件在服务器上给我空值。



我的代码,其中的确切错误如下所示。







  Dim  p 作为 处理
p.StartInfo = ProcessStartInfo(targetFilename)
p.Start()







请帮助它非常重要..

解决方案

您正在尝试打开Excel文件在服务器上。当您在本地运行该站点时,这是有效的,因为客户端和服务器是同一台计算机。当您将站点部署到真实服务器时,它不会起作用。您需要使用 Response.TransmitFile 将Excel文件发送到客户端。



此外,根据您的评论,您正在尝试将文件写入 C:驱动器的根目录。由于您的站点不会以管理用户身份运行,因此它无权写入该位置。选择它有权访问的文件夹 - 例如,网站中的 App_Data 文件夹。



< pre lang =c#> DataSet ds = CreateSampleData();

// 构建应用程序可以写入的路径。
// 使用随机文件名来避免多个同时请求发生冲突。
string targetFolder = Server.MapPath( 〜/ App_Data / );
string excelFilename = Path.GetRandomFileName()+ .XLSX;
string excelPath = Path.Combine(targetFolder,excelFilename);

// 创建Excel文件:
CreateExcelFile.CreateExcelDocument (ds,excelPath);

// 将文件传输到客户端:
回复.ContentType = application / vnd.openxmlformats-officedocument.spreadsheetml.sheet;
Response.AddHeader( Content-Disposition attachment; filename = Sample.xlsx);
Response.TransmitFile(excelPath);
Response.Flush();

// 删除临时文件:
File.Delete (excelPath);


http://stackoverflow.com/questions/21020359/export-data-from-vb-to-excel-sheet [ ^ ]





http://stackoverflow.com/questions/21020359 / export-data-from-vb-to-excel-sheet [ ^ ]



尝试thiz ..


你好,



我过去遇到过这种情况。



常见问题m在服务器中没有安装office / excel。



请尝试下载并安装以下访问引擎。



http://www.microsoft.com/en-in/download/details.aspx?id=13255



你没有提到你有哪个版本的excel。请尝试在服务器上下载并安装相应的版本。



希望这会有所帮助!



- S Francis

我的博客


I Have done Export To Excel in VS 2005 using vb.net ,My code Works Fine on local machine but i put

the Same code on my Server its Not Working .

when i click on Excel to export button , target File gives me null values on server.

my Code where the exact error throughing is like below.



Dim p As New Process
 p.StartInfo = New ProcessStartInfo(targetFilename)
 p.Start()




please Help its very important ..

解决方案

You're attempting to open the Excel file on the server. When you run the site locally, that works, since the client and server are the same computer. When you deploy the site to a real server, it's not going to work. You need to send the Excel file to the client using Response.TransmitFile.

Also, based on your comment, you're trying to write the file to the root of the C: drive. Since your site won't be running as an administrative user, it won't have permission to write to that location. Pick a folder to which it does have access - for example, the App_Data folder within the site.

DataSet ds = CreateSampleData();

// Build a path to which the application can write.
// Use a random file-name to avoid collisions from multiple simultaneous requests.
string targetFolder = Server.MapPath("~/App_Data/");
string excelFilename = Path.GetRandomFileName() + ".xlsx";
string excelPath = Path.Combine(targetFolder, excelFilename);

// Create the Excel file:
CreateExcelFile.CreateExcelDocument(ds, excelPath);

// Transmit the file to the client:
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("Content-Disposition", "attachment;filename=Sample.xlsx");
Response.TransmitFile(excelPath);
Response.Flush();

// Delete the temporary file:
File.Delete(excelPath);


http://stackoverflow.com/questions/21020359/export-data-from-vb-to-excel-sheet[^]


http://stackoverflow.com/questions/21020359/export-data-from-vb-to-excel-sheet[^]

Try thiz..


Hi,

I have encountered these kind of situation in my past.

The common problem is in the server there is no office/excel installed.

Please try to download and install the below access engine.

http://www.microsoft.com/en-in/download/details.aspx?id=13255

You didn't mentioned which version of excel you have. Please try to download and install appropriate version in the server machine.

Hope this helps!

- S Francis
My Blog


这篇关于为什么导出到vb.net中的excel代码不能在Server上工作,当它在本地机器上工作时。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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