using System.Reflection;
using Microsoft.Office.Interop.Excel;
protected void Page_Load(object sender, EventArgs e)
{
Application app = new Application();
//加载模板
Workbook workbook = app.Workbooks.Open(Server.MapPath("~/Template.xlt"),
Missing.Value, Missing.Value,Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value);
try
{
//获取模板中第一个sheet页
Worksheet worksheet = workbook.Sheets.get_Item(1) as Worksheet;
//向Excel单元格填充数据
worksheet.Cells[2, 1] = "66";
worksheet.Cells[2, 2] = "24";
worksheet.Cells[2, 3] = "女";
worksheet.Cells[3, 1] = "lulu";
worksheet.Cells[3, 2] = "20";
worksheet.Cells[3, 3] =
C# 结合Microsoft.Office.Interop.Excel写入Excel
最新推荐文章于 2024-07-11 00:41:48 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)