System.Runtime.InteropServices.COMException (0x800A03EC)

永动bug制造机 2012-01-19 05:44:00
System.Runtime.InteropServices.COMException (0x800A03EC): 异常来自 HRESULT:0x800A03EC 在 Microsoft.Office.Interop.Excel.WorkbookClass.SaveAs(Object Filename, Object FileFormat, Object Password, Object WriteResPassword, Object ReadOnlyRecommended, Object CreateBackup, XlSaveAsAccessMode AccessMode, Object ConflictResolution, Object AddToMru, Object TextCodepage, Object TextVisualLayout, Object Local) 在 PageHelper.Export_Excel1(DataTable source, String savePath, String fileName, String title)
...全文
821 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
iyori 2012-01-29
  • 打赏
  • 举报
回复
包括 调用com接口的权限 和 保存文件的权限
iyori 2012-01-29
  • 打赏
  • 举报
回复
主要是看看有没有权限
段传涛 2012-01-29
  • 打赏
  • 举报
回复
iis 6.0 --右键--管理(大概)--权限--设置下。
永动bug制造机 2012-01-20
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 net_lover 的回复:]
1确认所指定的文件夹已存在。
2确认文件所在的文件夹不是只读的。
3确认给出的文件名不包含下列字符: < > ? [ ] : | 或 * 。
4确认文件/路径名长度不超过 218 个字符。
5,确保office版本相同
6,确保服务器有这个文件夹存在C:\Windows\System32\config\systemprofile
7,参考http://hi.baidu.com/iks……
[/Quote]
用的是同一台电脑发布的 发布后就出现以上问题。
不存在你所说的问题哎
孟子E章 2012-01-19
  • 打赏
  • 举报
回复
1确认所指定的文件夹已存在。
2确认文件所在的文件夹不是只读的。
3确认给出的文件名不包含下列字符: < > ? [ ] : | 或 * 。
4确认文件/路径名长度不超过 218 个字符。
5,确保office版本相同
6,确保服务器有这个文件夹存在C:\Windows\System32\config\systemprofile
7,参考http://hi.baidu.com/ikswhy/blog/item/a8f9e612fef8eb62cb80c472.html
永动bug制造机 2012-01-19
  • 打赏
  • 举报
回复

public static string Export_Excel1(System.Data.DataTable source, string savePath, string fileName, string title)
{
Microsoft.Office.Interop.Excel.Application myExcel = new Microsoft.Office.Interop.Excel.Application();

if (myExcel == null)
{
return "无法打开Excel,请检查Excel是否可用或者是否安装好Excel!";
}

int rowCount = source.Rows.Count;//行数
int columnCount = source.Columns.Count;//列数

//保存文化环境
System.Globalization.CultureInfo currentCI = System.Threading.Thread.CurrentThread.CurrentCulture;
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

Microsoft.Office.Interop.Excel.Workbook workbook = myExcel.Workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Sheets.get_Item(1);
worksheet.Name = title;//一个sheet的名称

//myExcel.Visible = true;//打开导出的Excel文件

worksheet.Cells[1, 1] = title;//表标题

//填充列标题
for (int i = 0; i < columnCount; i++)
{
worksheet.Cells[2, i + 1] = source.Columns[i].ColumnName;
}

object[,] objData = new object[rowCount, columnCount];

//填充内容到对象数组
for (int r = 0; r < rowCount; r++)
{
for (int col = 0; col < columnCount; col++)
{
objData[r, col] = source.Rows[r][col].ToString();
}
}
//将对象数组的值赋给Excel对象
Microsoft.Office.Interop.Excel.Range range = worksheet.get_Range(worksheet.Cells[3, 1], worksheet.Cells[rowCount + 2, columnCount]);
range.NumberFormat = "@";//设置数字文本格式
range.Value2 = objData;

//设置格式
//worksheet.get_Range(worksheet.Cells[1, 1], worksheet.Cells[1, columnCount]).MergeCells = true;//合并单元格
//worksheet.get_Range(worksheet.Cells[1, 1], worksheet.Cells[1, columnCount]).HorizontalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter;//居中对齐
//worksheet.get_Range(worksheet.Cells[1, 1], worksheet.Cells[1, columnCount]).RowHeight = 38;
//worksheet.get_Range(worksheet.Cells[1, 1], worksheet.Cells[1, columnCount]).Font.Bold = true;
//worksheet.get_Range(worksheet.Cells[1, 1], worksheet.Cells[1, columnCount]).Font.Name = "黑体";
//worksheet.get_Range(worksheet.Cells[1, 1], worksheet.Cells[1, columnCount]).Font.Size = 16;
//worksheet.get_Range(worksheet.Cells[2, 1], worksheet.Cells[rowCount + 2, columnCount]).Borders.LineStyle = 1;//设置边框
//worksheet.get_Range(worksheet.Cells[2, 1], worksheet.Cells[rowCount, columnCount]).Columns.AutoFit();//设置单元格宽度为自适应

try
{
myExcel.Application.Workbooks[1].SaveAs(savePath + fileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
return "恭喜,数据已经成功导出为Excel文件!";
}
catch (Exception ex)
{
return ex.ToString();
}
finally
{
System.Threading.Thread.CurrentThread.CurrentCulture = currentCI;
source.Dispose();
myExcel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(myExcel);
System.Runtime.InteropServices.Marshal.ReleaseComObject(worksheet);
System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook);
GC.Collect();
}
}
lanwd 2012-01-19
  • 打赏
  • 举报
回复
把源码粘上去,让大家看看。
永动bug制造机 2012-01-19
  • 打赏
  • 举报
回复
saveas方法在本地运行没有问题
在服务器(iis6.0)运行有如上错误。

62,050

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧