API リファレンス
@office-kit/docx のすべての公開エクスポートと、@office-kit/docx-preview の唯一の関数を、31 のグループに分けて掲載しています(計 475 個)。ライブラリは関数と定数だけで構成されており、クラスはありません。ほとんどの関数は第 1 引数に Docx を受け取ります。モジュールには副作用がないため、インポートしなかったものはバンドラーが取り除きます。
このページは CI で実際にビルドしたパッケージと照合しているため、内容が古くなることはありません。引数の型は、パッケージに同梱されている型定義かソースコードを参照してください。そのまま貼り付けて使えるコードははじめにとレシピにあります。
ライフサイクル
ドキュメントの作成、読み込み、複製、シリアライズ。
createDocx({ paragraphs? }?) => DocxopenDocx(bytes: Uint8Array) => DocxfromBlob(blob: Blob) => Promise<Docx>toUint8Array(doc: Docx) => Uint8ArraytoBlob(doc: Docx) => Blobclone(doc: Docx) => Docx
段落とブロック
本文の段落、見出し、区切りの追加、挿入、削除。
appendParagraphinsertParagraphAtremoveParagraphappendHeadingappendPageBreakappendLineBreakappendSectionBreakclearBodyparagraphs
インラインとテキスト
検索と置換、ランとその書式、段落の配置、インデント、間隔、罫線、網かけ。
replaceTextreplaceTextEverywherefindTextfindTextEverywhereappendTextRunsetParagraphTextparagraphTextsetRunFormatclearRunFormatgetRunFormatHIGHLIGHT_COLORSreadonly HighlightColor[] — the only w:highlight values run-format writers acceptsetParagraphAlignmentgetParagraphAlignmentsetParagraphIndentsetParagraphSpacingsetParagraphBorderssetParagraphShadinggetParagraphStylegetParagraphNumberingmergeAdjacentRunsmergeAdjacentRunsInBodysetRunOnOffsetRunValPropgetRunPropsetParagraphOnOffsetParagraphValPropgetParagraphPropsplitParagraphAtmergeParagraphIntoPreviousrunTextLengthisolateParagraphRunRange
スタイルと段落番号
スタイル定義、箇条書きと番号付きリスト、デザイン済みテンプレートからのスタイルの取り込み。
addStyleremoveStylelistStylesensureHeadingStylesfindStyleIdByNamesetParagraphStyleaddBulletListaddNumberedListapplyListToParagraphmergeStylesFromTemplatesetStyleOnOffsetStyleValPropgetStylePropsetNumberingLevelOnOffsetNumberingLevelValgetNumberingLevelProp
表
表の作成と、行、セルのテキスト、罫線、網かけ、配置の編集。
addTabletablesremoveTableremoveAllTablesunwrapTableappendTableRowremoveTableRowsetTableRowAsHeadersetTableRowHeightsetTableBorderssetTableCellTextgetTableCellTextsetTableCellShadingsetTableCellVerticalAlign
表のレイアウト
Word の[レイアウト](表ツール)タブの操作。任意の位置への行・列・セルの挿入、結合と分割、サイズ、余白、並べ替え、文字列への変換、計算式。
tableCellPlacements(table) => TableCellPlacement[][]tableColumnCounttableColumnWidthstableCellBlocksinsertTableRow(table, index, { formatFrom? }?) => WmlTableRowdeleteTableRowsinsertTableColumn(table, index, { widthTwips?, formatFrom? }?) => voiddeleteTableColumnsdeleteTableCells(table, range, 'left' | 'up') => voidmergeTableCells(table, range: TableCellRange) => voidsplitTableCell(table, row, cell, { columns, rows }) => voidsplitTable(doc, table, row) => WmlTablesetTableWidthsetTableAlignmentsetTableIndentsetTableLayoutsetTableCellSpacingsetTableDefaultCellMarginssetTableAltTextsetTablePositionsetTableCellWidthsetTableCellMarginssetTableCellTextDirectionsetTableColumnWidthdistributeTableColumnsautoFitTable(table, 'contents' | 'window' | 'fixed') => voidsetTableRangeBorders(table, range, edges, border?) => voidsortTableRows(table, { keys, headerRow? }) => voidconvertTextToTable(doc, first, last, { separator, columns? }) => WmlTableevaluateTableFormula(table, row, cell, formula) => numberformatFieldNumber
表のスタイル
Word の組み込みの表スタイル(標準の表、グリッド テーブル、リスト テーブル)、表スタイルのオプション、表スタイルの書式。
BUILT_IN_TABLE_STYLESaddBuiltInTableStyle(doc, styleId) => voidbuiltInTableStylesetTableStylegetTableStylesetTableLook(table, look: TableLook) => voidgetTableLooksetTableStyleFormatting(doc, styleId, region, formatting) => void
画像
インライン画像の追加、ファイル内の画像の一覧取得、パーツ名または代替テキストによる差し替え。
addImageaddImageRuninsertImageIntoimagesimageReferencesreplaceImagereplaceImageByAltTextremoveAllImagesimageDrawingsgetImageInfosetImageAltTextsetImageSizeEmu
図、グラフ、配置
[図の形式]と[配置]の操作。文字列の折り返し、位置、重なり順、トリミング、図形、枠線、効果、色の調整に加え、ブックを埋め込んだ[挿入]▸[グラフ]。描画オブジェクトは imageDrawings のインデックスで指定します。
readDrawing(doc, drawing: XmlElement) => DrawingInfoimagePixelSize(bytes) => ImagePixelSize | undefinedimageNaturalSizeEmu(bytes) => { widthEmu, heightEmu } | undefinedsetDrawingWrap(doc, index, wrap: WrapStyle, position?) => voidsetDrawingPosition(doc, index, { horizontal?, vertical? }) => voidsetDrawingAnchorOptions(doc, index, AnchorOptions) => voidarrangeDrawing(doc, index, op: DrawingOrder) => voidsetDrawingTransform(doc, index, { rotation?, flipH?, flipV? }) => voidsetDrawingName(doc, index, name) => voidsetDrawingHidden(doc, index, hidden) => voidsetDrawingAspectLock(doc, index, locked) => voidsetDrawingHyperlink(doc, index, url | undefined) => voidremoveDrawing(doc, index) => voidsetPictureCrop(doc, index, PictureCrop) => voidsetPictureGeometry(doc, index, preset: string) => voidsetPictureOutline(doc, index, PictureOutline | undefined) => voidsetPictureEffects(doc, index, PictureEffects) => voidsetPictureColorAdjustments(doc, index, PictureColorAdjustments) => voidchangePicture(doc, index, bytes, contentType?) => voidresetPicture(doc, index, { size? }?) => voidaddChartRun(doc, spec: ChartSpec, { widthEmu, heightEmu, name?, altText? }) => WmlRunreadChart(doc, drawing: XmlElement) => ChartSpec | undefinedsetChart(doc, index, spec: ChartSpec) => void
コメント、脚注、ハイパーリンク、ブックマーク
校閲やナビゲーションのためのコンテンツの追加、一覧取得、リンクの書き換え、削除。
addCommentaddFootnoteaddEndnoteremoveAllCommentsremoveAllFootnotesremoveAllEndnotesaddHyperlinkaddInternalHyperlinkexternalHyperlinkssetHyperlinkUrlremoveAllHyperlinksaddBookmarkremoveBookmarkremoveAllBookmarksbookmarks
フィールドと変更履歴
目次や差し込みフィールドなどの複合フィールドと、変更履歴の挿入・削除の一括承諾・却下。
appendFieldaddTableOfContentsappendMergeFieldacceptAllRevisionsrejectAllRevisions
指定位置への挿入
Word の[挿入]タブで段落内の文字位置に配置できるもの。計算結果付きの複合フィールド、リンク、ブックマーク、記号と特殊文字、数式、ドロップ キャップ、署名欄。
insertField(doc, paragraph, offset, instruction, { result?, rPr?, lang?, context? }?) => WmlRun[]buildComplexField(instruction, result, rPr?, beginChildren?) => WmlRun[]updateFields(doc, { now?, page?, pageCount?, types? … }?) => numbercomplexFields(doc) => FieldInfo[]insertFormField(doc, paragraph, offset, FormFieldOptions) => WmlRun[]formatDatePicture(date, picture, locale?) => stringquoteFieldArgument(value) => stringinsertHyperlink(doc, paragraph, offset, text, { url? | bookmark?, tooltip?, targetFrame? }) => XmlElementparagraphHyperlinks(doc, paragraph) => HyperlinkInfo[]editHyperlinkremoveHyperlinkinsertBookmark(doc, name, start: TextPoint, end?: TextPoint) => numberisValidBookmarkName(name) => booleanensureReferenceBookmark(doc, paragraph, run?) => stringinsertSymbol(doc, paragraph, offset, SymbolSpec, rPr?) => WmlRuninsertEquation(doc, paragraph, offset, linear, { display? }?) => XmlElementbuildEquation(linear, { display? }?) => XmlElementequationLinear(element) => stringparagraphEquations(paragraph) => XmlElement[]setEquation(doc, paragraph, index, linear) => XmlElementgetDropCap(doc, paragraph) => DropCapOptionssetDropCap(doc, paragraph, { position, lines?, distanceTwips?, font? }) => voidinsertSignatureLine(doc, paragraph, offset, SignatureLineOptions) => WmlRun
ページ、ヘッダー、ページ番号
表紙、ヘッダーとフッターの内容、ページ番号とその書式、別のドキュメントの内容の取り込み([挿入]▸[オブジェクト]▸[ファイルからテキスト])。
insertCoverPage(doc, paragraphs) => voidremoveCoverPage(doc) => booleanhasCoverPage(doc) => booleansetDifferentFirstPage(doc, on) => voidheaderFooterParagraphs(doc, kind, type?) => WmlParagraph[]setHeaderFooterParagraphs(doc, kind, type, paragraphs) => voidremoveHeaderFooter(doc, kind, type?) => booleanensureHeaderFooterStyle(doc, kind) => stringinsertPageNumbers(doc, { position, align, style? }) => voidremovePageNumbers(doc) => numbersetPageNumberFormat(doc, { format?, start?, chapterStyle?, chapterSeparator? }) => voidgetPageNumberFormat(doc) => PageNumberFormatOptionsPAGE_NUMBER_FORMATSCHAPTER_SEPARATORSinsertDocumentContent(doc, source: Docx, blockIndex) => number
ドキュメントのプロパティ
コアプロパティとアプリケーションプロパティ。タイトルと作成者にはショートカットがあります。
corePropertiessetCorePropertiesappPropertiessetAppPropertiestitleauthorsetTitlesetAuthorgetDocumentSettingsetDocumentSettingOnOffsetDocumentSettingVal
図形、テキストボックス、ワードアート、インク(VML)
Word のギャラリーにある図形、テキストボックス、ワードアート、インクのストローク、描画キャンバスを ECMA-376 の VML(`w:pict`)として描画し、塗りつぶし、枠線、影、レイアウト、文字列の折り返し、重なり順、テキスト、グループ化を編集します。図形のハンドルは VML 要素そのものです。
addShape(doc, paragraph, { preset, width, height, left?, top?, wrap?, fill?, stroke?, text?, points?, ink? }, index?) => XmlElementaddWordArt(doc, paragraph, { text, width, height, font?, size?, bold?, italic? }, index?) => XmlElementaddDrawingCanvas(doc, paragraph, { width, height }, index?) => XmlElementaddShapeToGroup(doc, group, options) => XmlElementvmlShapes(doc) => XmlElement[]runShape(run) => XmlElement | undefinedshapeKindshapePresetSHAPE_PRESETSSHAPE_CATEGORIESchangeShapePresetgetShapePointssetShapePointsgetShapeLayoutsetShapeLayoutgetShapeWrapsetShapeWrapsetShapeOrdersetShapeMoveWithTextgetShapeFillsetShapeFillvmlImageDataFILL_PATTERNSgetShapeStrokesetShapeStrokegetShapeShadowsetShapeShadowshapeTextsetShapeTextgetTextBoxLayoutsetTextBoxLayoutlinkTextBoxeslinkedTextBoxgetWordArtsetWordArtgetShapeAltTextsetShapeAltTextgetShapeNamesetShapeNameremoveShapegroupShapesungroupShapesgroupMembers
SmartArt
SmartArt グラフィック(DrawingML のダイアグラム。データモデル、レイアウト、スタイル、色の各パーツ)の挿入と、箇条書き、レイアウト、色、スタイル、サイズの編集。
addSmartArt(doc, paragraph, { layout, nodes, width?, height?, colors?, style? }, index?) => WmlRunsmartArts(doc) => SmartArtRef[]runSmartArt(doc, run) => SmartArtRef | undefinedgetSmartArtsetSmartArtNodessetSmartArtLayoutsetSmartArtColorssetSmartArtStylesetSmartArtSizeremoveSmartArtSMARTART_LAYOUTSSMARTART_COLORSSMARTART_STYLES
診断
パッケージの検証と、ドキュメント内容の読み取り(アウトライン、フィールド、統計情報、プレーンテキスト)。
validatevalidatePackagestatisticsoutlinefieldstext
校閲: 変更履歴
変更履歴の一覧取得、承諾、却下。挿入・削除・書式変更の変更履歴としての記録と、2 つのドキュメントの比較。
revisions(doc: Docx) => RevisionInfo[]acceptRevisions(doc: Docx, ids: readonly string[]) => numberrejectRevisions(doc: Docx, ids: readonly string[]) => numberinsertTrackedTextdeleteTrackedTextparagraphMarkRevisiontrackParagraphMarktrackRunFormatChangetrackParagraphFormatChangecompareDocuments(original: Docx, revised: Docx, options: CompareOptions) => Docx
校閲: コメント、文章校正、アクセシビリティ
コメントの読み取りと編集、校正言語の設定、Word と同じ方法での文字数カウント、アクセシビリティ チェック。
comments(doc: Docx) => CommentInfo[]setCommentTextremoveCommentgetRunLanguagesetRunLanguagewordCount(doc: Docx, options?: WordCountOptions) => WordCountcheckAccessibility(doc: Docx) => AccessibilityIssue[]contrastRatio
ドキュメントの保護
編集の制限(パスワードは任意)、編集を許可する例外、常に読み取り専用で開く設定。
documentProtectionprotectDocument(doc: Docx, options: ProtectOptions) => voidunprotectDocument(doc: Docx, password: string) => booleanverifyProtectionPasswordwriteProtectionsetWriteProtectioneditableRangesaddEditableRangeremoveEditableRange
表示とユーザー設定のプロパティ
ドキュメントを開いたときの表示モードとズーム、ユーザー設定のドキュメント プロパティ。
documentViewsetDocumentViewdocumentZoomsetDocumentZoomcustomPropertiessetCustomPropertyremoveCustomProperty
低レベルのパーツ アクセス
解析済みの補助パーツ。上記の関数では手が届かない場合に使います。
stylesPartnumberingPartcommentsPartfootnotesPartendnotesPartxmlPartNamesgetRawPartRootmarkRawPartDirtychildElementsOfappendChildElementmakePropsElementgetElementAttrsetElementAttrgetElementPropsetElementOnOffsetElementValProp
ストーリーとセクションのヘッダー
ヘッダー、フッター、脚注、文末脚注、コメントを型付きのブロック コンテンツとして扱う関数と、各セクションに表示するヘッダー・フッターの指定。
storyBody(doc, ref: StoryRef) => WmlBody | undefinedcontentControlBlocks(block: WmlBlock) => readonly WmlBlock[] | undefinedwrappedRuns(inline: WmlInline) => readonly WmlRun[] | undefinedstoryView(doc, ref: StoryRef) => Docx | undefinedstoryKey(ref: StoryRef) => stringparseStoryKey(key: string) => StoryRef | undefinedsectionProperties(doc) => Array<XmlElement | undefined>resolveHeaderFooter(doc, section, kind, type) => { partName, section } | undefinedensureHeaderFooter(doc, section, kind, type) => stringisHeaderFooterLinked(doc, section, kind, type) => booleansetHeaderFooterLinked(doc, section, kind, type, linked) => void
文字書式と段落書式
テーマの色、すべての下線スタイル、テーマのフォント、ランの網かけと罫線、段落の辺ごとの罫線、タブ位置、ルビ、囲い文字、リストの定義、Word の組み込みスタイル。
setRunColor(run, color: ColorValue | undefined) => voidsetRunUnderline(run, underline: UnderlineValue | undefined) => voidsetRunFont(run, script, font: FontChoice | undefined) => voidsetRunShading(run, shading: ShadingOptions | undefined) => voidsetRunBorder(run, line: BorderLine | undefined) => voidsetParagraphBorder(p, side, line: BorderLine | undefined) => voidsetParagraphTabs(p, tabs: TabStop[]) => voidgetParagraphTabs(p) => TabStop[]buildRubyRun(base, ruby, options, rPr?) => WmlRunreadRuby(run) => RubyInfo | undefinedbuildEnclosedCharacterRuns(text, options, rPr?) => WmlRun[]addListDefinition(doc, levels: ListLevel[]) => numberrestartList(doc, numId, ilvl, start) => number | undefinedensureBuiltinStyle(doc, styleId) => booleanbuiltinStyles() => BuiltinStyleInfo[]updateStyleFormatting(doc, styleId, { run?, paragraph? }) => booleanTHEME_COLORSUNDERLINE_STYLESSHADING_PATTERNSBORDER_LINE_STYLESRUBY_ALIGNMENTSENCLOSURESNUMBER_FORMATS
用紙サイズと余白の定数
setPageSize と setPageMargins にそのまま渡せる値と、ライブラリのバージョン。
PAGE_SIZE_A4PAGE_SIZE_LETTERMARGINS_NORMALVERSION
セクションのレイアウト
セクション単位の段組み、行番号、ページ罫線、垂直方向の配置、文字グリッド、セクション区切り。
sectionCount(doc) => numbersectionIndexAt(doc, blockIndex) => numbergetSectionProperties(doc, section?) => SectionPropertiessetSectionProperties(doc, patch, scope?) => voidinsertSectionBreak(doc, blockIndex, start?) => numberPAGE_BORDER_LINE_STYLESreadonly string[] — line styles for page bordersPAGE_BORDER_ARTreadonly string[] — art border names (ST_Border)
デザイン: テーマ、スタイル セット、ページの背景
テーマ パーツ(配色、フォント、効果)、スタイル セット、段落の既定の間隔、ページの色、透かし。
setTheme(doc, theme: ThemeDefinition) => voidgetTheme(doc) => ThemeInfo | undefinedsetThemeColors(doc, colors: ThemeColorScheme) => voidsetThemeFonts(doc, fonts: ThemeFontScheme) => voidsetThemeEffects(doc, effects: ThemeEffectScheme) => voidthemeColorValue(colors, themeColor, { shade?, tint? }?) => string | undefinedapplyStyleSet(doc, set: StyleSetDefinition) => voidcurrentStyleSet(doc) => StyleSetDefinition | undefinedsetDefaultParagraphSpacing(doc, { before, after, line }) => voidgetDefaultParagraphSpacing(doc) => DefaultParagraphSpacing | undefinedsetPageColor(doc, color: PageColor | undefined) => voidgetPageColor(doc) => PageColor | undefinedsetWatermark(doc, watermark: Watermark | undefined) => voidgetWatermark(doc) => WatermarkInfo | undefinedTHEMESTHEME_COLOR_SCHEMESTHEME_COLOR_SLOTSTHEME_FONT_SCHEMESTHEME_EFFECT_SCHEMESSTYLE_SETSPARAGRAPH_SPACING_PRESETS
参考資料
Word の[参考資料]タブ。目次と図表目次、脚注と文末脚注、引用文献と文献目録、図表番号、索引、引用文献一覧を、計算済みのフィールド結果とともに扱います。
insertTableOfContents(doc, at, options?) => voidtableOfContentsInstructionremoveTableOfContentssetTocLevel(doc, paragraph, level | 'none') => voidtocLevelupdateTables(doc, { types?, pageOf? }?) => numberinsertNote(doc, paragraph, offset, 'footnote' | 'endnote', options?) => numbernoteMarksnoteTextsetNoteTextnotePropertiessetNotePropertiesconvertNotesbibliographySourcessetBibliographySourcesbibliographyStylesetBibliographyStylesuggestSourceTagcitationInstructioninsertCitationinsertBibliographyinsertCaption(doc, blockIndex, 'above' | 'below', options) => WmlParagraphcaptionLabelsaddCaptionLabelindexEntryInstructionmarkIndexEntrymarkAllIndexEntriesindexInstructioninsertIndexmarkAuthorityCitationinsertTableOfAuthoritiesCITATION_STYLESSOURCE_TYPESSOURCE_FIELDSBIBLIOGRAPHY_TITLESCAPTION_LABELSAUTHORITY_CATEGORIES
差し込み文書
封筒、ラベル、差し込み印刷。データ ソースの設定、差し込みフィールドとルール、宛先のプレビュー、新規文書への差し込み。
addEnveloperemoveEnvelopecreateLabelDocument(options) => DocxupdateLabelsmailMergeSettingssetMailMergeDocumentTypeparseRecipientCsvrecipientListToCsvattachRecipientListautoFieldMapmailMergeFieldMapsetMailMergeFieldMapsetRecipientInclusionrecipientInclusionmergeFieldInstructioninsertMergeFieldaddressBlockInstructioninsertAddressBlockgreetingLineInstructioninsertGreetingLineinsertMergeRulemergeFieldNamesmergeFieldErrorspreviewMailMerge(doc, list, index | undefined, options?) => voidmergeToNewDocument(doc, list, options?) => DocxENVELOPE_SIZESLABEL_PRODUCTSADDRESS_FIELDSADDRESS_NAME_FORMATSGREETING_NAME_FORMATS
ブラウザー プレビュー(@office-kit/docx-preview)
姉妹パッケージの唯一のエントリーポイント。
previewToDOM(source, container, options?) => Promise<Handle>