dotnet / dotnet/core

Excel Automation with .net core 2.2

Open
#5,000 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
PowerShell
Stars
22k
Forks
4.9k
Avg merge
5d 5h
Merged PRs (30d)
29

Description

I have looked at the closed issue: "Office Automation in dotnet core - are there any plans for this"
https://github.com/dotnet/core/issues/409

I may have missed it but I can't find the answer to the original question: Can Office Automation be done in dotnet core?

I have succeeded to do it on .net 4.6 by following the following example:
https://docs.microsoft.com/en-us/previous-versions/office/troubleshoot/office-developer/automate-excel-from-visual-c

Then I tried to import the Microsoft.Office.Interop.Excel library to the core project by following this example:
https://stackoverflow.com/questions/58130446/net-core-3-0-and-ms-office-interop#_=_
Adding a reference the Interop,Excel COM library to a .net 4.6 application and then copying the reference element of the .csproj from the net 4.6 app to the .net core 2.2 app

```


{00020813-0000-0000-C000-000000000046}
1
9
0
primary
False
True

```
Unfortunately, it doesn't work as expected:

An excel file is being opened but the fields are not being populated per that code:

```
oSheet = (Excel._Worksheet)oWB.ActiveSheet;
oSheet.Cells[1, 1] = "First Name";
oSheet.Cells[1, 2] = "Last Name";
oSheet.Cells[1, 3] = "Full Name";
oSheet.Cells[1, 4] = "Salary";
```

Also, these lines of code through a null reference exception
```
oSheet.get_Range("A1", "D1").Font.Bold = true;
oSheet.get_Range("A1", "D1").EntireColumn.AutoFit();
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.