mirror of
https://github.com/fumiama/go-docx.git
synced 2026-06-11 02:50:27 +08:00
feat: add param -d to cmd/main
This commit is contained in:
@@ -24,6 +24,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -39,6 +40,7 @@ func main() {
|
|||||||
unm := flag.Bool("u", false, "lease unmarshalled file")
|
unm := flag.Bool("u", false, "lease unmarshalled file")
|
||||||
splitre := flag.String("s", "", "split file into many docxs by matching regex")
|
splitre := flag.String("s", "", "split file into many docxs by matching regex")
|
||||||
droppp := flag.Bool("p", false, "drop all paragraph properties")
|
droppp := flag.Bool("p", false, "drop all paragraph properties")
|
||||||
|
dupnum := flag.Uint("d", 0, "copy times of the file into dup_filename")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
var w *docx.Docx
|
var w *docx.Docx
|
||||||
if !*analyzeOnly {
|
if !*analyzeOnly {
|
||||||
@@ -241,5 +243,24 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if *dupnum > 1 {
|
||||||
|
a := strings.LastIndex(*fileLocation, "/")
|
||||||
|
name := "dup_" + (*fileLocation)
|
||||||
|
if a > 0 {
|
||||||
|
name = (*fileLocation)[:a+1] + "dup_" + (*fileLocation)[a:]
|
||||||
|
}
|
||||||
|
f, err := os.Create(name)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
newFile := docx.NewA4()
|
||||||
|
for i := 0; i < int(*dupnum); i++ {
|
||||||
|
newFile.AppendFile(doc)
|
||||||
|
}
|
||||||
|
_, err = io.Copy(f, newFile)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
fmt.Println("End of main")
|
fmt.Println("End of main")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user