110,925
社区成员
发帖
与我相关
我的任务
分享
代码:
using System;
using System.IO;
using OfficeOpenXml;
class Program
{
static void Main()
{
// 定义文件路径
string filePath = @"d:\File.xlsx";
// 创建 Excel 文件并写入数据
using (var package = new ExcelPackage())
{
// 添加一个工作表
var worksheet = package.Workbook.Worksheets.Add("Sheet1");
// 写入数据
worksheet.Cells[1, 1].Value = "Hello, Excel!";
worksheet.Cells[2, 1].Value = "This is a test.";
// 保存文件
FileInfo fileInfo = new FileInfo(filePath);
package.SaveAs(fileInfo);
}
Console.WriteLine("Data has been written to Excel without showing a save dialog.");
}
}
运行错误
请问专家,如何解决?谢谢