$excel = "$pwd\桌面\book1.xls"
# Make the Connection : s
$ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=$excel;Extended Properties=Excel 8.0;"
$Conn = new-object System.Data.OleDb.OleDbConnection($connString)
# Open the Connection
$conn.open()
# Get the available Tables
$Tables = $Conn.GetOleDbSchemaTable([System.Data.OleDb.OleDbSchemaGuid]::tables,$null)
# make a Command to get all data of the first table (Sheet)
$cmd = new-object System.Data.OleDb.OleDbCommand("Select * from [$($tables.rows[0].TABLE_NAME)]",$Conn)
# Load a DataAdapter with the Select Command.
$da = new-object System.Data.OleDb.OleDbDataAdapter($cmd)
# Fill a DataSet from the Data Adapter
$ds = new-object System.Data.dataset
$da.fill($ds)
# get the Tables
$ds.tables | out-null
# get all Row's where User is Mow1
$ds.tables[0].select("user = 'Mow1'")
# Save this Dataset as XML Document:
$sw = new-object system.io.streamwriter("$pwd\桌面\Puters.xml")
$ds.WriteXml($sw)
$sw.close()
# Load XML document into new dataset :
$sr = new-object system.io.streamreader("$pwd\桌面\Puters.xml")
$ds.ReadXml($sr)
$sr.close()
$ds.tables
摘自:mow001的blog