Snippets Collections
from docx import Document
import pandas as pd

df = pd.read_csv('out.csv').to_dict()
word_doc = Document()

table_head = list(df.keys())

table_head_len = len(table_head)
tables_rows_len = len(df['name'])

# create tabel
table = word_doc.add_table(cols = table_head_len, rows = tables_rows_len)

# add the first row in the table
for i in range(table_head_len):
    table.cell(row_idx = 0, col_idx = i).text = table_head[i]


# add rows for name col
for i in range(1, tables_rows_len):
    table.cell(row_idx = i, col_idx = 0).text = df['name'][i]


# add rows for age col
for i in range(1, tables_rows_len):
    table.cell(row_idx = i, col_idx = 1).text = str(df['age'][i])


word_doc.save('word_doc.docx')
name: Custom document properties

description: Adds and reads custom document properties of different types.

host: WORD

api_set: {}

script:

  content: |

    $("#number").click(() => tryCatch(insertNumericProperty));

    $("#string").click(() => tryCatch(insertStringProperty));

    $("#read").click(() => tryCatch(readCustomDocumentProperties));

​

    async function insertNumericProperty() {

      await Word.run(async (context) => {

        context.document.properties.customProperties.add("Numeric Property", 14);

​

        await context.sync();

        console.log("Property added");

      });

    }

​

    async function insertStringProperty() {

      await Word.run(async (context) => {

        context.document.properties.customProperties.add("String Property", "Hello World!");
23
​

        await context.sync();

        console.log("Property added");

      });

    }

​

    async function readCustomDocumentProperties() {

      await Word.run(async (context) => {

        const properties = context.document.properties.customProperties;

        properties.load("key,type,value");

​

        await context.sync();

        for (let i = 0; i < properties.items.length; i++)

          console.log(

            "Property Name:" +

              properties.items[i].key +

              "; Type=" +

              properties.items[i].type +

              "; Property Value=" +

              properties.items[i].value

          );

      });

    }

​

    /** 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);
let words = input.match(/(\w+)/g).length
  
star

Thu Mar 02 2023 23:00:46 GMT+0000 (Coordinated Universal Time) https://gist.github.com/evansjeffm99/54b71165d2e20d41dc4b54bd7f723943/edit

#word #properties #customlabels #yaml
star

Mon Aug 08 2022 11:13:04 GMT+0000 (Coordinated Universal Time)

#javascript #string #word #count

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension