mirror of
https://github.com/fumiama/go-docx.git
synced 2026-06-13 04:13:15 +08:00
rename package to docx
This commit is contained in:
@@ -4,7 +4,7 @@ linters-settings:
|
|||||||
ignoretests: true
|
ignoretests: true
|
||||||
|
|
||||||
goimports:
|
goimports:
|
||||||
local-prefixes: github.com/fumiama/docxlib
|
local-prefixes: github.com/fumiama/go-docx
|
||||||
|
|
||||||
forbidigo:
|
forbidigo:
|
||||||
# Forbid the following identifiers
|
# Forbid the following identifiers
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package docxlib
|
package docx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package docxlib
|
package docx
|
||||||
|
|
||||||
//nolint:revive,stylecheck
|
//nolint:revive,stylecheck
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package docxlib
|
package docx
|
||||||
|
|
||||||
import "unsafe"
|
import "unsafe"
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package docxlib
|
package docx
|
||||||
|
|
||||||
// Color allows to set run color
|
// Color allows to set run color
|
||||||
func (r *Run) Color(color string) *Run {
|
func (r *Run) Color(color string) *Run {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package docxlib
|
package docx
|
||||||
|
|
||||||
import "unsafe"
|
import "unsafe"
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package docxlib
|
package docx
|
||||||
|
|
||||||
import "strings"
|
import "strings"
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/fumiama/docxlib"
|
"github.com/fumiama/go-docx"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -35,21 +35,21 @@ func main() {
|
|||||||
analyzeOnly := flag.Bool("a", false, "analyze file only")
|
analyzeOnly := flag.Bool("a", false, "analyze file only")
|
||||||
unm := flag.Bool("u", false, "lease unmarshalled file")
|
unm := flag.Bool("u", false, "lease unmarshalled file")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
var w *docxlib.Docx
|
var w *docx.Docx
|
||||||
if !*analyzeOnly {
|
if !*analyzeOnly {
|
||||||
fmt.Printf("Preparing new document to write at %s\n", *fileLocation)
|
fmt.Printf("Preparing new document to write at %s\n", *fileLocation)
|
||||||
|
|
||||||
w = docxlib.NewA4()
|
w = docx.NewA4()
|
||||||
// add new paragraph
|
// add new paragraph
|
||||||
para1 := w.AddParagraph().Justification("distribute")
|
para1 := w.AddParagraph().Justification("distribute")
|
||||||
r, err := para1.AddAnchorDrawingFrom("testdata/fumiama.JPG")
|
r, err := para1.AddAnchorDrawingFrom("testdata/fumiama.JPG")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
r.Children[0].(*docxlib.Drawing).Anchor.Size(r.Children[0].(*docxlib.Drawing).Anchor.Extent.CX/4, r.Children[0].(*docxlib.Drawing).Anchor.Extent.CY/4)
|
r.Children[0].(*docx.Drawing).Anchor.Size(r.Children[0].(*docx.Drawing).Anchor.Extent.CX/4, r.Children[0].(*docx.Drawing).Anchor.Extent.CY/4)
|
||||||
r.Children[0].(*docxlib.Drawing).Anchor.BehindDoc = 1
|
r.Children[0].(*docx.Drawing).Anchor.BehindDoc = 1
|
||||||
r.Children[0].(*docxlib.Drawing).Anchor.PositionH.PosOffset = r.Children[0].(*docxlib.Drawing).Anchor.Extent.CX
|
r.Children[0].(*docx.Drawing).Anchor.PositionH.PosOffset = r.Children[0].(*docx.Drawing).Anchor.Extent.CX
|
||||||
r.Children[0].(*docxlib.Drawing).Anchor.Graphic.GraphicData.Pic.BlipFill.Blip.AlphaModFix = &docxlib.AAlphaModFix{Amount: 50000}
|
r.Children[0].(*docx.Drawing).Anchor.Graphic.GraphicData.Pic.BlipFill.Blip.AlphaModFix = &docx.AAlphaModFix{Amount: 50000}
|
||||||
// add text
|
// add text
|
||||||
para1.AddText("test")
|
para1.AddText("test")
|
||||||
para1.AddText("test font size").Size("44")
|
para1.AddText("test font size").Size("44")
|
||||||
@@ -70,13 +70,13 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
r.Children[0].(*docxlib.Drawing).Inline.Size(r.Children[0].(*docxlib.Drawing).Inline.Extent.CX*4/5, r.Children[0].(*docxlib.Drawing).Inline.Extent.CY*4/5)
|
r.Children[0].(*docx.Drawing).Inline.Size(r.Children[0].(*docx.Drawing).Inline.Extent.CX*4/5, r.Children[0].(*docx.Drawing).Inline.Extent.CY*4/5)
|
||||||
para4.AddTab().AddTab()
|
para4.AddTab().AddTab()
|
||||||
r, err = para4.AddInlineDrawingFrom("testdata/fumiama2x.webp")
|
r, err = para4.AddInlineDrawingFrom("testdata/fumiama2x.webp")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
r.Children[0].(*docxlib.Drawing).Inline.Size(r.Children[0].(*docxlib.Drawing).Inline.Extent.CX*4/5, r.Children[0].(*docxlib.Drawing).Inline.Extent.CY*4/5)
|
r.Children[0].(*docx.Drawing).Inline.Size(r.Children[0].(*docx.Drawing).Inline.Extent.CX*4/5, r.Children[0].(*docx.Drawing).Inline.Extent.CY*4/5)
|
||||||
|
|
||||||
para5 := w.AddParagraph().Justification("center")
|
para5 := w.AddParagraph().Justification("center")
|
||||||
// add text
|
// add text
|
||||||
@@ -101,7 +101,7 @@ func main() {
|
|||||||
for x, r := range tbl2.TableRows {
|
for x, r := range tbl2.TableRows {
|
||||||
r.Justification("center")
|
r.Justification("center")
|
||||||
for y, c := range r.TableCells {
|
for y, c := range r.TableCells {
|
||||||
c.TableCellProperties.VAlign = &docxlib.WVerticalAlignment{Val: "center"}
|
c.TableCellProperties.VAlign = &docx.WVerticalAlignment{Val: "center"}
|
||||||
c.AddParagraph().Justification("center").AddText(fmt.Sprintf("(%d, %d)", x, y))
|
c.AddParagraph().Justification("center").AddText(fmt.Sprintf("(%d, %d)", x, y))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -131,7 +131,7 @@ func main() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
size := fileinfo.Size()
|
size := fileinfo.Size()
|
||||||
doc, err := docxlib.Parse(readFile, size)
|
doc, err := docx.Parse(readFile, size)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -154,9 +154,9 @@ func main() {
|
|||||||
fmt.Println("Plain text:")
|
fmt.Println("Plain text:")
|
||||||
for _, it := range doc.Document.Body.Items {
|
for _, it := range doc.Document.Body.Items {
|
||||||
switch para := it.(type) {
|
switch para := it.(type) {
|
||||||
case docxlib.Paragraph:
|
case docx.Paragraph:
|
||||||
fmt.Println(para.String())
|
fmt.Println(para.String())
|
||||||
case docxlib.WTable:
|
case docx.WTable:
|
||||||
fmt.Println("------------------------------")
|
fmt.Println("------------------------------")
|
||||||
for x, r := range para.TableRows {
|
for x, r := range para.TableRows {
|
||||||
fmt.Printf("[%d] ", x)
|
fmt.Printf("[%d] ", x)
|
||||||
|
|||||||
@@ -18,9 +18,9 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Package docxlib is one of the most functional libraries to read and write .docx
|
// package docx is one of the most functional libraries to read and write .docx
|
||||||
// (a.k.a. Microsoft Word documents or ECMA-376 Office Open XML) files in Go.
|
// (a.k.a. Microsoft Word documents or ECMA-376 Office Open XML) files in Go.
|
||||||
package docxlib
|
package docx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"archive/zip"
|
"archive/zip"
|
||||||
|
|||||||
2
empty.go
2
empty.go
@@ -18,7 +18,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package docxlib
|
package docx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|||||||
2
fs.go
2
fs.go
@@ -18,7 +18,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package docxlib
|
package docx
|
||||||
|
|
||||||
import "embed"
|
import "embed"
|
||||||
|
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -1,4 +1,4 @@
|
|||||||
module github.com/fumiama/docxlib
|
module github.com/fumiama/go-docx
|
||||||
|
|
||||||
go 1.18
|
go 1.18
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package docxlib
|
package docx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|||||||
2
image.go
2
image.go
@@ -18,7 +18,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package docxlib
|
package docx
|
||||||
|
|
||||||
// addImage add image to docx and return its rId
|
// addImage add image to docx and return its rId
|
||||||
func (f *Docx) addImage(m Media) string {
|
func (f *Docx) addImage(m Media) string {
|
||||||
|
|||||||
2
link.go
2
link.go
@@ -18,7 +18,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package docxlib
|
package docx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|||||||
2
media.go
2
media.go
@@ -18,7 +18,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package docxlib
|
package docx
|
||||||
|
|
||||||
//nolint:revive,stylecheck
|
//nolint:revive,stylecheck
|
||||||
const MEDIA_FOLDER = `word/media/`
|
const MEDIA_FOLDER = `word/media/`
|
||||||
|
|||||||
2
pack.go
2
pack.go
@@ -18,7 +18,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package docxlib
|
package docx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"archive/zip"
|
"archive/zip"
|
||||||
|
|||||||
2
slice.go
2
slice.go
@@ -18,7 +18,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package docxlib
|
package docx
|
||||||
|
|
||||||
import "unsafe"
|
import "unsafe"
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package docxlib
|
package docx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package docxlib
|
package docx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package docxlib
|
package docx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package docxlib
|
package docx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package docxlib
|
package docx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package docxlib
|
package docx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package docxlib
|
package docx
|
||||||
|
|
||||||
//nolint:revive,stylecheck
|
//nolint:revive,stylecheck
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package docxlib
|
package docx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package docxlib
|
package docx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package docxlib
|
package docx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package docxlib
|
package docx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package docxlib
|
package docx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
|
|||||||
Reference in New Issue
Block a user