你用到的dll是低版本的,换成高版本,支持2007的

解决方案 »

  1.   

    导excel直接用文件流,每列用英文逗号隔开,保存为csv格式的文件就可以了……这种方法最简单
      

  2.   

    然后,我换成了 WIN 7 + OFFICE2003 也一样,不知道是什么问题
      

  3.   


       public void DataGridViewtoExcel(DataGridView dataGridView1)
            {
                //导出到execl
                try
                {
                    if (dataGridView1.Rows.Count == 0)
                    {                  
                        toolStripStatusLabel1.Text = "当前时间点没有数据,请重新选择时间范围!";
                    }
                    else
                    {                    Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
                        excel.Visible = false;
                        excel.Application.Workbooks.Add(true);
                      
                        for (int i = 0; i < dataGridView1.Columns.Count; i++)
                        {
                            excel.Cells[1, i + 1] = dataGridView1.Columns[i].HeaderText;
                        }
                        for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
                        {
                            for (int j = 0; j < dataGridView1.Columns.Count; j++)
                            {
                                if (dataGridView1[j, i].ValueType == typeof(string))
                                {
                                    excel.Cells[i + 2, j + 1] = "'" + dataGridView1[j, i].Value.ToString();
                                }
                                else
                                {
                                    excel.Cells[i + 2, j + 1] = dataGridView1[j, i].Value.ToString();
                                }
                            }
                        }                    Worksheet worksheet = (Worksheet)excel.ActiveSheet;
                        worksheet.SaveAs(System.Windows.Forms.Application.StartupPath + "\\excel\\" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);                  
                        excel.DisplayAlerts = false;
                        excel.AlertBeforeOverwriting = false;                    
                        excel.Quit();
                        excel = null;
                    }
                }
                catch (Exception ex)
                {                MessageBox.Show(ex.Message, "错误提示");            }        }
      

  4.   

    office2007的EXCEL是10版本,XLSX格式
    与原来的XLS不兼容要重新引用 新的EXCEL的类
    代码结构差不多
      

  5.   

    http://bbs.csdn.net/topics/390830774
    楼主可以看看这个 应该会满足你
      

  6.   


    dll版本已经不兼容了。用6楼的方法不是挺好吗。。
      

  7.   

    把多个Excel文件汇总到一个Excel文件中
      private void btn_Gather_Click(object sender, EventArgs e)
            {
                object missing = System.Reflection.Missing.Value;//定义object缺省值
                string[] P_str_Names = txt_MultiExcel.Text.Split(',');//存储所有选择的Excel文件名
                string P_str_Name = "";//存储遍历到的Excel文件名
                List<string> P_list_SheetNames = new List<string>();//实例化泛型集合对象,用来存储工作表名称
                Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();//实例化Excel对象
                //打开指定的Excel文件
                Microsoft.Office.Interop.Excel.Workbook workbook = excel.Application.Workbooks.Open(txt_Excel.Text, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
                Microsoft.Office.Interop.Excel.Worksheet newWorksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Worksheets.Add(missing, missing, missing, missing);//创建新工作表
                for (int i = 0; i < P_str_Names.Length - 1; i++)//遍历所有选择的Excel文件名
                {
                    P_str_Name = P_str_Names[i];//记录遍历到的Excel文件名
                    //指定要复制的工作簿
                    Microsoft.Office.Interop.Excel.Workbook Tempworkbook = excel.Application.Workbooks.Open(P_str_Name, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
                    P_list_SheetNames = GetSheetName(P_str_Name);//获取Excel文件中的所有工作表名
                    for (int j = 0; j < P_list_SheetNames.Count; j++)//遍历所有工作表
                    {
                        //指定要复制的工作表
                        Microsoft.Office.Interop.Excel.Worksheet TempWorksheet = (Microsoft.Office.Interop.Excel.Worksheet)Tempworkbook.Sheets[P_list_SheetNames[j]];//创建新工作表
                        TempWorksheet.Copy(missing, newWorksheet);//将工作表内容复制到目标工作表中
                    }//CodeGo.net/
                    Tempworkbook.Close(false, missing, missing);//关闭临时工作簿
                }
                workbook.Save();//保存目标工作簿
                workbook.Close(false, missing, missing);//关闭目标工作簿
                MessageBox.Show("已经将所有选择的Excel工作表汇总到了一个Excel工作表中!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                CloseProcess("EXCEL");//关闭所有Excel进程
            }
      

  8.   

    用EXCEL本身的DLL问题挺多,需要考虑2003,2007,2010版本不同引用的DLL也不同
    WIN764位和32位也不同,32位DLL在64位下无法运行
    建议还是改成NPOI导入导出吧
      

  9.   

    如果不要求格式的话,可以参见,http://blog.csdn.net/duanzi_peng/article/details/17414629
      

  10.   

    用NPOI吧,
    http://blog.csdn.net/happy09li/article/details/7431967