这是我的html:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="./office-js/dist/office.js"></script>
</head>
<body>
<p id="output">hello</p>
</body>
<script type="text/javascript">
Office.onReady(info => {
if (info.host === Office.HostType.Excel) {
document.getElementById("output").innerHTML = typeof Excel;
} else {
document.getElementById("output").innerHTML = "out of excel";
}
});
</script>
</html>
我发现不仅未定义Excel,Office.js还是在Excel外部加载。我记录了window.external.GetContext,它也是未定义的,它导致“警告:Office.js加载到Office客户端之外”。