我有两个 .net-6 控制台应用程序:
C# 中的一个
using Excel = Microsoft.Office.Interop.Excel;
Console.WriteLine("Hello, World!");
var xl = new Excel.Application();
var wb = xl.Workbooks.Open(@"c:\temp\test-2.xlsx");
wb.Close(0);
xl.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(wb);
System.Runtime.InteropServices.Marshal.ReleaseComObject(xl);
wb = null;
xl = null;
Run Code Online (Sandbox Code Playgroud)
另一种是 VB.NET 中的。
Imports System
Imports Excel = Microsoft.Office.Interop.Excel
Module Program
Sub Main(args As String())
Console.WriteLine("Hello World!")
Dim xl = New Excel.Application()
Dim wb = xl.Workbooks.Open("c:\\temp\\test-2.xlsx")
wb.Close(0)
xl.Quit()
'System.Runtime.InteropServices.Marshal.ReleaseComObject(wb)
'System.Runtime.InteropServices.Marshal.ReleaseComObject(xl)
'wb = Nothing
'xl = Nothing
End Sub
End Module
Run Code Online (Sandbox Code Playgroud)
两个控制台中的项目配置是相同的:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>OfficeInteropTest</RootNamespace>
</PropertyGroup>
<ItemGroup>
<COMReference …Run Code Online (Sandbox Code Playgroud) 我的最终目标是用 C# 构建一个类库 (Calculator.dll),其中包含可通过 VBA 访问 Excel 的函数。
我本来希望避免注册 dll 的需要,而是在 VBA 代码中使用 Declare Function 语句,但显然这是不可能的,我的研究表明我需要使类库 COM-Visible,然后注册并将其添加为 VBA 项目的引用。在早期的 Visual Studio 版本中,这似乎是单击项目属性对话框中的框的问题,但我在 VS2022 中没有看到该框?!
这些是我对“玩具”示例采取的步骤,以及我遇到的问题。
(1) 我用一个计算类和一个简单的方法来添加两个整数,构建了以下 .dll。由于我们使用 32 位 Excel,因此我将其配置为 x86。
namespace ClassLibraryCalculator
{
public class Calculate
{
public int Add(int a,int b){ return a + b; }
}
}
Run Code Online (Sandbox Code Playgroud)
(2) 在命令提示符下,以管理员身份运行,我尝试运行 regsvr32“ClassLibraryCalculator.dll”,但遇到错误“..已加载,但未找到入口点 DllRegisterServer”
经过搜索,据说解决这个问题的方法是修改项目属性,这是(在早期版本的VS中?)一个对话框

带有一个复选框,但我在 Visual Studio 2022 项目属性中没有看到任何与 COM 相关的内容。
大约两个月前,我接到了制作 Outlook.com 插件的任务。基础功能完美运行,但更高优先级的东西出现了。所以这个项目在过去的两个月里还算顺利。
昨天我想继续这个项目,但它不再起作用了。当我在 Visual Studio 中启动项目并且需要登录我的办公室帐户时,问题就出现了。如果我登录,它将加载一段时间,然后弹出错误。它说:
An error occurred while connecting to the server:
The request failed. Unable to connect to the remote server
Run Code Online (Sandbox Code Playgroud)
既然我在过去两个月里没有改变任何东西,这怎么可能?我该如何解决这个问题?
我按照微软自己的教程进行操作。
编辑:
以下是一些屏幕截图:
这是在我的 Visual Studio 内,我在这里启动我的加载项。将出现以下弹出窗口。我已经仔细检查了我的凭据。

希望这能提供有关正在发生的事情的更多信息。
我想将一封电子邮件标记为从我的 python 代码中读取的。我在用着
from exchangelib import Credentials, Account
my_account = Account(...)
credentials = Credentials(...)
Run Code Online (Sandbox Code Playgroud)
访问该帐户。这部分效果很好。然后我使用这个进入我想要的文件夹
var1 = my_account.root / 'branch1' / 'desiredFolder'
Run Code Online (Sandbox Code Playgroud)
再说一次,这效果很好。这就是将其标记为已读似乎不起作用的地方。
item = var1.filter(is_read=False).values('body')
for i, body in enumerate(item):
#Code doing stuff
var1.filter(is_read=False)[i].is_read = True
var1.filter(is_read=False)[i].save(updated_fields=['is_read'])
Run Code Online (Sandbox Code Playgroud)
我已经尝试过这篇文章Mark email as read with Exchangelib中的提示和答案,但电子邮件仍然显示为未读。我究竟做错了什么?
我有以下两个组件(父组件和子组件)
\n.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Index.vue (Parent)\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 _GetShipment.vue (Child)\nRun Code Online (Sandbox Code Playgroud)\n在Index.vue我尝试使用 Office.js\ 的 getAsync 获取电子邮件正文的内容:
.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Index.vue (Parent)\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 _GetShipment.vue (Child)\nRun Code Online (Sandbox Code Playgroud)\n上面检查电子邮件正文内容以查看是否存在正则表达式匹配。如果存在,它将把匹配项添加到数组中shipments。
目前,如果仅找到一个匹配项,则该匹配项将在名为 的子组件中呈现_GetShipment:
<script>\nimport Shipment from \'./_GetShipment.vue\';\nimport { ref, defineComponent } from \'vue\';\n\n\nexport default defineComponent({\n setup() {\n const shipments = ref([]);\n\n Office.context.mailbox.item.body.getAsync(\n "text",\n function (result) {\n if (result.status === Office.AsyncResultStatus.Succeeded) {\n let matches = result.value.match(/S\\w{3}\\d{8,9}/ig);\n if(matches){\n shipments.value = matches;\n }\n }\n }\n );\n\n return {\n shipments,\n }\n },\n components: {\n Shipment,\n },\n})\n</script>\n\n<template>\n …Run Code Online (Sandbox Code Playgroud) 我已将ContextMenuItem添加到ContextMenu for Outlook约会.

问题是我无法弄清楚如何获得Appointment对象.如果我得到一个IRibbonControl,它的Context属性应该包含Appointment,但它包含一个Selection.据我所见,我无法使用选择来预约.

这个页面是我来自的地方:https://msdn.microsoft.com/en-us/library/office/ff863278%28v=office.14%29.aspx
谁知道如何获得预约?