docx
    Preparing search index...

    Function readTheme

    • Reads a theme, such as the theme of a Word document or template, as the options of a document's theme. The new document then has the theme's colors and fonts, so the styles, tables and text that use them look as they do in the file the theme came from:

      • its name;
      • its colors, each an RGB color or a system color's last value;
      • its fonts for headings and body text, with their fonts for East Asian text, complex scripts and each other script.

      The fills, lines and effects of shapes styled by the theme are Office's in the new document, as docx writes them.

      It reads the colors or fonts Word saves on their own too, from Design > Colors > Customize Colors or Design > Fonts > Customize Fonts, as the theme's colors or fonts.

      Parameters

      • data: string | ArrayBuffer | Uint8Array<ArrayBufferLike>

        A Word document or template (.docx, .docm, .dotx or .dotm), a PowerPoint presentation (.pptx), an Excel workbook (.xlsx), an Office theme (.thmx), or the XML of a theme, such as a document's word/theme/theme1.xml, or of a theme's colors or fonts, as text or bytes

      Returns IThemeOptions

      The theme's options, to give Document's theme, or to change before giving it

      If the data isn't one of those, or the file has no theme

      import * as fs from "fs";
      import { Document, readTheme } from "docx";

      // The template's styles, and its theme, whose colors and fonts its styles use
      const doc = new Document({
      theme: readTheme(fs.readFileSync("template.dotx")),
      externalStyles: fs.readFileSync("styles.xml", "utf-8"),
      sections: [],
      });