MudTools.OfficeInterop.Excel
1.1.7
.NET 6.0
This package targets .NET 6.0. The package is compatible with this framework or higher.
.NET Standard 2.0
This package targets .NET Standard 2.0. The package is compatible with this framework or higher.
.NET Framework 4.6.2
This package targets .NET Framework 4.6.2. The package is compatible with this framework or higher.
dotnet add package MudTools.OfficeInterop.Excel --version 1.1.7
NuGet\Install-Package MudTools.OfficeInterop.Excel -Version 1.1.7
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MudTools.OfficeInterop.Excel" Version="1.1.7" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MudTools.OfficeInterop.Excel" Version="1.1.7" />
<PackageReference Include="MudTools.OfficeInterop.Excel" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MudTools.OfficeInterop.Excel --version 1.1.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MudTools.OfficeInterop.Excel, 1.1.7"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MudTools.OfficeInterop.Excel@1.1.7
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MudTools.OfficeInterop.Excel&version=1.1.7
#tool nuget:?package=MudTools.OfficeInterop.Excel&version=1.1.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
MudTools.OfficeInterop.Excel
Excel 操作模块,提供完整的 Excel 应用程序操作接口。
项目概述
MudTools.OfficeInterop.Excel 是专门用于操作 Microsoft Excel 应用程序的 .NET 封装库。该模块提供了完整的 Excel 应用程序操作接口,包括工作簿、工作表、单元格等对象的便捷操作,以及图表、数据透视表等高级功能封装。
通过使用本模块,开发者可以避免直接处理复杂的 Excel COM 交互,从而更专注于业务逻辑的实现。
主要功能
- 完整的 Excel 应用程序操作接口
- 工作簿、工作表、单元格等对象的便捷操作
- 图表、数据透视表等高级功能封装
- 格式设置、样式管理等功能
支持的框架
- .NET Framework 4.6.2
- .NET Framework 4.7
- .NET Framework 4.8
- .NET Standard 2.1
- .NET 6.0-windows
- .NET 7.0-windows
- .NET 8.0-windows
- .NET 9.0-windows
安装
<PackageReference Include="MudTools.OfficeInterop.Excel" Version="1.1.2" />
核心组件
ExcelFactory
ExcelFactory 是用于创建和操作 Excel 应用程序实例的工厂类,提供以下方法:
Connection
- 通过现有 COM 对象连接到已运行的 Excel 应用程序实例CreateInstance
- 通过 ProgID 创建特定版本的 Excel 应用程序实例BlankWorkbook
- 创建新的空白 Excel 工作簿CreateFrom
- 基于模板创建新的 Excel 工作簿Open
- 打开现有的 Excel 工作簿文件
使用示例
基本操作
// 创建 Excel 应用程序实例
using var app = ExcelFactory.CreateApplication();
app.Visible = true;
// 添加工作簿
var workbook = app.Workbooks.Add();
var worksheet = workbook.Worksheets.Add();
// 操作单元格
worksheet.Range["A1"].Value = "Hello";
worksheet.Range["B1"].Value = "World";
// 保存工作簿
workbook.SaveAs(@"C:\temp\example.xlsx");
从模板创建 Excel 工作簿
// 基于模板创建工作簿
using var app = ExcelFactory.CreateFrom(@"C:\templates\ReportTemplate.xltx");
var worksheet = app.GetActiveSheet();
// 填充数据
worksheet.Range["A1"].Value = "销售报告";
worksheet.Range["A2"].Value = DateTime.Now.ToString("yyyy-MM-dd");
// 保存并关闭
app.ActiveWorkbook.SaveAs(@"C:\reports\SalesReport.xlsx");
app.Quit();
读取 Excel 数据
// 打开现有工作簿
using var app = ExcelFactory.Open(@"C:\data\SalesData.xlsx");
var worksheet = app.Worksheets[1];
// 读取数据范围
var dataRange = worksheet.Range["A1:D100"];
var rowCount = dataRange.Rows.Count;
var columnCount = dataRange.Columns.Count;
// 处理数据
for (int row = 1; row <= rowCount; row++)
{
for (int col = 1; col <= columnCount; col++)
{
var cellValue = dataRange.Cells[row, col].Value?.ToString();
Console.WriteLine($"Row {row}, Column {col}: {cellValue}");
}
}
app.Quit();
Excel 图表操作
using var app = ExcelFactory.BlankWorkbook();
var worksheet = app.GetActiveSheet();
// 添加示例数据
worksheet.Range["A1"].Value = "月份";
worksheet.Range["B1"].Value = "销售额";
worksheet.Range["A2"].Value = "一月";
worksheet.Range["B2"].Value = 10000;
worksheet.Range["A3"].Value = "二月";
worksheet.Range["B3"].Value = 15000;
worksheet.Range["A4"].Value = "三月";
worksheet.Range["B4"].Value = 12000;
// 创建图表
var chartObjects = worksheet.ChartObjects();
var chartObject = chartObjects.Add(100, 50, 300, 200);
var chart = chartObject.Chart;
// 设置图表数据源
chart.SetSourceData(worksheet.Range["A1:B4"]);
chart.ChartType = XlChartType.xlColumnClustered;
app.ActiveWorkbook.SaveAs(@"C:\charts\SalesChart.xlsx");
app.Quit();
许可证
本项目采用双重许可证模式:
免责声明
本项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任。
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net6.0-windows7.0 is compatible. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net8.0-windows7.0 is compatible. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETFramework 4.6.2
- log4net (>= 3.2.0)
- Microsoft.Office.Interop.Excel (>= 15.0.4795.1001)
- MudTools.OfficeInterop (>= 1.1.7)
- MudTools.OfficeInterop.Vbe (>= 1.1.7)
- System.ValueTuple (>= 4.6.1)
-
.NETStandard 2.0
- log4net (>= 3.2.0)
- Microsoft.Office.Interop.Excel (>= 15.0.4795.1001)
- MudTools.OfficeInterop (>= 1.1.7)
- MudTools.OfficeInterop.Vbe (>= 1.1.7)
- System.Drawing.Common (>= 4.7.3)
- System.ValueTuple (>= 4.6.1)
-
net6.0-windows7.0
- log4net (>= 3.2.0)
- Microsoft.Office.Interop.Excel (>= 15.0.4795.1001)
- MudTools.OfficeInterop (>= 1.1.7)
- MudTools.OfficeInterop.Vbe (>= 1.1.7)
-
net8.0-windows7.0
- log4net (>= 3.2.0)
- Microsoft.Office.Interop.Excel (>= 15.0.4795.1001)
- MudTools.OfficeInterop (>= 1.1.7)
- MudTools.OfficeInterop.Vbe (>= 1.1.7)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated | |
---|---|---|---|
1.1.7 | 32 | 9/22/2025 | |
1.1.6 | 217 | 9/19/2025 | |
1.1.5 | 257 | 9/17/2025 | |
1.1.4 | 111 | 9/14/2025 | |
1.1.3 | 79 | 9/12/2025 | |
1.1.2 | 351 | 9/11/2025 | |
1.1.1 | 347 | 9/10/2025 | |
1.1.0 | 354 | 9/8/2025 | |
1.0.7 | 424 | 8/26/2025 | |
1.0.6 | 285 | 8/23/2025 | |
1.0.5 | 349 | 8/21/2025 | |
1.0.4 | 211 | 8/21/2025 | |
1.0.3 | 216 | 8/19/2025 | |
1.0.2 | 209 | 8/18/2025 | |
1.0.1 | 214 | 8/18/2025 |
Initial release of MudTools.OfficeInterop.Excel library.