I would like to save the initial state of a workbook (or an Excel application) in the beginning, so that I could always get back to it regardless of modification on the workbook by my Add-in.
I tried some following code in Home.js
:
(function() {
"use strict";
Office.initialize = function(reason) {
$(document).ready(function() {
app.initialize();
initial();
$('#getInitial').click(getInitial);
});
};
var ctxInitial;
function initial () {
ctxInitial = new Excel.RequestContext();
}
function getInitial() {
Excel.run(function () {
var wSheetName = 'Sheet1';
var worksheet = ctxInitial.workbook.worksheets.getItem(wSheetName);
var usedRange = worksheet.getUsedRange();
usedRange.load(["values"]);
return ctxInitial.sync().then(function() {
document.getElementById("area").value += usedRange.values.toString();
});
});
}
})();
In the very beginning, my tests prints well the initial values of the worksheet. However, after some manual modification on some cell values, getInitial
prints the current state of the worksheet rather than the initial values.
Does anyone know what's the best practice to realise this?