ComAutoWrapper 1.1.5.4
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package ComAutoWrapper --version 1.1.5.4
NuGet\Install-Package ComAutoWrapper -Version 1.1.5.4
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="ComAutoWrapper" Version="1.1.5.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ComAutoWrapper" Version="1.1.5.4" />
<PackageReference Include="ComAutoWrapper" />
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 ComAutoWrapper --version 1.1.5.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ComAutoWrapper, 1.1.5.4"
#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 ComAutoWrapper@1.1.5.4
#: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=ComAutoWrapper&version=1.1.5.4
#tool nuget:?package=ComAutoWrapper&version=1.1.5.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
ComAutoWrapper
ComAutoWrapper egy minimalista és oktató jellegű C# wrapper könyvtár, amely megkönnyíti a COM-objektumok késői kötésű (late binding
) használatát IDispatch
alapon – külső interop DLL nélkül.
A cél: egyszerűen és biztonságosan vezérelhessük az Excel, Word vagy más COM-alapú alkalmazásokat .NET-ből.
🎯 Fő előnyök
- ✅ Könnyű használat – magas szintű metódusokkal
- ✅ Interop DLL-mentes – nem kell Microsoft.Office.Interop referenciát hozzáadni
- ✅ Hibakezelés és felszabadítás beépítve
- ✅ Excel & Word példák dokumentáltan
📦 Telepítés
A NuGet csomag hamarosan elérhető:
dotnet add package ComAutoWrapper
Fejlesztés alatt, lokális .nupkg is használható addig.
🔧 Fő komponensek
Osztály Szerepe
ComInvoker Property/metódus elérés late binding-gel
ComReleaseHelper COM-objektumok nyomon követése és felszabadítása (FinalReleaseComObject)
ComValueConverter .NET típusok → COM-kompatibilis (pl. Color → OLE_COLOR)
ComRotHelper Excel példányok listázása a Running Object Table-ből
ExcelHelper Workbook / Worksheet / Range lekérdezés
ExcelSelectionHelper Kijelölt tartomány kezelése, koordináta lekérdezés
ExcelStyleHelper Cella háttérszínezés
WordHelper Teljes minta Word táblázat beszúrására
WordStyleHelper Word Range formázása (pl. félkövér + háttérszín)
ComTypeInspector COM tagok introspektív lekérdezése ITypeInfo alapján
🧪 Példák
📘 Excel – cellák formázása
csharp
var app = Activator.CreateInstance(Type.GetTypeFromProgID("Excel.Application"));
ComInvoker.SetProperty(app!, "Visible", true);
var workbooks = ComInvoker.GetProperty<object>(app!, "Workbooks");
ComInvoker.CallMethod(workbooks!, "Add");
var apps = ComRotHelper.GetExcelApplications();
foreach (var excel in apps)
{
foreach (var wb in ExcelHelper.GetWorkbooks(excel))
{
foreach (var sheet in ExcelHelper.GetWorksheets(wb))
{
var range = ExcelHelper.GetRange(sheet, "B2:D2");
ComInvoker.SetProperty(range, "Value", "Teszt");
var interior = ComInvoker.GetProperty<object>(range, "Interior");
int szin = ComValueConverter.ToOleColor(System.Drawing.Color.LightGreen);
ComInvoker.SetProperty(interior!, "Color", szin);
ComReleaseHelper.Track(range);
ComReleaseHelper.Track(interior);
}
ComInvoker.SetProperty(wb, "Saved", ComValueConverter.ToComBool(true));
ComInvoker.CallMethod(wb, "Close", ComValueConverter.ToComBool(true));
ComReleaseHelper.Track(wb);
}
ComInvoker.CallMethod(excel, "Quit");
ComReleaseHelper.Track(excel);
}
ComReleaseHelper.ReleaseAll();
📝 Word – táblázat beszúrása és formázása
csharp
var wordApp = Activator.CreateInstance(Type.GetTypeFromProgID("Word.Application"));
ComInvoker.SetProperty(wordApp!, "Visible", true);
ComInvoker.SetProperty(wordApp!, "DisplayAlerts", false);
var documents = ComInvoker.GetProperty<object>(wordApp!, "Documents");
var doc = ComInvoker.CallMethod<object>(documents!, "Add");
var range = ComInvoker.GetProperty<object>(doc!, "Content");
var tables = ComInvoker.GetProperty<object>(doc!, "Tables");
var table = ComInvoker.CallMethod<object>(tables!, "Add", range, 3, 3);
for (int row = 1; row <= 3; row++)
{
for (int col = 1; col <= 3; col++)
{
var cell = ComInvoker.CallMethod<object>(table, "Cell", row, col);
var cellRange = ComInvoker.GetProperty<object>(cell, "Range");
ComInvoker.SetProperty(cellRange, "Text", $"R{row}C{col}");
if (row == 1)
{
WordStyleHelper.ApplyStyle(
cellRange,
fontColor: ComValueConverter.ToOleColor(Color.White),
backgroundColor: ComValueConverter.ToOleColor(Color.DarkRed),
bold: true
);
}
ComReleaseHelper.Track(cell);
ComReleaseHelper.Track(cellRange);
}
}
ComInvoker.SetProperty(doc, "Saved", ComValueConverter.ToComBool(true));
ComInvoker.CallMethod(doc, "Close", ComValueConverter.ToComBool(false));
ComInvoker.CallMethod(wordApp!, "Quit");
ComReleaseHelper.Track(table);
ComReleaseHelper.Track(tables);
ComReleaseHelper.Track(doc);
ComReleaseHelper.Track(documents);
ComReleaseHelper.Track(wordApp);
ComReleaseHelper.ReleaseAll();
🔐 License
MIT License
Szabadon használható oktatási és üzleti célra is.
Lásd: LICENSE
🙋♂️ Kinek ajánlott?
.NET fejlesztőknek, akik nem akarnak Office Interop DLL-t használni
Oktatóknak, akik bemutatnák a IDispatch-alapú elérést
Haladó automatizálóknak, akik minimalista, de stabil COM API-t keresnek
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net9.0
- No dependencies.
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.5.5 | 155 | 7/26/2025 |
1.1.5.4 | 485 | 7/23/2025 |
1.1.5.3 | 184 | 7/20/2025 |
1.1.5.2 | 23 | 7/19/2025 |
1.1.5.1 | 17 | 7/19/2025 |
1.1.5 | 22 | 7/19/2025 |
1.1.4 | 116 | 7/16/2025 |
1.1.3.2 | 132 | 7/15/2025 |
1.1.3.1 | 102 | 7/12/2025 |
1.1.3 | 91 | 7/12/2025 |
1.1.2 | 135 | 7/10/2025 |
1.1.1 | 141 | 7/6/2025 |
1.1.0 | 138 | 6/23/2025 |
1.0.0 | 138 | 6/23/2025 |