Skip to content

Instantly share code, notes, and snippets.

View davecra's full-sized avatar
💭
Coding for arrays

David E. Craig davecra

💭
Coding for arrays
View GitHub Profile
@davecra
davecra / SendCustomXmlPartMessage.js
Created June 15, 2020 19:55
This is the code from a Task Pane Add-in that sends a message to a Content Add-in via a CustomXMLPart
const ns = "http://pfe.microsoft.com/excelpoc/1.0";
const xml = "<message xmlns='http://pfe.microsoft.com/excelpoc/1.0'>" +
"<sentby>[who]</sentby>" +
"<info>[data]</info>" +
"</message>";
const from_tp = "TASKPANE ADD-IN";
function sendMessage() {
Excel.run(function(context) {
var data = xml.replace("[who]", from_tp).replace("[data]", "This message is coming from the taskpane.");
const customXmlPart = context.workbook.customXmlParts.add(data);
@davecra
davecra / ContentAddInReadCustomXmlPart.js
Last active June 15, 2020 20:07
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
Office.initialize = function(reason) {
// background thread checker
window.setInterval(() => { checkForPart(); }, 1000);
}
const ns = "http://pfe.microsoft.com/excelpoc/1.0";
const xml = "<message xmlns='http://pfe.microsoft.com/excelpoc/1.0'>" +
"<sentby>[who]</sentby>" +
"<info>[data]</info>" +
"</message>";
@davecra
davecra / DetectUserPrintInOutlook.cs
Created June 5, 2020 17:35
Using a background thread and Windows API's in Outlook, we can detect when the user has opened the Print tab in the backstage
[DllImport("user32.dll")]
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
davecra / plugins.js
Created May 29, 2020 20:12
Plugins for all OfficeJS Parts
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
davecra / entry.js
Created May 29, 2020 20:08
Web Pack Entry
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
davecra / webpack _required.js
Last active May 29, 2020 19:59
Required code for web pack to work in a project
/*************************************************/
/* REQUIRED BY WEB PACK - DO NOT DELETE */
/*************************************************/
function getGlobal() {
return typeof self !== "undefined"
? self
: typeof window !== "undefined"
? window
: typeof global !== "undefined"
? global
@davecra
davecra / Manifest.xml
Last active May 23, 2020 21:34
Updated simple manifest for localhost
<?xml version="1.0" encoding="UTF-8"?>
<OfficeApp
xmlns="http://schemas.microsoft.com/office/appforoffice/1.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0"
xmlns:ov="http://schemas.microsoft.com/office/taskpaneappversionoverrides"
xsi:type="TaskPaneApp">
<Id>5226365f-62d0-435f-a4af-cc6a7bd753b2</Id>
<Version>1.0.0.1</Version>
<ProviderName>TheOfficeContext.com</ProviderName>
@davecra
davecra / easyewshtmlscriptline.html
Created May 5, 2020 15:11
Script line for easyEws CDN
<script type="text/javascript" src="node_modules/easyews/easyews.min.js"></script>
@davecra
davecra / NonModalMessageBox.cs
Last active May 1, 2020 19:59
A C# Library that provides an Asynchronous MessageBox
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.
@davecra
davecra / modes_gist.ps1
Created April 26, 2020 22:25
Microsoft Office Development Environment Setup Script Gist - https://github.com/davecra/modes
Add-Type -assembly "system.io.compression.filesystem";$vscode_url = "https://aka.ms/win32-x64-user-stable";$vscode_output = $env:USERPROFILE + "\downloads\vscode.exe";$node_url = "https://nodejs.org/dist/latest/win-x64/node.exe";$node_output = $env:USERPROFILE + "\downloads\node.exe";$node_install_path = $env:USERPROFILE + "\node";$npm_url = "https://nodejs.org/dist/npm/npm-1.4.9.zip";$npm_output = $env:USERPROFILE + "\downloads\npm.zip"
Invoke-WebRequest -Uri $vscode_url -OutFile $vscode_output
Invoke-WebRequest -Uri $node_url -OutFile $node_output
Invoke-WebRequest -Uri $npm_url -OutFile $npm_output
Start-Process -FilePath $vscode_output -ArgumentList ('/VERYSILENT', '/MERGETASKS=!runcode') -Wait
md $node_install_path
copy $node_output $node_install_path
[io.compression.zipfile]::ExtractToDirectory($npm_output, $node_install_path)
[Environment]::SetEnvironmentVariable("Path", [Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::User) + ";" + $node_install_path, [EnvironmentVariableTarg