C#winform 如何导出一定格式的excel啊?
2个回答
展开全部
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.在代码头添加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);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询