FileStream file = RenderDataTableToExcel(table) as FileStream;
RenderDataTableToExcel()是个方法,我现在要把读到的流数据写入到一个
excel文件里,该怎么写呢!!???急用!
类似与操作数据库表:
连接excel文件
执行数据的添加
关闭excel连接
具体实现:
string connectionStr = string.Format(" Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = {0};" +
" Extended Properties= Excel 8.0", filePath);
oledbConnection = new OleDbConnection(connectionStr);
string sqlStr = "insert into[Sheet1$] (f1,f2)";
oledbConnection.Open();
OleDbCommand command = new OleDbCommand(sqlStr, oledbConnection);
command.ExecuteNonQuery();
CloseConnection();
StreamWrite sw = new StreamWrite(path); //path:Excel路径
sw.write(file);