日期:2014-5-20 浏览次数:20660次

c#.net如何讀寫電子表格??及圖檔
c#.net如何讀寫電子表格???word文檔???及3D圖檔???

------解决方案--------------------
我写了一个对excel操作的类 可作参考
private OleDbConnection oleConn = null;
public DataAccess(string filePath)
{
oleConn = new OleDbConnection( "provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + filePath + "; " + "Extended Properties=Excel 8.0 ");
}

private void OpenConn()
{
if (oleConn.State == ConnectionState.Closed)
{
oleConn.Open();
}
}

private void CloseConn()
{
if (oleConn.State == ConnectionState.Open)
{
oleConn.Close();
}
}

/// <summary>
/// 查询
/// </summary>
/// <param name= "oleCmdstr "> </param>
/// <returns> </returns>
public DataSet ReturnOleDataSet(string oleCmdstr)
{
this.OpenConn();
DataSet ds = new DataSet();
try
{
OleDbCommand oleCmd = new OleDbCommand();
oleCmd.Connection = oleConn;
oleCmd.CommandText = oleCmdstr;

OleDbDataAdapter oleDa = new OleDbDataAdapter(oleCmd);

oleDa.Fill(ds);
}
finally
{
this.CloseConn();
}
return ds;
}

/// <summary>
/// 更新
/// </summary>
/// <param name= "oleCmdstr "> </param>
/// <returns> </returns>
public void UpdateExcel(string oleCmdstr)
{
this.OpenConn();
OleDbCommand oleCmd = new OleDbCommand();
OleDbTransaction myTran = oleConn.BeginTransaction();
DataSet ds = new DataSet();
oleCmd.Transaction = myTran;
try
{
oleCmd.Connection = oleConn;
oleCmd.CommandText = oleCmdstr;

oleCmd.ExecuteNonQuery();
}
catch
{
myTran.Rollback();
}
finally
{
this.CloseConn();
}

}