你看下这个网站希望对你有用如果你还有什么不明白可以写信给我:http://www.cnblogs.com/northeastTycoon
这个代码需要你下载:Npoi动态库。代码我都是经过测试的没有问题。对了在官网上就可以下载。

解决方案 »

  1.   

    这个主要是看,你class 的结构..
    一个for循环就可以导入到EXcel 了....
      

  2.   

    http://blog.csdn.net/happy09li/article/details/7431967
      

  3.   

    怎么不给分啊。把list<class>转为datatable就可以了。
      

  4.   

     各位前辈。。我这样导入数据,就会报错,可是我的逻辑没有错啊...请各位帮忙...  错误:“未处理的COMException”
    异常来自 HRESULT:ox800a03ec
        private static void ExportToExcel(string path,List<ExcelClass> listEclass)
            {
                object Nothing = System.Reflection.Missing.Value; //占位符 
                Excel.Application app = null;
                Excel.Workbook MyBook = null;
                Excel.Worksheet mySheet = null;            app = new Excel.Application();            MyBook = app.Workbooks.Open(path, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing);
                mySheet = (Worksheet)MyBook.Worksheets[1];            for (int i = 0; i < listEclass.Count;i++)
                {
                    mySheet.Cells[i, 1] = listEclass[i].AppID.ToString().Trim();
                    mySheet.Cells[i, 2] = listEclass[i].AccountName.ToString().Trim();
                    mySheet.Cells[i, 3] = listEclass[i].EmailDomain.ToString().Trim();
                }
                MyBook.Save();
                MyBook.Saved = true;            if(mySheet!=null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(mySheet);
                    mySheet=null;
                }
                if(MyBook!=null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(MyBook);
                    MyBook = null;
                }
                //关闭对象
                app.Workbooks.Close();
                app.Quit();
                if(app!=null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
                    app = null;
                }
                GC.Collect();
            }
      

  5.   

    ==============================
    检查你的 path参数。
    注意  \ 必须转义为\\  或是前面加@   
                        //注意必须是\\ 或是 @\不然会提示错误
                        sw.SaveAs("c:\a.xls");【错误!!】
                         sw.SaveAs(@"c:\a.xls“)【正确】