C#winform 如何导出一定格式的excel啊?

2024-12-30 16:42:52
推荐回答(2个)
回答1:

1.右击解决方案的引用,添加.NET中Microsoft.Office.Interop.Excel的引用;
2.在代码头添加using Microsoft.Office.Interop.Excel;
3.在函数中添加如下代码:
//创建
Microsoft.Office.Interop.Excel.Application excel1 = new Microsoft.Office.Interop.Excel.Application();
Workbook workbook1 = excel1.Workbooks.Add(true);
Worksheet worksheet1 = (Worksheet)workbook1.Worksheets["sheet1"];

//写入
worksheet1.Cells[1, 1] = "航班号";
worksheet1.Cells[1, 2] = "起飞地点";
worksheet1.Cells[1, 3] = "降落地点";

//显示
excel1.Visible = true;

Console.ReadLine();

//保存文件
workbook1.Close(true, "d:\\1.xls", null);

回答2:

com组件 去搜索学习下吧