基于现有表格用Excel JavaScript API开发Add-in的调试问题
Excel JavaScript Add-in 调试打开空白工作簿的解决方法
问题
我基于现有工资表工作簿开发Excel Add-in,用Excel JavaScript API实现提取指定单元格数据并在新工作簿重新格式化的功能。但运行npm start(实际执行office-addin-debugging start manifest.xml)时,总是打开空白工作簿。我猜要改manifest.xml但不知道怎么操作,不用Visual Studio解决方案,也没找到相关指引,求帮助。
我的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" xmlns:ov="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="TaskPaneApp"> <Id>3b1c4cad-3081-4941-9176-4ba875ffa3b5</Id> <Version>1.0.0.0</Version> <ProviderName>Contoso</ProviderName> <DefaultLocale>en-US</DefaultLocale> <DisplayName DefaultValue="Convert"/> <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="Workbook"/> </Hosts> <DefaultSettings> <SourceLocation DefaultValue="https://localhost:3000/taskpane.html"/> </DefaultSettings> <Permissions>ReadWriteDocument</Permissions> <VersionOverrides xmlns="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="VersionOverridesV1_0"> <Hosts> <Host xsi:type="Workbook"> <DesktopFormFactor> <GetStarted> <Title resid="GetStarted.Title"/> <Description resid="GetStarted.Description"/> <LearnMoreUrl resid="GetStarted.LearnMoreUrl"/> </GetStarted> <FunctionFile resid="Commands.Url"/> <ExtensionPoint xsi:type="PrimaryCommandSurface"> <OfficeTab id="TabHome"> <Group id="CommandsGroup"> <Label resid="CommandsGroup.Label"/> <Icon> <bt:Image size="16" resid="Icon.16x16"/> <bt:Image size="32" resid="Icon.32x32"/> <bt:Image size="80" resid="Icon.80x80"/> </Icon> <Control xsi:type="Button" id="TaskpaneButton"> <Label resid="TaskpaneButton.Label"/> <Supertip> <Title resid="TaskpaneButton.Label"/> <Description resid="TaskpaneButton.Tooltip"/> </Supertip> <Icon> <bt:Image size="16" resid="Icon.16x16"/> <bt:Image size="32" resid="Icon.32x32"/> <bt:Image size="80" resid="Icon.80x80"/> </Icon> <Action xsi:type="ShowTaskpane"> <TaskpaneId>ButtonId1</TaskpaneId> <SourceLocation resid="Taskpane.Url"/> </Action> </Control> <Control xsi:type="Button" id="ToggleProtection"> <Label resid="ProtectionButtonLabel" /> <Supertip> <Title resid="ProtectionButtonLabel" /> <Description resid="ProtectionButtonToolTip" /> </Supertip> <Icon> <bt:Image size="16" resid="Icon.16x16"/> <bt:Image size="32" resid="Icon.32x32"/> <bt:Image size="80" resid="Icon.80x80"/> </Icon> <Action xsi:type="ExecuteFunction"> <FunctionName>toggleProtection</FunctionName> </Action> </Control> </Group> </OfficeTab> </ExtensionPoint> </DesktopFormFactor> </Host> </Hosts> <Resources> <bt:Images> <bt:Image id="Icon.16x16" DefaultValue="https://localhost:3000/assets/icon-16.png"/> <bt:Image id="Icon.32x32" DefaultValue="https://localhost:3000/assets/icon-32.png"/> <bt:Image id="Icon.80x80" DefaultValue="https://localhost:3000/assets/icon-80.png"/> </bt:Images> <bt:Urls> <bt:Url id="GetStarted.LearnMoreUrl" DefaultValue="https://go.microsoft.com/fwlink/?LinkId=276812"/> <bt:Url id="Commands.Url" DefaultValue="https://localhost:3000/commands.html"/> <bt:Url id="Taskpane.Url" DefaultValue="https://localhost:3000/taskpane.html"/> </bt:Urls> <bt:ShortStrings> <bt:String id="GetStarted.Title" DefaultValue="Get started with your sample add-in!"/> <bt:String id="CommandsGroup.Label" DefaultValue="Commands Group"/> <bt:String id="TaskpaneButton.Label" DefaultValue="Show Taskpane"/> <bt:String id="ProtectionButtonLabel" DefaultValue="Toggle Worksheet Protection" /> </bt:ShortStrings> <bt:LongStrings> <bt:String id="GetStarted.Description" DefaultValue="Your sample add-in loaded succesfully. Go to the HOME tab and click the 'Show Taskpane' button to get started."/> <bt:String id="TaskpaneButton.Tooltip" DefaultValue="Click to Show a Taskpane"/> <bt:String id="ProtectionButtonToolTip" DefaultValue="Click to protect or unprotect the current worksheet." /> </bt:LongStrings> </Resources> </VersionOverrides> </OfficeApp>
解决步骤
1. 调整调试命令,指定目标工作簿
不用修改manifest.xml,直接改npm start对应的命令。在office-addin-debugging start后加上你的工资表文件路径:
office-addin-debugging start manifest.xml "C:\你的路径\工资表.xlsx"
然后打开项目里的package.json,找到scripts里的start命令,把原来的内容替换成上面这条。之后运行npm start就会直接打开指定的工资表并加载你的Add-in。
2. 关于manifest.xml的说明
你当前的manifest.xml配置没有问题,它只是定义了Add-in的基本信息、命令栏按钮和功能入口。调试时打开空白工作簿是office-addin-debugging工具的默认行为,和manifest无关。目前无法通过manifest配置直接关联特定工作簿,只能通过调试命令指定目标文件。
内容的提问来源于stack exchange,提问作者snowcap420
相关产品推荐
相关产品推荐

