Last active
July 12, 2021 08:57
-
-
Save nulIptr/c247598f7254d4cfd6f5b702b47ce758 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: eva log | |
description: Create a new snippet from a blank template. | |
host: EXCEL | |
api_set: {} | |
script: | |
content: | | |
$("#run").click(() => tryCatch(run)); | |
function isNum(char) { | |
return "1234567890".indexOf(char) >= 0; | |
} | |
function getNumber(log, beginIndex) { | |
for (let t = beginIndex; t <= log.length; t++) { | |
if (isNum(log[t])) { | |
continue; | |
} else { | |
return parseInt(log.substr(beginIndex, t)); | |
} | |
} | |
} | |
async function run() { | |
await Excel.run(async (context) => { | |
const sheet = context.workbook.worksheets.getItem("dmlog"); | |
var uRange = sheet.getUsedRange(); | |
uRange.load("address"); | |
uRange.load("rowCount"); | |
await context.sync(); | |
var count = uRange.rowCount; | |
var qRanges = sheet.getRange("I2:I" + count.toString()).load("values"); | |
var bheader = sheet.getRange("H1:H1").load("values"); | |
await context.sync(); | |
var queries = qRanges.values; | |
for (var i = 0; i < queries.length; i++) { | |
if (queries[i] == undefined || queries[i][0].toString() == "") { | |
break; | |
} | |
let log: string = queries[i][0]; | |
let values = []; | |
for (let h = 0; h < bheader.values[0].length; h++) { | |
let s = log.indexOf(bheader.values[0][h]); | |
let single = log.substring(log.indexOf("[", s) + 1, log.indexOf("]", s)) | |
let begin = getNumber(single, 0); | |
let es = single.lastIndexOf("~"); | |
let end = getNumber(single, es + 1); | |
values = [...values, end - begin]; | |
} | |
var bRanges = sheet.getRange("H" + (2 + i).toString() + ":H" + (2 + i).toString()); | |
bRanges.values = [values]; | |
context.sync(); | |
} | |
}); | |
} | |
/** Default helper for invoking an action and handling errors. */ | |
async function tryCatch(callback) { | |
try { | |
await callback(); | |
} catch (error) { | |
// Note: In a production add-in, you'd want to notify the user through your add-in's UI. | |
console.error(error); | |
} | |
} | |
language: typescript | |
template: | |
content: | | |
<button id="run" class="ms-Button"> | |
<span class="ms-Button-label">Run</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