Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Coding for arrays

David E. Craig davecra

💭
Coding for arrays
View GitHub Profile
@davecra
davecra / getHost.js
Created Jul 3, 2017
Gets the host application name
View getHost.js
var current;
app.hostTypes = { Word :"Word", PowerPoint :"PowerPoint", Excel :"Excel"};
app.getHost = function () {
if (current == null) {
if (Office.context.requirements.isSetSupported('WordApi')) {
current = app.hostTypes.Word;
} else if (Office.context.requirements.isSetSupported('ExcelApi')) {
current = app.hostTypes.Excel;
} else {
var host = $.urlParam("_host_Info");
@davecra
davecra / getMailType.js
Created Jul 3, 2017
Determines if the mail item is a new mail, reply or forward
View getMailType.js
/// getMailType()
/// This function determines the type of email item currently being composed
/// - If it is a new item, it returns "New"
/// - If it is a reply, it return "Reply"
/// - If it is a Forward it returns "Forward"
/// - And if it cannot determine, it returns "UnknownReplyOrForward"
/// This accepts a function that is called with the resulting value.
function getMailType(returnFunction) {
// get the conversation ID - if it exists
var id = Office.cast.item.toItemCompose(Office.context.mailbox.item).conversationId;
@davecra
davecra / makeAjaxCall.js
Created Jul 3, 2017
Helper function to call a web service
View makeAjaxCall.js
// Helper function to call the web service controller
app.makeAjaxCall = function (command, params, callback, error) {
var dataToPassToService = {
Command: command,
Params: params
};
$.ajax({
url: '../../api/WebService',
type: 'POST',
data: JSON.stringify(dataToPassToService),
@davecra
davecra / OfficeControllerWebService.cs
Created Jul 3, 2017
Web Service Controller for an OfficeJS Add-in
View OfficeControllerWebService.cs
/// <summary>
/// CORE SERVICE FUNCTION
/// This function will take a web request which will contain the command the caller wants
/// to initate and then the paramaters needed for that call. We enter a SELECT statement
/// below to determine the command given and we then call the proper helper function
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpPost()]
public WebServiceResponse WebService(WebServiceRequest request)
@davecra
davecra / sendPlainTextEmailWithAttachment.js
Created Jul 3, 2017
creates a new emails message with a single attachment and sends it
View sendPlainTextEmailWithAttachment.js
// PUBLIC: creates a new emails message with a single attachment and sends it
// RETURNS: 'success' is compelted successfully
easyEws.sendPlainTextEmailWithAttachment = function (subject, body, to, attachmentName, attachmentMime, successCallback, errorCallback) {
var soap = '<m:CreateItem MessageDisposition="SendAndSaveCopy">' +
' <m:Items>' +
' <t:Message>' +
' <t:Subject>' + subject + '</t:Subject>' +
' <t:Body BodyType="Text">' + body + '</t:Body>' +
' <t:Attachments>' +
' <t:ItemAttachment>' +
@davecra
davecra / sample.js
Created Jul 3, 2017
Sample to submit email with an attachment
View sample.js
// Loads the form items to attach to events
function loadForm() {
$("#forward-button").click(function () {
getCurrentMessage();
});
}
// This function handles the click event of the sendNow button.
// It retrieves the current mail item, so that we can get its itemId property
// ans also get the MIME content
@davecra
davecra / console.js
Created Jul 3, 2017
Helps with debug logging right in the taskpane for the full clients
View console.js
/*!
* logger JavaScript Library v1.0.1
* http://davecra.com
*
* Copyright David E. Craig and other contributors
* Released under the MIT license
* https://tldrlegal.com/license/mit-license
*
* Date: 2016-08-09T12:00EST
*/
@davecra
davecra / FindAppointments.cs
Created Jul 3, 2017
Gets all the appointments between the given date times
View FindAppointments.cs
/// <summary>
/// EXTENSION METHOD
/// Get all the appointments between the given date times
/// </summary>
/// <param name="PobjItems"></param>
/// <param name="PobjStart"></param>
/// <param name="PobjEnd"></param>
/// <returns></returns>
public static List<Outlook.AppointmentItem> FindAppointments(this Outlook.Items PobjItems,
@davecra
davecra / broken.cs
Created Jul 3, 2017
This does not work
View broken.cs
/// <summary>
/// EXTENSION METHOD
/// Get all the appointments between the given date times
/// </summary>
/// <param name="PobjItems"></param>
/// <param name="PobjStart"></param>
/// <param name="PobjEnd"></param>
/// <returns></returns>
public static List<Outlook.AppointmentItem> FindAppointments(this Outlook.Items PobjItems,
DateTime PobjStart,
@davecra
davecra / BasicAddin.xml
Created Jul 3, 2017
A simple Excel add-in Manifest
View BasicAddin.xml
<?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>