日期:2014-05-18 浏览次数:20518 次
StreamWriter sw = new StreamWriter(@"c:\a.xls"); sw.WriteLine("testText1/ttestText2");
StreamWriter sw = new StreamWriter(@"c:\a.xls"); sw.WriteLine("testText1/ttestText2"); sw.Flush(); sw.close();
StreamWriter sw = File.AppendText(@"c:\a.xls); sw.WriterLine("testText1/ttestText2"); sw.Flush(); sw.close();(
OleDbConnection objConn = null; DataSet data = new DataSet(); try { string strConn = @"Provider=Microsoft.ACE.OleDb.12.0;Data Source=c:"待发工资.xlsx;Extended Properties='Excel 12.0;HDR=YES'";//IMEX=1为只读 //"Provider=Microsoft.Jet.OleDb.4.0;data source=c:"待发工资.xlsx;Extended Properties=""Excel 12.0;HDR=YES;IMEX=1"""; objConn = new OleDbConnection(strConn); objConn.Open(); //System .Data . DataTable schemaTable = objConn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, null); //int SheetIndex = 0; //string tableName = schemaTable.Rows[SheetIndex][2].ToString().Trim(); string strSql = "Select * From [Sheet1$]"; OleDbCommand objCmd = new OleDbCommand(strSql, objConn); OleDbDataAdapter sqlada = new OleDbDataAdapter(); sqlada.SelectCommand = objCmd; sqlada.Fill(data); string str = ""; for (int i = 0; i < data.Tables[0].Rows[0].ItemArray.Length; i++) { str += data.Tables[0].Rows[0].ItemArray[i].ToString() + "."; } MessageBox.Show(str); objConn.Close(); } catch (Exception ex) { objConn.Close(); Console.WriteLine(ex.Message.ToString()); }
------解决方案--------------------
StreamWriter来用写文件的方式生成excel其实就是在写csv文件,而只是把文件名存成了xls罢了
一个csv文件能有多个sheet吗?
不能
所以你的问题估计也是不能