public void SaveDetailToExcel(DataSet ds, string filePath)
        {
            try
            {
                GC.Collect();
                Application app;
                Worksheet wSheet = null;
                Workbook wBook;                app = new ApplicationClass();                app.Visible = false;
                wBook = app.Workbooks.Add(true);                int t = ds.Tables.Count;                for (int sheetIndex = 0; sheetIndex < t; sheetIndex++)
                {
                    wSheet = (Worksheet)wBook.Worksheets.Add(Type.Missing, Type.Missing, 1, Type.Missing);
                    wSheet.Name = ds.Tables[sheetIndex].TableName;                    //赋值
                    if (ds.Tables[sheetIndex].Rows.Count > 0)
                    {
                        int row = 0;
                        row = ds.Tables[sheetIndex].Rows.Count;
                        int col = ds.Tables[sheetIndex].Columns.Count;                        for (int i = 3; i <= row + 2; i++)
                        {
                            for (int j = 2; j < col; j++)
                            {
                                string str = ds.Tables[sheetIndex].Rows[i - 3][j].ToString();
                                wSheet.Cells[i + 1, j - 1] = str;
                            }
                        }
                    }                    wSheet.Cells[1, 1] = "表";                    //设置禁止弹出保存和覆盖的询问提示框
                    app.DisplayAlerts = false;
                    app.AlertBeforeOverwriting = false;
                }                wBook.Save();
                app.Save(filePath);                wBook.Close(false, null, null);
                app.Quit();                System.Runtime.InteropServices.Marshal.ReleaseComObject(wBook);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(wSheet);                wBook = null;
                app = null;
                wSheet = null;
                GC.Collect();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
            }
        }我用这个把数据库里面类容保存了一个execl在本地,为什么发给别人,都打开不了,一打开就提示错误,只能在我本地打开

解决方案 »

  1.   

    我就是实现点一个按钮,把数据保存在execl里面,但保存的东西,别人下下来了打开不了啊,老是提示错误,是为什么啊?只有本机才能打开看到
      

  2.   

    提示:无法找到"Sheet1.xlsx".请检查文件名的拼写,并检查文件位置是否正确.
    如果您正试图从"文件"菜单上最近使用的文档列表中打开文件,请确认文件未被重命名,移动或删除.我机子上面装的是office2007,别人好像都是2003的,但按上面生成的文件是.XLS的execl,应该2003都打的开的吧
      

  3.   

    我机器上面装的是2007,要怎么才能生成2003版本的execl?
      

  4.   

    好像有个什么类似插件的东西
    你装个最早的.NETOFFICE支持吧..
      

  5.   

    卸载吧。。要不会别人是无法打开的,装2003,我的项目里也用到了excel的生成和下载,我都把2007给卸了