我是菜鸟,各位能不能给出简单例子代码?

解决方案 »

  1.   

    引用 Excel 组件,然后 使用 Excel 对象创建
      

  2.   

    解决方案资源管理器中,右键,添加引用。
    或者菜单,项目,添加引用。
    com选项卡中
      

  3.   

    lz 不是不想帮你了。
    工程名称,右击,添加引用,COM,找到 Microsoft Excel 9.0 Object Library,选择,确定
      

  4.   

    例子: 
            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文件
      

  5.   

    谢谢各位帮忙
    还有,那个owc控件又是什么呢?