代碼
protected void exportToExcelClient(IDictionary<string, string> map)
{
if (map.Count == 0)
{
MessageBox.Show("請選擇要導出的字段!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
pgbClient.Value = 0;
_excel = new Excel.Application();
Excel.Workbook wbook = _excel.Workbooks.Add(Missing.Value);
Excel.Worksheet wsheet = (Excel.Worksheet)_excel.ActiveSheet;
Excel.Range range = (Excel.Range)wsheet.Cells;
Excel.Range ran = null;
string tofilepath = Application.StartupPath + "\Excel_save\";
string tofilename = "customer.xls";
string sql = "SELECT ";
ArrayList keyArr = new ArrayList();
foreach(KeyValuePair<string,string> entry in map)
{
sql+=entry.Value+",";
keyArr.Add(entry.Key);
}
sql = sql.Substring(0, sql.Length - 1);
sql += " FROM tb_ClientInfo WHERE 1=1"+condition;
//MessageBox.Show(sql);
DataSet myds = boperate.getds(sql, "tb_Client");
DataTable dt = myds.Tables["tb_Client"];
for (int i = 0; i < keyArr.Count; i++)
{
ran = (Excel.Range)range[1, i + 1];
ran.Font.Bold = true;
ran.Font.Size = 10;
ran.Value2 = keyArr[i];
//ran.Columns.AutoFit();
NAR(ran);
pgbClient.Step =