Skip to content

Instantly share code, notes, and snippets.

Coding for arrays

David E. Craig davecra

Coding for arrays
View GitHub Profile
davecra / getUsername.js
Created Jul 27, 2020
Gets the username for the current user using the SSO API
View getUsername.js
export async function getUserName() {
try {
let tokenData = await OfficeRuntime.auth.getAccessToken({ allowSignInPrompt: false, forMSGraphAccess: true });
var parts = tokenData.split(".");
var token = JSON.parse(atob(parts[1]));
return token.preferred_username;
catch (exception) {
davecra / SendCustomXmlPartMessage.js
Created Jun 15, 2020
This is the code from a Task Pane Add-in that sends a message to a Content Add-in via a CustomXMLPart
View SendCustomXmlPartMessage.js
const ns = "";
const xml = "<message xmlns=''>" +
"<sentby>[who]</sentby>" +
"<info>[data]</info>" +
const from_tp = "TASKPANE ADD-IN";
function sendMessage() { {
var data = xml.replace("[who]", from_tp).replace("[data]", "This message is coming from the taskpane.");
const customXmlPart = context.workbook.customXmlParts.add(data);
davecra / ContentAddInReadCustomXmlPart.js
Last active Jun 15, 2020
This is a function from a Content Add-in looks for a specific customXMLPart in the document as a message from a TaskPane Add-in
View ContentAddInReadCustomXmlPart.js
Office.initialize = function(reason) {
// background thread checker
window.setInterval(() => { checkForPart(); }, 1000);
const ns = "";
const xml = "<message xmlns=''>" +
"<sentby>[who]</sentby>" +
"<info>[data]</info>" +
davecra / DetectUserPrintInOutlook.cs
Created Jun 5, 2020
Using a background thread and Windows API's in Outlook, we can detect when the user has opened the Print tab in the backstage
View DetectUserPrintInOutlook.cs
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);
/// <summary>
/// Startup for Outlook Add-in
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ThisAddIn_Startup(object sender, System.EventArgs e)
davecra / plugins.js
Created May 29, 2020
Plugins for all OfficeJS Parts
View plugins.js
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
filename: "taskpane.html",
template: "./src/dialogs/taskpane.html",
chunks: ["polyfill", "common", "shared", "taskpane"]
new HtmlWebpackPlugin({
filename: "dialog.html",
template: "./src/dialogs/dialog.html",
davecra / entry.js
Created May 29, 2020
Web Pack Entry
View entry.js
entry: {
polyfill: "@babel/polyfill",
dialog: "./src/dialogs/dialog.js",
commands: "./src/commands/commands.js",
shared: "./src/common/shared.js",
common: "./src/common/common.js",
taskpane: "./src/taskpane/taspane.js"
davecra / webpack _required.js
Last active May 29, 2020
Required code for web pack to work in a project
View webpack _required.js
function getGlobal() {
return typeof self !== "undefined"
? self
: typeof window !== "undefined"
? window
: typeof global !== "undefined"
? global
davecra / Manifest.xml
Last active May 23, 2020
Updated simple manifest for localhost
View Manifest.xml
<?xml version="1.0" encoding="UTF-8"?>
davecra / easyewshtmlscriptline.html
Created May 5, 2020
Script line for easyEws CDN
View easyewshtmlscriptline.html
<script type="text/javascript" src="node_modules/easyews/easyews.min.js"></script>
davecra / NonModalMessageBox.cs
Last active May 1, 2020
A C# Library that provides an Asynchronous MessageBox
View NonModalMessageBox.cs
using System;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
namespace NonModalMessageBox
/// <summary>
/// Provides an asyncronous MessageBox. You can use this static class to
/// present a message to the usser while your code can continue to run.