当前位置:软件学习 > Excel >>

C# 调用Excel组件生成excel文件

代码
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 = 补充:软件开发 , C# ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,