Skip to content

Instantly share code, notes, and snippets.

View barisbikmaz's full-sized avatar

Baris Bikmaz barisbikmaz

  • officeatwork
  • Zug, Switzerland
View GitHub Profile
@barisbikmaz
barisbikmaz / filepicker.html
Last active July 10, 2023 08:49
OneDrive FilePicker Example
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title>file picker</title>
<style>
html,
body {
name: Style API - Removing Style
description: ''
host: WORD
api_set: {}
script:
content: |
/**
* USE CASE:
* Removing Style from the current document
*
@barisbikmaz
barisbikmaz / Styles API - Replacing Style.WORD.yaml
Last active May 17, 2023 12:03
Example to replace the style in the current document
name: Styles API - Replacing Style
description: Example to replace the style in the current document
host: WORD
api_set: {}
script:
content: "/**\n * USE CASE:\n * We want to replace a style in the current document with the styles from a base64 docx\n *\n * ISSUES:\n * Replacing a style is nearly not possible because:\n * - When setting some properties like font.color the API throws\n * - You cannot set deeper object properties partially like font.color. You must set the whole object.\n * - Problems loading the font property of a style\n */\n$(\"#replace-style\").click(() => tryCatch(replaceStyle));\n$(\"#apply-style\").click(() => tryCatch(applyStyle));\n\nfunction sourceDocumentStyleName() {\n return $(\"input[name=sourceStyleName]\").val() as string;\n}\n\nfunction targetDocumentStyleName() {\n return $(\"input[name=targetStyleName]\").val() as string;\n}\n\nasync function replaceStyle() {\n const styleName = targetDocumentStyleName();\n const styleNameInSource = sourceDocumentStyleName();\n\n
@barisbikmaz
barisbikmaz / Styles API - Adding Style.WORD.yaml
Last active May 17, 2023 12:03
Adds a style from a source document into the current document
name: Styles API - Adding Style
description: Adds a style from a source document into the current document
host: WORD
api_set: {}
script:
content: "/**\n * USE CASE:\n * We want to add a style from a base64 docx document into the current document\n *\n * ISSUES:\n * - retrieveStylesFromBase64 returns a JSON with UpperCase properties but when settings styles we need lowerCase\n * - setting a style property with null causes errors\n * - settings the font propery often errors\n * - retrieveStylesFromBase64 sometime returns font property with null objects\n */\n\n$(\"#add-style\").click(() => tryCatch(addStyle));\n\nfunction sourceDocumentStyleName() {\n return $(\"input[name=sourceStyleName]\").val() as string;\n}\n\nfunction targetDocumentStyleName() {\n return $(\"input[name=targetStyleName]\").val() as string;\n}\n\nasync function addStyle() {\n const styleToApplyNameLocal = sourceDocumentStyleName();\n\n console.log(`⚙️ Searching for style ${styleToApplyNameLocal} in source document...`);\n\n const st
name: Preview Styles API Experiment
description: ''
host: WORD
api_set: {}
script:
content: "$(\"#get-styles-from-base64-document\").click(() => tryCatch(logBase64DocumentStyles));\n$(\"#get-styles-from-current-document\").click(() => tryCatch(logCurrentDocumentStyles));\n$(\"#update-style\").click(() => tryCatch(updateStyle));\n$(\"#add-style\").click(() => tryCatch(addStyle));\n$(\"#remove-style\").click(() => tryCatch(removeStyle));\n$(\"#replace-style\").click(() => tryCatch(replaceStyle));\n\n// PROBLEM: You cannot add style names with spaces or dots\n// const styleName = \"ofaw\";\n// const styleToApplyNameLocal = \"ofaw.styles.1\";\n\n// #region -- LOGGING STYLES INTO CONSOLE --\nasync function logBase64DocumentStyles() {\n const styles = await loadBase64DocumentStyles();\n console.log(styles);\n}\n\nasync function logCurrentDocumentStyles() {\n await Word.run(async (context) => {\n const styles = context.document.getStyles();\n styles.load();\n await context.sync();\n\n console.log(st
@barisbikmaz
barisbikmaz / ooxml of Content Control with Image Bug.WORD.yaml
Last active January 20, 2023 08:15
Insert a content control with an image. Then reads the ooxml of the content control
name: ooxml of Content Control with Image Bug
description: >-
Insert a content control with an image. Then reads the ooxml of the content
control
host: WORD
api_set: {}
script:
content: |
$("#setup").click(() => tryCatch(setup));
$("#get-ooxml").click(() => tryCatch(getOoxml));
@barisbikmaz
barisbikmaz / Child Content Control ooxml bug.WORD.yaml
Last active January 23, 2023 16:23
Creates a content control with a child content control. When you try to get the ooxml of the content control, the child content control is ignored.
name: Child Content Control ooxml bug
description: >-
Creates a content control with a child content control. When you try to get
the ooxml of the content control, the child content control is ignored.
host: WORD
api_set: {}
script:
content: |
$("#setup").click(() => tryCatch(setup));
$("#get-ooxml").click(() => tryCatch(getOoxml));
name: Style Ignored in Word Online (2)
description: ''
host: WORD
api_set: {}
script:
content: "$(\"#run\").click(() => tryCatch(run));\n\nasync function run() {\n await Word.run(async (context) => {\n const range = context.document.getSelection();\n range.insertHtml(html, \"Replace\");\n await context.sync();\n });\n}\n\n/** Default helper for invoking an action and handling errors. */\nasync function tryCatch(callback) {\n try {\n await callback();\n } catch (error) {\n // Note: In a production add-in, you'd want to notify the user through your add-in's UI.\n console.error(error);\n }\n}\n\nconst html = `<html>\n\t<body>\n <div>\n <h1>This line has Heading 1 style</h1>\n <p class=MsoTitle>This line has Title style</p>\n <p>&nbsp;</p>\n </div>\n\t</body>\n</html>`;"
language: typescript
template:
content: |
<button id="run" class="ms-Button">
name: Coop UI Performance Test
description: ''
host: WORD
api_set: {}
script:
content: |
$("#insert-html").on("input", function() {
insertHtmlIntoCCs((this as HTMLInputElement).value);
});
@barisbikmaz
barisbikmaz / Insert Docx Resets Content Control.WORD.yaml
Created October 28, 2020 13:09
To demonstrate reset behaviour in Word Onlie
name: Insert Docx Resets Content Control
description: To demonstrate reset behaviour in Word Onlie
host: WORD
api_set: {}
script:
content: >
// Preparation
// Create a blank document in Word in Windows