将CSV文件转换成XLS文件,要保持格式不变,怎么转?谢谢

解决方案 »

  1.   

    System.Web.HttpPostedFile file = Request.Files["FILE"];
    string path = System.Web.HttpContext.Current.Server.MapPath(".")+"\\"+System.Guid.NewGuid()+".csv";
    file.SaveAs(path);
    string oleConnString =  "Provider=Microsoft.Jet.OLEDB.4.0 Data Source="+path+" Extended Properties=Excel 8.0;";
    PostDataSet.Tables.Add(this.Tables[TableName].Clone());
    using( System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(oleConnString))
    {
    string sql ="select * from [tmp$]";
    System.Data.OleDb.OleDbCommand comm = new System.Data.OleDb.OleDbCommand(sql,conn);
    conn.Open();
    System.Data.OleDb.OleDbDataReader dr =comm.ExecuteReader();
    }
    这样出错了!!!
      

  2.   

    string path1 = @"c:\123.CSV";
    string path2 = @"c:\123.xsl";System.IO.File.Move(path1,path2);
    System.IO.File.Delete(path1);
      

  3.   

    string path = Server.MapPath("a.csv").ToLower();
    string path2 = path.Replace(".csv",".xls");if (File.Exists(path2)) 
    File.Delete(path2);
    File.Move(path, path2);
    string sql ="select * from [sheet1$]";