using system;
using system.data.oledb;
using system.io;
using system.windows.forms;
namespace postgraduateclient
public sqltoexcel(string tablename)
public void exporttoexcel(string filename,system.data.datatable dtable)
string oledbconnstr = "provider=microsoft.jet.oledb.4.0;data source="+filename+";";
oledbconnstr += " extended properties=excel 8.0;";
string createstr = "create table "+this.excelname+"(";
for(int i=0;i<=dtable.columns.count-1;i++)
createstr = createstr.remove(createstr.length-1,1);
createstr = createstr+")";
oledbconnection oconn = new oledbconnection();
oconn.connectionstring = oledbconnstr;
oledbcommand ocreatecomm = new oledbcommand();
ocreatecomm.connection = oconn;
ocreatecomm.commandtext = createstr;
oconn.open();
ocreatecomm.executenonquery();
//中間填充資料;
string insertstr = "insert into "+this.excelname+" values(";
for(int i=0;i<=dtable.rows.count-1;i++)
insertstr = insertstr.remove(insertstr.length-1,1) +")";
ocreatecomm.commandtext = insertstr;
ocreatecomm.executenonquery();
}
catch
insertstr = "insert into "+this.excelname+" values(";
}
//中間填充資料;
oconn.close();
}
catch
}
}
}
將資料匯出到excel
前台jsp呼叫 function outexe action 將資料匯出到excel action value lpm grpinfoexl public string lpmexl throws exception else if g.getregtime null else rows 當stri...
資料匯出到excel
一 加上表頭後變成亂碼 要匯出的datatable 型別 excel的檔名 匯出的檔案中不帶表頭 二 使用wps開啟正常 匯出到excel 已經實現效果 資料表 檔名 列名 需要查詢幾列 else else resp.write ls item resp.write resp.end 三 目前用著感...
將mysql資料匯出到excel表中
title 資料備份 date y m d h i s sep t crlf n conn mysql connect localhost root or die 不能連線資料庫 mysql select db 資料庫名稱 conn mysql query set names utf8 header...