Skip to content

Commit 4aa07e0

Browse files
committed
Update to version 1.1.5.2 - Added UsedRangeSelect and minor improvements
1 parent efcd79c commit 4aa07e0

3 files changed

Lines changed: 135 additions & 9 deletions

File tree

β€ŽComAutoWrapper.csprojβ€Ž

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFramework>net9.0</TargetFramework>
4-
<ImplicitUsings>enable</ImplicitUsings>
4+
<ImplicitUsings>enable</ImplicitUsings>
55
<Nullable>enable</Nullable>
66
<Platforms>AnyCPU;x64</Platforms>
77
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
8+
89
<PackageId>ComAutoWrapper</PackageId>
9-
<Version>1.1.4</Version>
10+
<Version>1.1.5.2</Version>
1011
<Authors>pmonitor</Authors>
1112
<Company>SajΓ‘t FejlesztΓ©s</Company>
1213
<Description>Simple AutoWrapper-style COM helper for C#. Enables method and property calls on COM objects without Interop DLLs or dynamic.</Description>
1314
<PackageTags>COM Interop AutoWrap Excel, Word</PackageTags>
14-
<AssemblyVersion>1.1.4</AssemblyVersion>
15-
<FileVersion>1.1.4</FileVersion>
16-
<PackageProjectUrl></PackageProjectUrl>
15+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1716
<PackageReadmeFile>Readme.md</PackageReadmeFile>
1817
<RepositoryUrl>https://github.com/pmonitor0/ComAutoWrapper</RepositoryUrl>
19-
<NuGetAudit>True</NuGetAudit>
18+
19+
<AssemblyVersion>1.1.5.2</AssemblyVersion>
20+
<FileVersion>1.1.5.2</FileVersion>
2021
</PropertyGroup>
22+
2123
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
2224
<DebugType>embedded</DebugType>
2325
</PropertyGroup>
@@ -30,7 +32,7 @@
3032
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
3133
<DebugType>embedded</DebugType>
3234
</PropertyGroup>
33-
<ItemGroup>
35+
<ItemGroup>
3436
<Reference Include="ComAutoWrapper">
3537
<HintPath>bin\x64\Release\net9.0\ComAutoWrapper.dll</HintPath>
3638
</Reference>

β€ŽWordStyleHelper.csβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
using System.Text;
88
using System.Threading.Tasks;
99

10-
namespace ComAutoWrapperDemo
10+
namespace ComAutoWrapper
1111
{
12-
class WordStyleHelper
12+
public class WordStyleHelper
1313
{
1414
public static void ApplyStyle(
1515
object range,

β€Žnupkg/Readme.mdβ€Ž

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# ComAutoWrapper
2+
3+
**ComAutoWrapper** is a lightweight, zero-Interop, fluent C# helper library for automating COM objects such as **Excel** and **Word** β€” without relying on bulky Primary Interop Assemblies (PIAs).
4+
5+
βœ”οΈ Fully dynamic
6+
βœ”οΈ Typed property/method access
7+
βœ”οΈ Introspectable
8+
βœ”οΈ Ideal for WPF / Console / WinForms projects
9+
βœ”οΈ Just **~30 KB** compiled DLL
10+
11+
---
12+
13+
## πŸš€ Features
14+
15+
- **No Interop DLLs needed**
16+
- Lightweight COM helper for C#
17+
- Elegant dynamic wrappers:
18+
- `GetProperty<T>()`, `SetProperty()`
19+
- `CallMethod<T>()`
20+
- COM introspection (`ComTypeInspector`)
21+
- Excel selection utilities (`ComSelectionHelper`)
22+
- Safe release of COM objects
23+
- Compatible with: .NET 6, 7, 8, 9+
24+
25+
---
26+
27+
## 🧠 Examples
28+
29+
### Get/Set COM Properties
30+
31+
```csharp
32+
var excel = Activator.CreateInstance(Type.GetTypeFromProgID("Excel.Application")!);
33+
ComInvoker.SetProperty(excel, "Visible", true);
34+
35+
var workbooks = ComInvoker.GetProperty<object>(excel, "Workbooks");
36+
var workbook = ComInvoker.CallMethod<object>(workbooks, "Add");
37+
```
38+
39+
### Invoke COM Methods
40+
41+
```csharp
42+
var sheet = ComInvoker.GetProperty<object>(workbook, "ActiveSheet");
43+
var cell = ComInvoker.GetProperty<object>(sheet, "Cells");
44+
ComInvoker.SetProperty(cell, "Item", new object[] { 1, 1 }, "Hello");
45+
```
46+
47+
### Introspect COM Object
48+
49+
```csharp
50+
var (methods, propsGet, propsSet) = ComTypeInspector.ListMembers(sheet);
51+
Console.WriteLine("Available methods:");
52+
methods.ForEach(Console.WriteLine);
53+
```
54+
55+
---
56+
57+
## ✨ Excel-Specific Helpers (Optional)
58+
59+
Provided via the built-in `ComSelectionHelper`:
60+
61+
| Method | Description |
62+
|--------|-------------|
63+
| `SelectCells(excel, sheet, "A1", "B3", "C5")` | Selects non-contiguous Excel cells |
64+
| `GetSelectedCellCoordinates(excel)` | Returns `(row, column)` for each selected cell |
65+
| `HighlightUsedRange(sheet)` | Highlights the used range with color |
66+
67+
These helpers abstract away the quirks of Excel's COM object model.
68+
69+
---
70+
71+
## πŸ“¦ NuGet Package
72+
73+
Install via CLI:
74+
75+
```bash
76+
dotnet add package ComAutoWrapper
77+
```
78+
79+
Or via Visual Studio NuGet UI.
80+
81+
---
82+
83+
## πŸ’» Requirements
84+
85+
- Windows OS (COM-based)
86+
- .NET 6 / 7 / 8 / 9
87+
- Microsoft Excel/Word must be installed
88+
89+
> The library **does not embed Interop DLLs**. It uses late binding with proper error handling.
90+
91+
---
92+
93+
## πŸ”— Related Project
94+
95+
- [ComAutoWrapperDemo (GitHub)](https://github.com/pmonitor0/ComAutoWrapperDemo)
96+
WPF demo showcasing full Excel and Word automation using this wrapper.
97+
98+
---
99+
100+
## πŸ“Š Comparison: OpenXML vs COM Automation
101+
102+
| Feature | OpenXML SDK | ComAutoWrapper |
103+
|--------|-------------|----------------|
104+
| Requires Excel Installed | ❌ | βœ… |
105+
| Works on Locked/Password Files | ❌ | βœ… |
106+
| Manipulate Active Excel Instance | ❌ | βœ… |
107+
| Word Automation | ❌ | βœ… |
108+
| File Size (DLL) | >10 MB | ~30 KB |
109+
| API Simplicity | Moderate | High (fluent & dynamic) |
110+
| Cell Selection / UI Interaction | ❌ | βœ… |
111+
| UsedRange / Borders / Colors | ❌ | βœ… |
112+
113+
---
114+
115+
## πŸ™ Acknowledgment
116+
117+
This library is the result of an iterative collaboration between the author and ChatGPT.
118+
Special thanks to all early testers and contributors who shaped the API.
119+
120+
---
121+
122+
## πŸ“„ License
123+
124+
MIT

0 commit comments

Comments
Β (0)