我是菜鸟,各位能不能给出简单例子代码?
解决方案 »
- 整形转换成十六进制
- WPF中page调用所在window的事件
- Excel2003英文版的Com和Excel2003中文版Com使用上有什么不同吗?
- 请教前辈:使用C#调用API函数
- 如何把一条条数据增加到DataGrid中,然后一起存数据库?我用的是Ajax技术,不使用ViewState保存table
- 给客户的项目做完后,软件的版权和著作权属于谁的?
- ADSL拨号的密码忘记了!
- c#与xml的图片等文件存储问题?
- 在Asp.net 用C#中写一个方法里面用到SqlParameter,要用到一个时间格式的参数,那么这个参数要怎么写,
- 怎么在调试的时候看引用类型的地址呀?
- 主程序循环中除2是什么意思
- 获取Textbox中的字符但报错?(书上原例)谢谢!
或者菜单,项目,添加引用。
com选项卡中
工程名称,右击,添加引用,COM,找到 Microsoft Excel 9.0 Object Library,选择,确定
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文件
还有,那个owc控件又是什么呢?