C# excel 通过datatable方式读取保存 留存
public System.Data.DataTable LoadxlsToTable(string xlsPath,string sheetName="Sheet1")
{
var connectString = String.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=1\"", xlsPath);
var adapter = new OleDbDataAdapter($"SELECT * FROM [{sheetName}$]", connectString);
var ds = new DataSet();
adapter.Fill(ds, sheetName);
return ds.Tables[sheetName];
}
public bool SaveTableToXls(string xlsPath,DataTable _dataTable)
{
if(_datatable==null)
{
return false;
}
try
{
Microsoft.Office.Interop.Excel.Application xls = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Range m_objRange = null;
Microsoft.Office.Interop.Excel.Workbook m_objWor