sql與excel互動(匯出/匯入)
exce->sql
//方案一: 通過oledb方式獲取excel檔案的資料,然後通過dataset中轉到sql server
openfiledialog = new openfiledialog();
openfiledialog.filter = "excel files(*.xls)|*.xls";
if(openfiledialog.showdialog()==dialogresult.ok)
console.writeline("新插入 " + datatable1.rows.count.tostring() + " 條記錄");
sqlda1.update(datatable1);
oledbconnection.close(); }
catch(exception ex)
} //方案二: 直接通過sql語句執行sql server的功能函式將excel檔案轉換到sql server資料庫
openfiledialog openfiledialog = new openfiledialog();
openfiledialog.filter = "excel files(*.xls)|*.xls";
sqlconnection sqlconnection1 = null;
if(openfiledialog.showdialog()==dialogresult.ok)
catch(exception ex)
} if(sqlconnection1!=null)
//方案三: 通過到入excel的vba dll,通過vba介面獲取excel資料到dataset
openfiledialog openfile = new openfiledialog();
openfile.filter = "excel files(*.xls)|*.xls";
excelio excelio = new excelio();
if(openfile.showdialog()==dialogresult.ok)
object temp = new object[y];
for(int i=1; i<=x; i++)
dr.itemarray = temp;
ds.tables[0].rows.add(dr); }
datagrid1.setdatabinding(ds,"xlstable");
if(excelio!=null)
excelio.close(); }
sql->excel
public class opexcel
public bool writdatasettoexcel(dataset ds,string excelpath,progressbar pb)
{if(ds==null)return false;
int row=ds.tables [0].rows .count ;
int col=ds.tables [0].columns .count ;
if(row <1 || col<1)return false;
pb.minimum =0;pb.maximum =row;pb.value =0;
try{
excel.workbooks.add (type.missing );
excel.worksheet sheet=(excel.worksheet)excel.activesheet;
for(int i=0;i
Hutool匯出Excel,導多個Sheet頁
指定要寫出的 sheet 頁 bigwriter.setsheet sheet.getsheetname public class huexcelutils else 設定欄位和別名 bigwriter.setheaderalias sheet.getfieldandalias 設定只匯出有別名的字...
sql語句,匯出成excel
exec master.xp cmdshell bcp select from gico.management dbo tb user queryout c abc.xls c s 192.168.0.2,11433 u sa p 123456 下邊那句話必須寫成一行,換行就掛了,靠,我也不知道原因...
SQL語句匯入匯出Excel
匯出到excel exec master.xp cmdshell bcp settledb.dbo.shanghu out c temp1.xls c q s gnetdata gnetdata u sa p 匯入excel select from opendatasource microsoft....