mirror of
https://github.com/fumiama/go-docx.git
synced 2026-06-28 07:00:23 +08:00
Update README.md
This commit is contained in:
36
README.md
36
README.md
@@ -55,6 +55,7 @@ And you will see two files generated under `pwd` with the same contents as below
|
|||||||
```bash
|
```bash
|
||||||
go get -d github.com/fumiama/go-docx@latest
|
go get -d github.com/fumiama/go-docx@latest
|
||||||
```
|
```
|
||||||
|
### Generate Document
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|
||||||
@@ -87,6 +88,41 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
### Parse Document
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/fumiama/go-docx"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
readFile, err := os.Open("file2parse.docx")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
fileinfo, err := readFile.Stat()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
size := fileinfo.Size()
|
||||||
|
doc, err := docx.Parse(readFile, size)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
fmt.Println("Plain text:")
|
||||||
|
for _, it := range doc.Document.Body.Items {
|
||||||
|
switch it.(type) {
|
||||||
|
case *docx.Paragraph, *docx.WTable: // printable
|
||||||
|
fmt.Println(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user