Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
lalalic committed Oct 18, 2021
1 parent afcc68c commit ffdd71e
Show file tree
Hide file tree
Showing 26 changed files with 54,170 additions and 43 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@
# Commenting this out is preferred by some people, see
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
node_modules
dist/*.js
yarn-error.log
lib
yarn-error.log
84 changes: 45 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,50 @@
![](https://api.travis-ci.org/lalalic/docx4js.svg?branch=master)

# docx4js
docx4js
===
a docx/pptx/xlsx parser

API
===
```js
import docx4js from "docx4js"

docx4js.load("~/test.docx").then(docx=>{
//you can render docx to anything (react elements, tree, dom, and etc) by giving a function
docx.render(function createElement(type,props,children){
return {type,props,children}
})

//or use a event handler for more flexible control
const ModelHandler=require("docx4js/lib/openxml/docx/model-handler").default
class MyModelhandler extends ModelHandler{
onp({type,children,node,...}, node, officeDocument){

}
}

const handler=new MyModelhandler()
handler.on("*",function({type,children,node,...}, node, officeDocument){
console.log("found model:"+type)
})
handler.on("r",function({type,children,node,...}, node, officeDocument){
console.log("found a run")
})

docx.parse(handler)

//you can change content on docx.officeDocument.content, and then save
docx.officeDocument.content("w\\:t").text("hello")
docx.save("~/changed.docx")

})

//you can create a blank docx
docx4js.create().then(docx=>{
//do anything you want
docx.save("~/new.docx")
})
```

***please note 3.x is totally different from 2.x**, everything is breaking change.

Expand Down Expand Up @@ -96,45 +140,7 @@ Attributes of word model usually affects styles, but I don't understand all of t
* section
* table

## 3.x API
<pre>
import docx4js from "docx4js"

docx4js.load("~/test.docx").then(docx=>{
//you can render docx to anything (react elements, tree, dom, and etc) by giving a function
docx.render(function createElement(type,props,children){
return {type,props,children}
})

//or use a event handler for more flexible control
const ModelHandler=require("docx4js/lib/openxml/docx/model-handler").default
class MyModelhandler extends ModelHandler{
onp({type,children,node,...}, node, officeDocument){

}
}
let handler=new MyModelhandler()
handler.on("*",function({type,children,node,...}, node, officeDocument){
console.log("found model:"+type)
})
handler.on("r",function({type,children,node,...}, node, officeDocument){
console.log("found a run")
})

docx.parse(handler)

//you can change content on docx.officeDocument.content, and then save
docx.officeDocument.content("w\\:t").text("hello")
docx.save("~/changed.docx")

})

//you can create a blank docx
docx4js.create().then(docx=>{
//do anything you want
docx.save("~/new.docx")
})
</pre>
# ChangeLog
* ~~identify OLE object~~
# License
Expand Down
516 changes: 516 additions & 0 deletions dist/docx4js.js

Large diffs are not rendered by default.

Loading

0 comments on commit ffdd71e

Please sign in to comment.