我导出excel的时候总是出错,编写的语言是C#(.net2005)
提示的报错如下:
未能加载文件或程序集"CarlosAg.ExcelXMLWriter, Version=1.0.0.6,Culture=neutral,PublicKeyToken=eac822d9c4196ba1"
或他的某一个依赖项,系统找不到指定的文件。不知道我这个是引用缺少了一些还是我的代码本身就不对,
还有就是于CarlosAg.ExcelXMLWriter相关的引用都有哪些?我的引用是:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ZedGraph;using System.Collections;
using System.Runtime.InteropServices;
using System.IO;我的关于导出excel那段的代码是:
        private void button1_Click(object sender, EventArgs e)
        {
            this.boundGridControl1.ExportToExcel("temp.xls", true, true, true);
            System.Diagnostics.Process.Start("excel.exe");
}
这段代码执行的时候报错就是上边的那段,如果是到出道txt文档就不会有问题
        private void button1_Click(object sender, EventArgs e)
        {
            this.boundGridControl1.ExportToTabDelimitedText("temp.txt", true, true, true);
            System.Diagnostics.Process.Start("notepad.exe", "temp.txt");   //用记事本
        }

解决方案 »

  1.   

    CarlosAg.ExcelXMLWriter这个是你自己写的或是其他人写的一个dll吗?如果是,这个dll里面操作excel是不是用的com方式来操作的,如果是你引用这个dll的项目里面还应该引用相应的Microsoft.Office.Excel9.0或者Microsoft.Office.Excel12.0
      

  2.   

    http://blog.csdn.net/yicel/archive/2007/04/16/1566577.aspx
    using CarlosAg.ExcelXmlWriter;
    CarlosAg.ExcelXmlWriter是第三方dll控件,可以到http://www.carlosag.net/Tools/ExcelXmlWriter/Default.aspx下载需要在工程里添加引用,并在代码加using CarlosAg.ExcelXmlWriter;
      

  3.   

    boundGridControl1应该是个第三方的组件吧你确定对这个组件已添加引用?
      

  4.   

    CarlosAg.ExcelXmlWriter应该是个第三方的组件吧 你确定对这个组件已添加引用?
      

  5.   

    你看看你引用那里有没有CarlosAg.ExcelXMLWriter?
      

  6.   

    在项目引用中添加引用的第三方组件CarlosAg.dll; 
    添加引用 using CarlosAg.ExcelXmlWriter; 
      

  7.   

    这个是一个别人写的DLL,请问一下,Microsoft.Office.Excel9.0应该在哪里加入阿?
      

  8.   

    在做BS结构时候导出EXCEL最好不要同EXCEL.DLL 很费内存的,我用过。后来改进了一下,直接从DataTable导出Excel,速度也不错,而且导出的格式可以自己控制,下面是我写的导出代码,LZ可以看看:/// <summary> 
        /// 将datatable中的数据导出到指定的excel文件中 
        /// </summary> 
        /// <param name="page">web页面对象</param> 
        /// <param name="tab">包含被导出数据的datatable对象</param> 
        /// <param name="filename">excel文件的名称</param> 
        public static void Export(System.Web.UI.Page page, DataTable tab, string filename)
        {
            System.Web.HttpResponse httpresponse = page.Response;
            System.Web.UI.WebControls.DataGrid datagrid = new DataGrid();
            datagrid.DataSource = tab.DefaultView;
            datagrid.AllowPaging = false;
            datagrid.HeaderStyle.BackColor = Color.White;
            datagrid.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
            datagrid.HeaderStyle.Font.Bold = true;
            datagrid.DataBind();
            httpresponse.AppendHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename,System.Text.Encoding.UTF8)); //filename="*.xls"; 
            httpresponse.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
            httpresponse.ContentType = "application/ms-excel";
            StringWriter tw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(tw);
            datagrid.RenderControl(hw);        string filepath = page.Server.MapPath("..") + "\\files\\" + filename;
            StreamWriter sw = System.IO.File.CreateText(filepath);
            sw.Write(tw.ToString());
            sw.Close();        DownFile(httpresponse, filename, filepath);        httpresponse.End();
        }
        private static bool DownFile(System.Web.HttpResponse response, string filename, string fullpath)
        {
            try
            {
                response.ContentType = "application/octet-stream";            response.AppendHeader("content-disposition", "attachment;filename=" +
                HttpUtility.UrlEncode(filename, Encoding.UTF8) + ";charset=gb2312");
                System.IO.FileStream fs = System.IO.File.OpenRead(fullpath);
                long flen = fs.Length;
                int size = 102400;//每100k同时下载数据 
                byte[] readdata = new byte[size];//指定缓冲区的大小 
                if (size > flen) size = Convert.ToInt32(flen);
                long fpos = 0;
                bool isend = false;
                while (!isend)
                {
                    if ((fpos + size) > flen)
                    {
                        size = Convert.ToInt32(flen - fpos);
                        readdata = new byte[size];
                        isend = true;
                    }
                    fs.Read(readdata, 0, size);//读入一个压缩块 
                    response.BinaryWrite(readdata);
                    fpos += size;
                }
                fs.Close();
                System.IO.File.Delete(fullpath);
                return true;
            }
            catch
            {
                return false;
            }
        }
      

  9.   


    你要用TlbImp.exe 转换工具 把Ocx 把它转换成dll
      

  10.   

    项目引用里面Com里面找Microsoft.Office.Excel...,添加进来后,在它的属性点复制到本地,编译下,在Debug目录里面找到它生成出来的相应的2-3个dll
      

  11.   

    项目引用里面Com里面找Microsoft.Office.Excel...,添加进来后,在它的属性点复制到本地,编译下,在Debug目录里面找到它生成出来的相应的2-3个dll
      

  12.   

    C# DataGridView导出成Excel
            目前知道有2种方法:第一种:用流保存成xls文件.  这种方法比较好,不用引用Excel组件.   下面是本人使用具体例子,可以参考 using System.IO;                /// <summary>        /// 另存新档按钮        /// </summary>        private void SaveAs()  //另存新档按钮   导出成Excel
      

  13.   

    http://yueqing.blog.163.com/blog/static/3208259200827101420898/