今天软件交付给客户,可是噩梦一般的感觉!!! VS2005,部署到目标计算机上一切成功,但是就是不能导入EXCEL文件,可是部署到我的开发机器上是可以导入EXCEL文件的,怎么回事情呢,????? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 导入EXECL文件的代码:protected void Button4_Click(object sender, EventArgs e) { try { GridView1.DataSource = createdatasource(); GridView1.DataBind(); } catch { Response.Write(""); }}private DataSet createdatasource() { ViewState["excelfile"] = FileUpload2.PostedFile.FileName.ToString(); string strconn; strconn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + FileUpload2.PostedFile.FileName + ";" + "Extended Properties=Excel 8.0;"; OleDbConnection conn = new OleDbConnection(strconn);OleDbDataAdapter comm = new OleDbDataAdapter("select * from [Sheet1$]", strconn); DataSet ds = new DataSet(); conn.Open(); comm.Fill(ds);conn.Close(); return ds; } 我试了2个office 版本,问题依旧!!急死我啊!!! 跟我的程序一样,我的正改呢应该先将Excel文件上传到服务器上再导入 我把TRY去掉,重新部署后再导入EXCEL文件,提示:没有可用的错误消息,结果代码: E_FAIL(0x80004005)。 关注,以前在学校里面搞人员数据导入的时候也碰到过这种问题(后来把整个系统ghost回来搞,一直没搞定)原因可能不是程序方面的 应该是office的版本问题,我也遇过,换了个版本就好了 嗯,同意,应该是Office版本的事 怎看代码都很正常...服务器的系统是什么?Win2000 OR Win2003 服务器的系统是Win2003换XP问题一样 就是office版本的问题,我曾经预见过和你一样的问题! 考虑下office的版本问题再考虑下权限问题如果在不行 配置看下 是不是没有权限?添加User 或者 asp.net 用户试一试。 office版本的问题可能性较大 楼主别慌,遇到这种问题从两台服务器的环境差别上找找原因,文件权限,组件的版本,或者.Net的运行时安全级别都有可能出现这种情况,捕获一下错误异常信息再分析原因 com7ecity(经营之道 http://info.7ecity.com/html/G/)一个问题就恶梦?有点夸张哦主要是找不到原因,找到原因就好说 检查FileUpload2.PostedFile.FileName 中有没有空格。如果有的话,用''括起来。把Extended Properties=Excel 8.0中的Excel 8.0改为Excel 5.0或者Excel 10.0试试看。 另外一个就是权限问题。你是通过FileUpload2.PostedFile.FileName来连接的,有可能IIS启动用户没有这个权限,建议先把文件保存到网站所在的某个临时目录下,然后再连接它。 我也觉得是权限问题,你导入的那个文件夹所在盘必须是ntfs格式,然后在安全选项中添加用户权限,加入aspnet账户应该可以 Excel 8.0啊,用这么高的版本啊,我的建议,不管有没有问题,开发最好用更底版本,这样就不会出现了 你把你在自己机器上开发用到的execl的dll文件放到你的程序里,随你的程序一起发布,你引用你程序里的excel的dll文件,因该就不会出现版本问题了 或者你导入excel时采用写文件的方法,就是把excel当作一般文本文件来写,只是文件的后缀名改为excel的后缀名也不会出现版本问题. 我遇到过这问题,和office版本没有关系,[Sheet1$]是系统自动生成的表,你远程上传文件,让系统在重新生成,你用上传的文件导入就可以了. 权限的问题吧,你是FAT32的而服务器是nTFS的 要先上传到服务器才能导入!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!你取的只是客户端的EXCEL文件,要先把EXCEL文件上传到服务器,然后再导入!!!!!!!!!!!!仔细想一想 Response.Buffer=true; Response.Charset="GB2312";//BIG5 Response.AddHeader("content-disposition","attachment;filename=FileName.xls"); Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");//BIG5 Response.ContentType="application/vnd.xls"; this.EnableViewState=false; System.Globalization.CultureInfo myCItrad=new System.Globalization.CultureInfo("ZH-CN",true); System.IO.StringWriter stringWrite=new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite=new HtmlTextWriter(stringWrite); System.IO.StringWriter oStringWriter=new System.IO.StringWriter(myCItrad); System.Web.UI.HtmlTextWriter oHtmlTextWriter=new HtmlTextWriter(oStringWriter); Response.Write(oStringWriter.ToString());这是我的你看可不可以以前我也遇到过这种情况,是我的office的问题,重装后就没事了 using System;using System.Collections.Generic;using System.Text;using System.Windows.Forms ;using System.IO;namespace OutputToExecl{ public class ExportXLS { public ExportXLS() { } public static void ExportDataGridViewToExcel(DataGridView dataGridview1) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Execl files (*.xls)|*.xls"; saveFileDialog.FilterIndex = 0; saveFileDialog.RestoreDirectory = true; saveFileDialog.CreatePrompt = true; saveFileDialog.Title = "导出Excel文件到"; saveFileDialog.ShowDialog(); Stream myStream; myStream = saveFileDialog.OpenFile(); StreamWriter sw = new StreamWriter(myStream, System.Text.Encoding.GetEncoding("gb2312")); string str = ""; try { //写标题 for (int i = 0; i < dataGridview1.ColumnCount; i++) { if (i > 0) { str += "\t"; } str += dataGridview1.Columns[i].HeaderText; } sw.WriteLine(str); //写内容 for (int j = 0; j < dataGridview1.Rows.Count; j++) { string tempStr = ""; for (int k = 0; k < dataGridview1.Columns.Count; k++) { if (k > 0) { tempStr += "\t"; } tempStr += dataGridview1.Rows[j].Cells[k].Value.ToString(); } sw.WriteLine(tempStr); } sw.Close(); myStream.Close(); } catch (Exception e) { MessageBox.Show(e.ToString()); } finally { sw.Close(); myStream.Close(); } } }}PS:VS2005下测试通过,不需要考虑Excel版本问题楼主,可以结贴了:) 三层下的注册界面求指导 打开VS后->website->asp.net configuration就出现这样的错误提示,在应用程序配置中未找到连接名LocalSqlServer或者连接字符串为空 自动填写网页(高分请教) 求今年规划摸版 用参数传递怎么模糊查询mysql中,不能使用存储过程 如何显示存储在数据库中的图片 asp.net网站莫名其妙的出现这样的问题...昨天还好用 一个控件问题? 在Page_Load里面可以知道是那个控件触发事件而提交页面的吗? ASP.NET如何用实现饼图? 请问我在asp.net 如何调用存储过程的返回值?? 初级问题--字符为空
protected void Button4_Click(object sender, EventArgs e)
{
try
{
GridView1.DataSource = createdatasource();
GridView1.DataBind(); }
catch { Response.Write("");
}
}
private DataSet createdatasource()
{
ViewState["excelfile"] = FileUpload2.PostedFile.FileName.ToString();
string strconn;
strconn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + FileUpload2.PostedFile.FileName + ";" + "Extended Properties=Excel 8.0;"; OleDbConnection conn = new OleDbConnection(strconn);
OleDbDataAdapter comm = new OleDbDataAdapter("select * from [Sheet1$]", strconn); DataSet ds = new DataSet();
conn.Open();
comm.Fill(ds);
conn.Close();
return ds;
}
应该先将Excel文件上传到服务器上再导入
没有可用的错误消息,结果代码: E_FAIL(0x80004005)。
原因可能不是程序方面的
再考虑下权限问题
如果在不行 配置看下
一个问题就恶梦?有点夸张哦主要是找不到原因,找到原因就好说
你用上传的文件导入就可以了.
你取的只是客户端的EXCEL文件,要先把EXCEL文件上传到服务器,然后再导入!!!!!!!!!!!!仔细想一想
Response.Charset="GB2312";//BIG5
Response.AddHeader("content-disposition","attachment;filename=FileName.xls");
Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");//BIG5
Response.ContentType="application/vnd.xls";
this.EnableViewState=false;
System.Globalization.CultureInfo myCItrad=new System.Globalization.CultureInfo("ZH-CN",true);
System.IO.StringWriter stringWrite=new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite=new HtmlTextWriter(stringWrite);
System.IO.StringWriter oStringWriter=new System.IO.StringWriter(myCItrad);
System.Web.UI.HtmlTextWriter oHtmlTextWriter=new HtmlTextWriter(oStringWriter);
Response.Write(oStringWriter.ToString());
这是我的你看可不可以以前我也遇到过这种情况,是我的office的问题,重装后就没事了
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms ;
using System.IO;namespace OutputToExecl
{
public class ExportXLS
{
public ExportXLS()
{
}
public static void ExportDataGridViewToExcel(DataGridView dataGridview1)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "Execl files (*.xls)|*.xls";
saveFileDialog.FilterIndex = 0;
saveFileDialog.RestoreDirectory = true;
saveFileDialog.CreatePrompt = true;
saveFileDialog.Title = "导出Excel文件到"; saveFileDialog.ShowDialog(); Stream myStream;
myStream = saveFileDialog.OpenFile();
StreamWriter sw = new StreamWriter(myStream, System.Text.Encoding.GetEncoding("gb2312"));
string str = "";
try
{
//写标题
for (int i = 0; i < dataGridview1.ColumnCount; i++)
{
if (i > 0)
{
str += "\t";
}
str += dataGridview1.Columns[i].HeaderText;
} sw.WriteLine(str);
//写内容
for (int j = 0; j < dataGridview1.Rows.Count; j++)
{
string tempStr = "";
for (int k = 0; k < dataGridview1.Columns.Count; k++)
{
if (k > 0)
{
tempStr += "\t";
}
tempStr += dataGridview1.Rows[j].Cells[k].Value.ToString();
}
sw.WriteLine(tempStr);
}
sw.Close();
myStream.Close();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
finally
{
sw.Close();
myStream.Close();
}
} }
}
PS:VS2005下测试通过,不需要考虑Excel版本问题
楼主,可以结贴了:)