110,561
社区成员
发帖
与我相关
我的任务
分享
/// <summary>
/// Excel 转换 XML
/// </summary>
/// <param name="_excelPath"></param>
public void ExcelConversionXML(string _excelPath) {
string connection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + _excelPath + ";Extended Properties=\"Excel 12.0;HDR=YES\"";
try {
OleDbConnection conn = new OleDbConnection(connection);
string tbName = null; // 表名
OleDbDataAdapter oda = new OleDbDataAdapter("select * from ["+ tbName +"$]", conn);//
oda.Fill(ds, "商品信息");
oda = new OleDbDataAdapter("select * from [右边$]", conn);
oda.Fill(ds, "商品信息");
conn.Close();
} catch (Exception ex) {
}
}
DataTable schemaTable = conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, null);
string tableName = schemaTable.Rows[0][2].ToString().Trim();//获取第一个工作页的名称;
OleDbDataAdapter oda = new OleDbDataAdapter("select * from [" + tableName + "]", conn);
/// <summary>
/// Excel 转换 XML
/// </summary>
/// <param name="_excelPath"></param>
public void ExcelConversionXML(string _excelPath) {
string connection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + _excelPath + ";Extended Properties=\"Excel 12.0;HDR=YES\"";
try {
OleDbConnection conn = new OleDbConnection(connection);
// 当前数据库有的表名
string[] tbName = null; // TODO: ????????????????????????????????????????????????????????
foreach (string item in tbName) {
oda = new OleDbDataAdapter("select * from [" + item + "$]", conn);
oda.Fill(ds, conn.Database);
}
conn.Close();
} catch {
throw;
}
}