AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-6469472

Humberto's questions

Martin Hope
Humberto
Asked: 2025-04-09 00:25:46 +0800 CST

无需 Visual Studio 和 Windows 计算机即可创建基本的 Web 内容插件

  • 5

我正在尝试按照官方文档开发内容插件。实现部分指出只需要进行少量更改:

  • 对于 OfficeApp 元素,将 xsi:type 属性设置为“ContentApp”。
  • 在DefaultSettings元素中,添加RequestedHeight和RequestedWidth元素。

在同一部分中,列出了两个适用于 PowerPoint 和 Excel 的基于内容的入门插件,但遗憾的是它们针对的是 Visual Studio,而我没有 Windows 电脑。此外,还提到了一个已有 9 年历史的示例Excel-Content-Add-in-Humongous-Insurance,其清单看起来相当过时。

我决定尝试使用 Yeoman 和 VScode。由于yo officeOffice 不提供基于内容的插件入门,我选择使用:

? Choose a project type: Office Add-in Task Pane project using React framework
? Choose a script type: TypeScript
? What do you want to name your add-in? my-content-addin
? Which Office client application would you like to support? Powerpoint

按照上面列出的文档,我将元素xsi:type的更改OfficeApp为,并将和元素ContentApp添加到元素。RequestedHeightRequestedWidthDefaultSettings

此外,我注意到Excel-Content-Add-in-Humongous-Insurance清单在 OfficeApp 中没有以下模式:

xmlns:ov="http://schemas.microsoft.com/office/taskpaneappversionoverrides"

我检查了 office-addin-manifest 存储库,但找不到内容插件的替代方案,例如,.../contentappversionoverrides我只找到了一个额外的.../mailappversionoverrides。

我还注意到Excel-Content-Add-in-Humongous-Insurance清单中没有该VersionOverrides元素,因此我从生成的清单中删除了该元素manifest.xml。因此,我最终得到了:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<OfficeApp 
  xmlns="http://schemas.microsoft.com/office/appforoffice/1.1" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0" 
  xsi:type="ContentApp">
  <Id>9e2e38ec-67af-43e6-8aeb-c8c3e22b86bd</Id>
  <Version>1.0.0.0</Version>
  <ProviderName>Contoso</ProviderName>
  <DefaultLocale>en-US</DefaultLocale>
  <DisplayName DefaultValue="my-content-addin"/>
  <Description DefaultValue="A template to get started."/>
  <IconUrl DefaultValue="https://localhost:3000/assets/icon-32.png"/>
  <HighResolutionIconUrl DefaultValue="https://localhost:3000/assets/icon-64.png"/>
  <SupportUrl DefaultValue="https://www.contoso.com/help"/>
  <AppDomains>
    <AppDomain>https://www.contoso.com</AppDomain>
  </AppDomains>
  <Hosts>
    <Host Name="Presentation"/>
  </Hosts>
  <DefaultSettings>
    <SourceLocation DefaultValue="https://localhost:3000/taskpane.html"/>
    <RequestedHeight>400</RequestedHeight>
    <RequestedWidth>400</RequestedWidth>
  </DefaultSettings>
  <Permissions>ReadWriteDocument</Permissions>
</OfficeApp>

之后我尝试验证清单并收到以下错误:

Error #1: 
XML Schema Validation Error: Error found during XML Schema validation.
  - Details: The element 'DefaultSettings' in namespace 'http://schemas.microsoft.com/office/appforoffice/1.1' has invalid child element 'RequestedWidth' in namespace 'http://schemas.microsoft.com/office/appforoffice/1.1'.
  - Line: 25
  - Column: 6

Error #2: 
XML Schema Violation: Your manifest does not adhere to the current set of XML schema definitions for Office Add-in manifests.

我删除了它,尽管它似乎被模块RequestedWidth识别,然后重试。这次清单是有效的。因此,我运行了,我的插件自动添加到了当前幻灯片中。manifestHandlerXml.tsoffice-addin-manifestnpm start

这是我的最终 manifest.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<OfficeApp 
  xmlns="http://schemas.microsoft.com/office/appforoffice/1.1" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0" 
  xsi:type="ContentApp">
  <Id>9e2e38ec-67af-43e6-8aeb-c8c3e22b86bd</Id>
  <Version>1.0.0.0</Version>
  <ProviderName>Contoso</ProviderName>
  <DefaultLocale>en-US</DefaultLocale>
  <DisplayName DefaultValue="my-content-addin"/>
  <Description DefaultValue="A template to get started."/>
  <IconUrl DefaultValue="https://localhost:3000/assets/icon-32.png"/>
  <HighResolutionIconUrl DefaultValue="https://localhost:3000/assets/icon-64.png"/>
  <SupportUrl DefaultValue="https://www.contoso.com/help"/>
  <AppDomains>
    <AppDomain>https://www.contoso.com</AppDomain>
  </AppDomains>
  <Hosts>
    <Host Name="Presentation"/>
  </Hosts>
  <DefaultSettings>
    <SourceLocation DefaultValue="https://localhost:3000/taskpane.html"/>
    <RequestedHeight>400</RequestedHeight>
  </DefaultSettings>
  <Permissions>ReadWriteDocument</Permissions>

</OfficeApp>

如何为我的内容插件指定默认宽度?

如何仅当我单击功能区命令(如默认 TaskPane 演示打开任务窗格)时插入我的插件?

在 Yeoman Taskpane Demo 中,VersionOverrides需要一个 schema xmlns="http://schemas.microsoft.com/office/taskpaneappversionoverrides"。 action 元素的替代方案是什么Control?<Action xsi:type="ShowTaskpane">是在基于内容的插件中吗?

在此处输入图片描述

office-js
  • 1 个回答
  • 20 Views
Martin Hope
Humberto
Asked: 2024-08-29 21:43:50 +0800 CST

重载方法的自动完成参数值的类型推断

  • 6

我正在尝试为通用方法的参数添加一些自动完成支持

 subscribeToTelemetry<T extends keyof TypeMap>(name: T): Stream<TypeMap[T]>;
 subscribeToTelemetry<T extends NonNullable<{}>>(name: EntityName<T>): Stream<T>; 

简而言之,如果没有提供类型,subscribeToTelemetry则应根据名称和一些可用的注入/自动生成类型推断返回类型。此外,应使用可用的注入/自动生成类型提出可能的名称建议。例如,使用以下类型:

type TypeMap = {
    ranger1: RangerTelemetry,
    ranger2: RangerTelemetry,
    mavic2: DroneTelemetry
};

以及以下代码

// should suggest: ['mavic2' | 'ranger2' | 'ranger1'] since no type T is provided 
const myStream1 = r.subscribeToTelemetry('ranger1'); // myStream1: Stream<RangerTelemetry

建议值应为 ['mavic2' | 'ranger2' | 'ranger1'],因为未提供类型 T,并且 myStream1 类型将是Stream<RangerTelemetry>

相反,如果我们提供一个类型subscribeToTelemetry ,并考虑可用的注入/自动生成类型

const entityNames = {
    RangerTelemetry: ['ranger1', 'ranger2', 'ranger3'],
    DroneTelemetry: ['mavic1', 'mavic2', 'mavic3'],
} as const;

和其他一些类型的技巧(参见操场链接),使用以下代码

// should suggest only: ['mavic1' | 'mavic2' | 'mavic3'] since type T is provided as DroneTelemetry,
const myStream3 = r.subscribeToTelemetry<DroneTelemetry>('mavic1');

我们应该建议:['mavic1' | 'mavic2' | 'mavic3'],因为提供了类型DroneTelemetry,但显示的却是 ['mavic1' | 'mavic2' | 'mavic3', 'ranger1', 'ranger2', 'ranger3']。的类型myStream3将是Stream<DroneTelemetry>

我有多个重载方法的签名实现变体,但 subscribeToTelemetry在提供类型时无法提供正确的建议,即使我指定 DroneTelemetry为类型,我总是会得到游骑兵的建议。

class Registry {
    subscribeToTelemetry<T extends keyof TypeMap>(name: T): Stream<TypeMap[T]>;
    subscribeToTelemetry<T extends NonNullable<{}>>(name: EntityName<T>): Stream<T>;
    subscribeToTelemetry<T extends NonNullable<{}>>(name: EntityName<T>): Stream<T> {
        return new Stream<T>(name); 
    }
}

如果有人有任何建议,我将不胜感激

温贝托

完整代码如下:

type DroneTelemetry = { kind: 'DroneTelemetry', batteryLevel: number, velocity: number, location: {latitude: number, longitude: number}}
type RangerTelemetry = { kind: 'RangerTelemetry', velocity: number, location: {latitude: number, longitude: number}}


////// the entity names and type mapping will be autogenerated
const entityNames = {
    RangerTelemetry: ['ranger1', 'ranger2', 'ranger3'],
    DroneTelemetry: ['mavic1', 'mavic2', 'mavic3'],
} as const;

type TypeMap = {
    ranger1: RangerTelemetry,
    ranger2: RangerTelemetry,
    mavic2: DroneTelemetry
};
////////

// Define the types for the keys and values of the mapping
type EntityNames = typeof entityNames;
type EntityKeys = keyof EntityNames;
type EntityValues<T extends EntityKeys> = EntityNames[T][number];

// Define a mapping from type aliases to their corresponding keys
type TypeToKey<T> = T extends { kind: infer K } ? K : never;

type ExtractEntitiesNames<T> = TypeToKey<T> extends keyof EntityNames ? EntityValues<TypeToKey<T>> : never;
type EntityName<T> = ExtractEntitiesNames<T> |  (string  & {});

/////////////////////////////////////////////////////////////////////

class Stream<T> {
    name: string
    constructor(name: string){
        this.name = name
    }
    getLastValue() {
        return {} as T // dummy impl
    }
}

class Registry {
    subscribeToTelemetry<T extends keyof TypeMap>(name: T): Stream<TypeMap[T]>;
    subscribeToTelemetry<T extends NonNullable<{}>>(name: EntityName<T>): Stream<T>;
    subscribeToTelemetry<T extends NonNullable<{}>>(name: EntityName<T>): Stream<T> {
        return new Stream<T>(name); 
    }
}

const r = new Registry();
// should suggest: ['mavic2' | 'ranger2' | 'ranger1'] since no type T is provided // OK
const myStream1 = r.subscribeToTelemetry('ranger1'); // myStream1 type will be Stream<RangerTelemetry>

// should suggest: ['mavic2' | 'ranger2' | 'ranger1'] since no type T is provided // OK
const myStream2 = r.subscribeToTelemetry('ranger2'); // myStream2 type will be Stream<RangerTelemetry>

 // should suggest only: ['mavic1' | 'mavic2' | 'mavic3'] since type T is provided as DroneTelemetry,
 // but ['mavic1' | 'mavic2' | 'mavic3', 'ranger1', 'ranger2', 'ranger3'] is shown instead.                // WRONG
const myStream3 = r.subscribeToTelemetry<DroneTelemetry>('mavic1'); // myStream3 type will be Stream<RangerTelemetry>

这是一个包含完整代码的ts-playground

typescript
  • 1 个回答
  • 43 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve