程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> C# 調用Excel組件生成excel文件

C# 調用Excel組件生成excel文件

編輯:C#入門知識

代碼

        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 =
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved