c#中怎么生成excel

thefifthseal 2006-11-27 02:22:30
我是菜鸟,各位能不能给出简单例子代码?
...全文
176 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
thefifthseal 2006-11-27
  • 打赏
  • 举报
回复
谢谢各位帮忙
还有,那个owc控件又是什么呢?
cpitandy 2006-11-27
  • 打赏
  • 举报
回复
UP
DeanMonica 2006-11-27
  • 打赏
  • 举报
回复
例子:
Excel.Application xlsApp=null;
Excel.Workbook xlsWorkBook=null;
Excel.Worksheet xlsSheet=null;
try
{
// xlsApp = new Excel.ApplicationClass();
xlsApp = new Excel.Application();
xlsApp.Visible = false;
xlsWorkBook = new Excel.Workbook();
xlsSheet = new Excel.Worksheet();
xlsSheet.Cells[1, 1] = "aaa";
xlsWorkBook.SaveCopyAs("tt.xls");
xlsSheet = null;
xlsWorkBook = null;
xlsApp.Quit();
xlsApp = null;
}
catch (Exception erinfo)

{ throw erinfo;

}

finally

{
if (xlsSheet != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlsSheet);
xlsSheet = null;
}
if (xlsWorkBook != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlsWorkBook);
xlsWorkBook = null;
xlsApp.Workbooks.Close();
}
if (xlsApp != null)
{

xlsApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlsApp);
xlsApp = null;
}
GC.Collect();
}

也可用owc控件来实现,但owc生成的不是真正的excel文件
cangwu_lee 2006-11-27
  • 打赏
  • 举报
回复
lz 不是不想帮你了。
工程名称,右击,添加引用,COM,找到 Microsoft Excel 9.0 Object Library,选择,确定
mfjustlove 2006-11-27
  • 打赏
  • 举报
回复
解决方案资源管理器中,右键,添加引用。
或者菜单,项目,添加引用。
com选项卡中
thefifthseal 2006-11-27
  • 打赏
  • 举报
回复
怎么引用啊?
cangwu_lee 2006-11-27
  • 打赏
  • 举报
回复
引用 Excel 组件,然后 使用 Excel 对象创建

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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