I'm trying to update my Excel add-in to use the workbook SettingCollection instead of the Office.context.document.settings object. The documentation seems to suggest they are functionally equivalent, but with document.settings I can call saveAsync() and see my data persisted (in the PropertyBag in a webextensions.xml).
With ctx.workbook.settings.add('key', 'value'), I can get the settings and get them in the current session, but they don't get added to the webextensions.xml and aren't available on the next open of the add-in.
Is there a version of saveAsync for workbook settings that I'm missing? I assumed context.sync would take care of it, but I haven't had any luck.
Edit: I figured out what was causing my initial issue, but the problem is still there. When I close the browser tab with Excel Online and re-open it with my add-in, the settings are not persisting. Nothing is getting added to webextensions.xml.
Here is an example Excel.run()
window.Excel.run(async ctx => {
ctx.workbook.settings.add('hello', 'world');
await ctx.sync();
let setting = ctx.workbook.settings.getItemOrNullObject('hello');
setting.load('value');
await ctx.sync();
console.log(setting.value);
});
The setting 'hello' sets and exists the next if I relaunch my add-in, but not if I close the file and open my add-in.
there is a bug with the Excel rich API for settings, can you please try the Shared API flavor as a workaround in the meantime...
function createSetting() {
Office.context.document.settings.set("Foo", "bar");
Office.context.document.settings.saveAsync();
}
function readSetting() {
console.log(Office.context.document.settings.get("Foo"));
}
Related
I'm trying to invoke browser control in a Window Form using ChromiumFX framework in the Excel VSTO Addin.
The excel application throws the following alerts and another excel instance gets started.
Sorry, we couldn't find Files\Microsoft.xlsx. Is is possible it was removed, renamed of deleted ?
Sorry, we couldn't find Office\root\Office16\debug.log. Is is possible it was removed, renamed of deleted ?
Although I’m able to load the URL in the Web Browser control but i get the above errors multiple time and every time another instance of excel gets initiated.
I’m invoking the following piece of code after which the alerts start appearing.
var assemblyDir = System.IO.Path.GetDirectoryName(new System.Uri(System.Reflection.Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath);
Environment.CurrentDirectory = System.IO.Path.Combine(assemblyDir, #".");
if (CfxRuntime.PlatformArch == CfxPlatformArch.x64)
CfxRuntime.LibCefDirPath = #"cef\Release64";
else
CfxRuntime.LibCefDirPath = #"cef\Release";
Chromium.WebBrowser.ChromiumWebBrowser.OnBeforeCfxInitialize += ChromiumWebBrowser_OnBeforeCfxInitialize;
ChromiumWebBrowser.OnBeforeCommandLineProcessing += ChromiumWebBrowser_OnBeforeCommandLineProcessing;
Chromium.WebBrowser.ChromiumWebBrowser.Initialize();
Any suggestions on what i might be doing wrong ? Or what piece of code i’m missing ?
Looking through the docs, I wasn't able to find a way to view everything currently stored in settings. I'm trying to debug some memory issues, and I'm worried that giant objects have been stored in the document settings (potentially from other add-ins that have worked on this same workbook).
Is there a way to see everything stored in Office.context.document.settings without using the .get method (which requires you to know the name of the property you want)?
Thanks for your help
Which host are you looking for? For Word and Excel, there is an API to get all settings. For Word, document.settings and for Excel use workbook.settings. Other hosts don't support this API.
await Excel.run(async (context) => {
const settings = context.workbook.settings.load();
settings.load("items");
await context.sync();
for (let i = 0; i < settings.items.length; i++) {
console.log(JSON.stringify(settings.items[i])) + "\n";
}
});
For Word, just replace context.workbook with context.document.
It also wouldn't help you here since it also only surfaces settings from the current add-in. Any settings created by other add-ins are inaccessible from yours.
Your best bet is to decompress the .docx file (it's just a Zip file) and inspect the contents directly. The settings are stored as XML in the \xl\webextensions folder.
Excel 2016 (Office 365) 32 bits, 16.0.6965.2115, Visual Studio 14.0.25425.01 Update 3
I'm quite sure the statement below used to work, but now it doesn't work anymore:
var range = ctx.workbook.names.getItem("Countries").getRange();
I get an error stating that there is no support for getRange method, but it should be supported as documented here.
What am I'm doing wrong?
--- EDIT: this is the code I'm using ---
function paintRange() {
Excel.run(function (ctx) {
var range = ctx.workbook.names.getItem("Countries").getRange();
range.format.fill = "green";
return ctx.sync();
}).catch(function (error) {
app.showNotification("Error", error);
})
}
paintRange is attached to a button. There is a global scope defined name called Countries.
I don't have any more details of the error besides the one I mentioned, I also tried opening the quick watch window to get more clues.
UPDATE: The issue is fixed with an update to the CDN. You should be able to use namedItem.getRange() now. Thanks for reporting the issue, and allowing us to do a quick turn-around on it.
================
Felipe, looks like you're absolutely right. This is definitely a bug. Let me talk to the right folks to get this regression fixed as soon as we can. I'll see if we can put in some processes to avoid this in the future, as well.
From an immediate-workaround perspective, two options:
Use the BETA CDN (esp if it's for an in-development add-in, rather than a production one). That URL is: https://appsforoffice.microsoft.com/lib/beta/hosted/office.js
Do a temporarily filling in of the inadvertently-removed getRange functionality. Inside of Office.initialize, include the following code:
if (!Excel.NamedItem.prototype.getRange) {
Excel.NamedItem.prototype.getRange=function () {
return new Excel.Range(this.context,
OfficeExtension.ObjectPathFactory.createMethodObjectPath(
this.context, this, "GetRange",
OfficeExtension.OperationType.Read, [], false, true, null
)
);
};
}
The workaround in #2 should not cause harm even after the functionality is restored, but I would none-the-less recommend making a mental note to remove this after we've fixed the issue. I'll update this thread once we have fixed the underlying bug, hopefully within a weeks' time (as a very rough estimate, pending any complications that might delay it).
Thanks for bringing it to our attention -- both the individual bug, and the underlying process that let the regression to this one API go unnoticed.
Since, I could not find any satifying answer on the web for this question, I put forth it in Stackoverflow. I use activexscript to manipulate Excel, Outlook. But, even after I runexcelobj.Quit() at the end, I see an EXCEL.EXE still running in the task manager.
I tried using excelobj.Application.Quit() (as mentioned by some post in stackoverflow)also did not resolve the problem.
Can somebody help me with this??
Here's one way the application goes away in JScript:
// WScript.CreateObject for cscript.exe or wscript.exe
var excel = new ActiveXObject("Excel.Application");
// ...
excel.Quit();
// null out EVERY reference to Excel objects
excel = null;
CollectGarbage();
Following Copy/Paste code not working in Chrome Extension,
I need to write Chrome Extension that copy and paste data using clipboard.
I write following code in Backgroung.html page, but its not working.
function buttonClick(){
document.getElementById('initialText').select();
chrome.experimental.clipboard.executeCopy(1, function() {
alert("Copy");
document.getElementById('nameText').focus();
chrome.experimental.clipboard.executePaste(1, function() {
alert("Paste");
});
});
}
As of Chrome 13, clipboard access is no longer experimental.
The commands are now document.execCommand('paste'), document.execCommand('copy') and document.execCommand('cut').
However, permissions need to be added to your manifest: "clipboardRead" and "clipboardWrite".
Try implementing the above and see how you get on.
To eliminate the obvious; have you added the "experimental" permission to your manifest and are you using the latest dev build of Chrome as listed in the official documentation?
Otherwise, I'm not sure what may help you as I don't use the experimental API due to them not being usable in production. There is a workaround for copying without using the experimental API (using an input field and document.execCommand) but I'm not sure how to paste without it.
EDIT:
I've just noticed that experimental.clipboard is not longer listed on the experimental API page. It may be that this namespace has been deprecated/abandoned as can happen when using the experimental API. A simple test for this would be inserting;
console.log(typeof chrome.experimental.clipboard);
console.log(typeof chrome.experimental.clipboard.executeCopy);
console.log(typeof chrome.experimental.clipboard.executePaste);
Which should output the following the console for your background page;
> object
> function
> function