求助,如何,winform c# 读取EXCEL模板 然后再把数据写入EXCEL希望提供详细的步骤,包含各种引用等。感激不尽。

解决方案 »

  1.   

    我觉得应当可以读取xml模板,然后写入excel。
      

  2.   

    DataSet ds=new DataSet(); 
                OleDbConnection oleDbConnection = null; 
                try 
                { 
                    oleDbConnection =new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName + ";Extended Properties=\"Excel 8.0;IMEX=1;\""); 
                    OleDbCommand selectCommand = new OleDbCommand(); 
                    selectCommand.Connection = oleDbConnection; 
                    selectCommand.CommandText = "select * from [" + sheetName +"]"; 
                  selectCommand.CommandType = CommandType.Text; 
                    OleDbDataAdapter adapter = new OleDbDataAdapter(selectCommand); 
                    ds= new DataSet(); 
                  adapter.Fill(ds); 
                } 
                catch (Exception exception) 
                { 
                    oleDbConnection.Close(); 
                } 
              finally 
                {                
                    oleDbConnection.Close(); 
                } 
    赋值给二位数组,或打开excel模板实现赋值