1
0
mirror of https://github.com/fumiama/go-docx.git synced 2026-06-28 15:10:24 +08:00

Update README.md

This commit is contained in:
源文雨
2023-03-07 15:15:33 +08:00
committed by GitHub
parent 8402c813de
commit 6b512c1716

View File

@@ -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