日期:2014-05-20  浏览次数:20650 次

DataSet向excl导出数据,简单问题
string   path;
                        OpenFileDialog   ofd   =   new   OpenFileDialog();

                        if   (ofd.ShowDialog()   !=   DialogResult.OK)
                        {
                                MessageBox.Show( "未选择文件 ");
                                return;
                        }
                       
                        path=   ofd.FileName;//得到路径和文件名
                       
                        string   strConn   =   "Provider=Microsoft.Jet.OLEDB.4.0; "   +   "Data   Source= "+path+ ";     Extended   Properties=Excel   8.0; ";
                        OleDbConnection   conn   =   new   OleDbConnection(strConn);
                        conn.Open();
                        string   tableName= " ";
                        DataTable   dt   =   conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,   null);
                        for   (int   i   =   0;   i   <   dt.Rows.Count;   i++)
                        {
                                tableName   +=   dt.Rows[i][2].ToString().Trim();
                        }

                        string   strExcel   =   " ";
                        OleDbDataAdapter   myCommand   =   null;
                        strExcel   =   "select   *   from   [ "+tableName+ "]   ";
                        myCommand   =   new   OleDbDataAdapter(strExcel,   strConn);
                        DataSet   dataSet1   =   new   DataSet();
                        myCommand.Fill(dataSet1,   "[ "+tableName+ "] ");  
                        //以上代码经测试,通过


                        //以下代码未通过,我想实现最简单的将dataset的修改内容保存入excel文件