C#导出到Excel模板已存在 [英] C# Export to Excel template already existing

查看:621
本文介绍了C#导出到Excel模板已存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以将值从gridview导出到excel工作表,而我已经完成了,现在的问题是,我想将网格视图中的值填充到已经存在的excel模板中(现有模板已经包含页眉,页脚,列名和所有),请帮助我(与机密代码朋友一起.)

在这里,我有创建一个新的Excel工作表的代码,但是我想填充已经存在的Excel工作表.这是我的C#代码.



受保护的void exporttoexcel_Click(对象发送者,EventArgs e)
{
Microsoft.Office.Interop.Excel.Application xla =新的Microsoft.Office.Interop.Excel.Application();
工作簿vb = xla.Workbooks.Add(XlSheetType.xlWorksheet);
工作表ws =(工作表)xla.ActiveSheet;


xla.Visible = true;

ws.Cells [1,1] ="Slno";
ws.Cells [1,2] =代码";
ws.Cells [1,3] =名称";
ws.Cells [1,4] ="Ashte";

ws.Cells [2,1] = TextBox1.Text;
ws.Cells [2,2] = TextBox2.Text;
ws.Cells [2,3] = TextBox3.Text;
ws.Cells [2,4] = TextBox4.Text;

ws.Cells [11,9] = TextBox4.Text;

}

i can export a values from gridview to an excel sheet and i am done with that, the problem what i have now is, i want to populate the values from grid view into already existing excel template (existing template already contains header, footer, column name and all ) please help me out wit code friends.

here i have my code which creates a new excel sheet, but i want to fill already existing excel sheet. this is my c# code.



protected void exporttoexcel_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Excel.Application xla = new Microsoft.Office.Interop.Excel.Application();
Workbook vb = xla.Workbooks.Add(XlSheetType.xlWorksheet);
Worksheet ws = (Worksheet)xla.ActiveSheet;


xla.Visible = true;

ws.Cells[1,1]="Slno";
ws.Cells[1, 2] = "code";
ws.Cells[1, 3] = "name";
ws.Cells[1, 4] = "Ashte";

ws.Cells[2, 1] = TextBox1.Text;
ws.Cells[2, 2] = TextBox2.Text;
ws.Cells[2, 3] = TextBox3.Text;
ws.Cells[2, 4] = TextBox4.Text;

ws.Cells[11, 9] = TextBox4.Text;

}

推荐答案

hi,

请参阅下面的链接..

http://social.msdn.microsoft.com/论坛/da-DK/csharpgeneral/thread/ef11a193-54f3-407b-9374-9f5770fd9fd7 [


See the below link..

http://social.msdn.microsoft.com/Forums/da-DK/csharpgeneral/thread/ef11a193-54f3-407b-9374-9f5770fd9fd7[^]


Hope this works out...


这篇关于C#导出到Excel模板已存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆