Last active
October 11, 2019 07:00
-
-
Save jiju-MS/a6683f14d407a96893cec59b91cd3540 to your computer and use it in GitHub Desktop.
Create a new snippet from a blank template.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Blank snippet (6) | |
description: Create a new snippet from a blank template. | |
host: EXCEL | |
api_set: {} | |
script: | |
content: | | |
var fontSize; | |
var numFmt; | |
var fillColor = "#FFFFFF"; | |
var fontColor; | |
var fontBold; | |
var barChartColor = "#4472C4"; | |
var mapChartColor = "#595959"; | |
var HeightNum = []; | |
var WidthNum = []; | |
var Height = 100; | |
var Width = 135; | |
var rate = 0.9; | |
var randomIndex = 0; | |
var init = false; | |
var num = 5; | |
var eventHandler; | |
$("#Stop").click(function() { | |
if (!eventHandler) { | |
return; | |
} | |
Excel.run(eventHandler.context, async function(context) { | |
eventHandler.remove(); | |
await context.sync(); | |
}); | |
}); | |
$("#Next").click(function() { | |
num = 4; | |
randomIndex = 0; | |
registerEvent(); | |
}); | |
async function registerEvent() { | |
await Excel.run(async function(context) { | |
var worksheet1 = context.workbook.worksheets.getItem("Sheet" + num.toString()); | |
var worksheet2 = context.workbook.worksheets.getItem("Sheet2"); | |
//var worksheet3 = context.workbook.worksheets.getItem("Sheet3"); | |
eventHandler = worksheet2.onFormatChanged.add(handleDataChange); | |
await context.sync(); | |
console.log("Event handler successfully onFormatChanged event in the worksheet."); | |
}); | |
} | |
async function handleDataChange(event) { | |
//console.log("success"); | |
setTimeout(async function() { | |
await Excel.run(async function(ctx) { | |
await ctx.sync(); | |
// if (!init) { | |
// var worksheet2 = ctx.workbook.worksheets.getItem("Sheet2"); | |
// await ctx.sync(); | |
// for (var i = 0; i < Height * rate; i++) { | |
// var nextcell = worksheet2.getCell(0, i); | |
// nextcell.load("format/fill/color"); | |
// await ctx.sync(); | |
// nextcell.format.fill.color = "#FFFFFF"; | |
// } | |
// init = true; | |
// } | |
var worksheet1 = ctx.workbook.worksheets.getItem("Sheet" + num.toString()); | |
var worksheet2 = ctx.workbook.worksheets.getItem("Sheet2"); | |
//var nextrange = worksheet2.getRange(event.address); | |
//var range = worksheet1.getRange(event.address); | |
//console.log(event.address); | |
var nextWidth = WidthNum[randomIndex]; | |
var nextHeight = HeightNum[randomIndex]; | |
//console.log("(" + WidthNum[randomIndex] + "," + HeightNum[randomIndex] + ")"); | |
var nextcell = worksheet2.getCell(nextWidth, nextHeight); | |
var cell = worksheet1.getCell(nextWidth, nextHeight); | |
randomIndex++; | |
if (randomIndex >= Height * Width) return; | |
if (randomIndex % 100 == 0) { | |
console.log(randomIndex); | |
} | |
nextcell.load("format/fill/color"); | |
cell.load("values"); | |
//nextDest.load("format/fill/color"); | |
//nextData.load("values"); | |
await ctx.sync(); | |
//dest.format.fill.color = data.values.toString(); | |
//console.log(range.values[0][0]); | |
nextcell.format.fill.color = cell.values[0][0].toString(); | |
await ctx.sync(); | |
}); | |
}, 20); | |
} | |
run(); | |
async function run() { | |
for (var i = 0; i < Height; ++i) { | |
for (var j = 0; j < Width; ++j) { | |
HeightNum[i * Width + j] = i; | |
WidthNum[i * Width + j] = j; | |
} | |
} | |
for (var i = 0; i < Height * Width * 3; ++i) { | |
var index = Math.floor(Math.random() * Height * Width); | |
var temp = HeightNum[index]; | |
HeightNum[index] = HeightNum[0]; | |
HeightNum[0] = temp; | |
var temp1 = WidthNum[index]; | |
WidthNum[index] = WidthNum[0]; | |
WidthNum[0] = temp1; | |
} | |
await registerEvent(); | |
} | |
language: typescript | |
template: | |
content: |- | |
<button id="run" class="ms-Button"> | |
<span class="ms-Button-label">Run</span> | |
</button> | |
<button id="Stop" class="ms-Button"> | |
<span class="ms-Button-label">Stop</span> | |
</button> | |
<button id="Next" class="ms-Button"> | |
<span class="ms-Button-label">Next</span> | |
</button> | |
language: html | |
style: | |
content: |- | |
section.samples { | |
margin-top: 20px; | |
} | |
section.samples .ms-Button, section.setup .ms-Button { | |
display: block; | |
margin-bottom: 5px; | |
margin-left: 20px; | |
min-width: 80px; | |
} | |
language: css | |
libraries: | | |
https://appsforoffice.microsoft.com/lib/1/hosted/office.js | |
@types/office-js | |
office-ui-fabric-js@1.4.0/dist/css/fabric.min.css | |
office-ui-fabric-js@1.4.0/dist/css/fabric.components.min.css | |
core-js@2.4.1/client/core.min.js | |
@types/core-js | |
jquery@3.1.1 | |
@types/jquery@3.3.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: FormatChanged-ShowImage-Demo | |
description: Create a new snippet from a blank template. | |
host: EXCEL | |
api_set: {} | |
script: | |
content: | | |
var fontSize; | |
var numFmt; | |
var fillColor = "#FFFFFF"; | |
var fontColor; | |
var fontBold; | |
var barChartColor = "#4472C4"; | |
var mapChartColor = "#595959"; | |
var HeightNum = []; | |
var WidthNum = []; | |
var Height = 100; | |
var Width = 135; | |
var rate = 0.9; | |
var randomIndex = 0; | |
var init = false; | |
var num = 5; | |
var eventHandler; | |
$("#Stop").click(function() { | |
if (!eventHandler) { | |
return; | |
} | |
Excel.run(eventHandler.context, async function(context) { | |
eventHandler.remove(); | |
await context.sync(); | |
}); | |
}); | |
$("#Next").click(function() { | |
num = 4; | |
randomIndex = 0; | |
registerEvent(); | |
}); | |
async function registerEvent() { | |
await Excel.run(async function(context) { | |
var worksheet1 = context.workbook.worksheets.getItem("Sheet" + num.toString()); | |
var worksheet2 = context.workbook.worksheets.getItem("Sheet2"); | |
//var worksheet3 = context.workbook.worksheets.getItem("Sheet3"); | |
eventHandler = worksheet2.onFormatChanged.add(handleDataChange); | |
await context.sync(); | |
console.log("Event handler successfully onFormatChanged event in the worksheet."); | |
}); | |
} | |
async function handleDataChange(event) { | |
//console.log("success"); | |
setTimeout(async function() { | |
await Excel.run(async function(ctx) { | |
await ctx.sync(); | |
// if (!init) { | |
// var worksheet2 = ctx.workbook.worksheets.getItem("Sheet2"); | |
// await ctx.sync(); | |
// for (var i = 0; i < Height * rate; i++) { | |
// var nextcell = worksheet2.getCell(0, i); | |
// nextcell.load("format/fill/color"); | |
// await ctx.sync(); | |
// nextcell.format.fill.color = "#FFFFFF"; | |
// } | |
// init = true; | |
// } | |
var worksheet1 = ctx.workbook.worksheets.getItem("Sheet" + num.toString()); | |
var worksheet2 = ctx.workbook.worksheets.getItem("Sheet2"); | |
//var nextrange = worksheet2.getRange(event.address); | |
//var range = worksheet1.getRange(event.address); | |
//console.log(event.address); | |
var nextWidth = WidthNum[randomIndex]; | |
var nextHeight = HeightNum[randomIndex]; | |
//console.log("(" + WidthNum[randomIndex] + "," + HeightNum[randomIndex] + ")"); | |
var nextcell = worksheet2.getCell(nextWidth, nextHeight); | |
var cell = worksheet1.getCell(nextWidth, nextHeight); | |
randomIndex++; | |
if (randomIndex >= Height * Width) return; | |
if (randomIndex % 100 == 0) { | |
console.log(randomIndex); | |
} | |
nextcell.load("format/fill/color"); | |
cell.load("values"); | |
//nextDest.load("format/fill/color"); | |
//nextData.load("values"); | |
await ctx.sync(); | |
//dest.format.fill.color = data.values.toString(); | |
//console.log(range.values[0][0]); | |
nextcell.format.fill.color = cell.values[0][0].toString(); | |
await ctx.sync(); | |
}); | |
}, 20); | |
} | |
run(); | |
async function run() { | |
for (var i = 0; i < Height; ++i) { | |
for (var j = 0; j < Width; ++j) { | |
HeightNum[i * Width + j] = i; | |
WidthNum[i * Width + j] = j; | |
} | |
} | |
for (var i = 0; i < Height * Width * 3; ++i) { | |
var index = Math.floor(Math.random() * Height * Width); | |
var temp = HeightNum[index]; | |
HeightNum[index] = HeightNum[0]; | |
HeightNum[0] = temp; | |
var temp1 = WidthNum[index]; | |
WidthNum[index] = WidthNum[0]; | |
WidthNum[0] = temp1; | |
} | |
await registerEvent(); | |
} | |
language: typescript | |
template: | |
content: |- | |
<button id="run" class="ms-Button"> | |
<span class="ms-Button-label">Run</span> | |
</button> | |
<button id="Stop" class="ms-Button"> | |
<span class="ms-Button-label">Stop</span> | |
</button> | |
<button id="Next" class="ms-Button"> | |
<span class="ms-Button-label">Next</span> | |
</button> | |
language: html | |
style: | |
content: |- | |
section.samples { | |
margin-top: 20px; | |
} | |
section.samples .ms-Button, section.setup .ms-Button { | |
display: block; | |
margin-bottom: 5px; | |
margin-left: 20px; | |
min-width: 80px; | |
} | |
language: css | |
libraries: | | |
https://appsforoffice.microsoft.com/lib/1/hosted/office.js | |
@types/office-js | |
office-ui-fabric-js@1.4.0/dist/css/fabric.min.css | |
office-ui-fabric-js@1.4.0/dist/css/fabric.components.min.css | |
core-js@2.4.1/client/core.min.js | |
@types/core-js | |
jquery@3.1.1 | |
@types/jquery@3.3.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment