UNPKG

3.12 kBMarkdownView Raw
1![](https://api.travis-ci.org/lalalic/docx4js.svg?branch=master)
2
3# docx4js
4
5***please note 3.x is totally different from 2.x**, everything is breaking change.
6
7***please note 2.x is totally different from 1.x**, everything is breaking change.
8
9**docx4js** is a javascript docx parser.
10
11The original goal is to support docx, pptx, and xlsx, but it's a huge work, so I limited to docx so far.
12
13In sake of performance, the implementation doesn't keep parsed structure. It only traverse docx content, and identify docx model, then call passed visitors one by one. No matter content, and styles, are all with the same stratigy. This method makes it do more with less memory.
14
15There are lots of information in docx, but the client application usually only cares about part of them, such as content only, structure only, some styles, or some attributes. The client application is able to handle special word model by TYPE.
16
17Attributes of word model usually affects styles, but I don't understand all of them, so I'm lazy just to iterate every attribute, and some unknown child elements, so client application is possible to catch all information you know.
18
19# pptx supported since 3.1.30
20
21# Features
22
23
24## environment
25
26
27* nodejs
28* browser
29 * IE9+
30 * firefox
31 * chrome
32
33
34**identified models**
35
36* section
37* header
38* footer
39* paragraph
40* inline
41* numbering
42* heading
43* shape
44 * group
45 * line
46 * roundRect
47 * rect
48* image
49* hyperlink
50* table
51 * row
52 * cell
53* control.
54 * checkbox
55 * checked
56 * comboBox
57 * value
58 * options: {displayText, value}
59 * date
60 * value
61 * format
62 * locale
63 * dropDownList
64 * value
65 * options: {displayText, value}
66 * gallery
67 * picture
68 * richtext
69 * text
70 * value
71* text
72 * softHyphen
73 * noBreakHyphen
74 * tab
75 * symbol
76* field
77 * date
78 * hyperlink
79 * ref
80* OLE: {type:"object", embed, prog, data}
81* diagram
82* equation
83* bookmark
84* range
85* br
86* chart
87
88**style**
89
90* document default style
91* named style
92* style inheritance
93* paragraph
94* character
95* numbering
96* section
97* table
98
99## 3.x API
100<pre>
101import docx4js from "docx4js"
102
103docx4js.load("~/test.docx").then(docx=>{
104 //you can render docx to anything (react elements, tree, dom, and etc) by giving a function
105 docx.render(function createElement(type,props,children){
106 return {type,props,children}
107 })
108
109 //or use a event handler for more flexible control
110 const ModelHandler=require("docx4js/openxml/docx/model-handler").default
111 class MyModelhandler extends ModelHandler{
112 onp({type,children,node,...}, node, officeDocument){
113
114 }
115 }
116 let handler=new MyModelhandler()
117 handler.on("*",function({type,children,node,...}, node, officeDocument){
118 console.log("found model:"+type)
119 })
120 handler.on("r",function({type,children,node,...}, node, officeDocument){
121 console.log("found a run")
122 })
123
124 docx.parse(handler)
125
126 //you can change content on docx.officeDocument.content, and then save
127 docx.officeDocument.content("w\\:t").text("hello")
128 docx.save("~/changed.docx")
129
130})
131
132//you can create a blank docx
133docx4js.create().then(docx=>{
134 //do anything you want
135 docx.save("~/new.docx")
136})
137</pre>
138# ChangeLog
139 * ~~identify OLE object~~
140# License
141GPL