Excel 插件项目、office-js、VS Code、智能不适用于使用 Javascript 的 React 项目 按照下面的建议创建 https://learn.microsoft.com/en-us/office/dev/add-ins/quickstarts/excel-quickstart-jquery?tabs=yeomangenerator
按照
中的建议我尝试过以下方法。 通过将 tsconfig.json 文件添加到加载项解决方案中 Web 应用程序项目的根目录来使用 Office.js 的在线版本。该文件应包含以下内容。 { “编译器选项”:{ "allowJs": true, // 这些设置也适用于 JavaScript 文件。 "noEmit": true // 不编译该项目中的 JS(或 TS)文件。 }, “排除”: [ "node_modules", // 不要包含在“node_modules”下找到的任何 JavaScript。 "Scripts/Office/1" // 禁止从 Office NuGet 包加载所有 JavaScript 文件。 ], “类型获取”:{ "enable": true, // 启用自动获取检测到的 JavaScript 库的类型定义。 "include": [ "office-js" ] // 确保获取“Office-js”类型定义。 } }
我还做了 npm install -g @types/office-js ,不确定这是否有帮助,因为我的代码不在打字稿中
我有 github copilot,我禁用了它并尝试过,以防发生冲突
我期待着
从 'axios' 导入 axios;
export const updateOrAddScenarioRecords = async (context, tableName) => { console.log("正在更新或添加场景记录...");
const response = await axios.get(`http://localhost:3001/api/fetchdata/${tableName}`);
const apiData = response.data;
await Excel.run(async (localContext) => {
const sheet = localContext.workbook.worksheets.getItem(tableName);
const table = sheet.tables.getItem(tableName);
// Remove any existing color formatting
const tableRange= table. ---- here it tells me what are the valid functions, properties etc. like in VBA
请大家帮忙指导,期待中谢谢
当你这样做时它就会起作用 C:\Node\ITSMDashboard\ITSMDashboard_React> npm install @types/office-js --save-dev 当 PS C:\Node\ITSMDashboard\ITSMDashboard_React\MyFirstExcelAddin> npm install @types/office-js --save-dev 我的实际项目位于 MyFirstExcelAddin 时不起作用,当我刚刚在此处安装时,typescipt intellisense 正在工作,但是为了让 javascript 智能以某种方式工作,我必须向上一级 ITSMDashboard_React ,它只不过是我在 VScode 中打开并安装在那里的文件夹。不知道为什么。但它可以工作,而且我对此很陌生,所以如果有人可以帮助我理解为什么那会很棒