Microsoft Word 中的某处存在隐藏状态,即使重新启动后该状态仍然存在。要重现该错误,您几乎需要新电脑.
让我解释一下我是如何在... 1 周后让它工作的。
首先从office-js 生成器开始。
yo office
,我为此选择了打字稿。
修改 src/taskpane/taskpane.ts 如下:
export async function run() {
return Word.run(async context => {
/**
* Insert your Word code here
*/
// insert a paragraph at the end of the document.
const paragraph = context.document.body.insertParagraph("Hello World", Word.InsertLocation.end);
// change the paragraph color to blue.
paragraph.font.color = "blue";
// Add these two lines
Office.context.document.settings.set("Office.AutoShowTaskpaneWithDocument", true);
Office.context.document.settings.saveAsync();
// Technically should wait, but doesn't matter.
await context.sync();
});
修改manifest.xml如下:
代替ButtonId1
with Office.AutoShowTaskpaneWithDocument
<Action xsi:type="ShowTaskpane">
<TaskpaneId>Office.AutoShowTaskpaneWithDocument</TaskpaneId>
<SourceLocation resid="Taskpane.Url"/>
</Action>
正常启动项目。npm run start
单击运行按钮触发自动打开文件的创建。
将文件保存在某处。
重新打开它以验证其是否有效。有趣的是,当我单击“显示任务窗格”按钮时,它创建了一个相同的任务窗格。这是一个错误,但对我有用。毕竟是为了测试目的。
为了证明文件的问题确实是隐藏状态:
将存储库克隆到新电脑, npm run start
,将文件复制过来。
运行该文件,您将遇到与我在原始帖子中遇到的相同问题。