1
0
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:
源文雨
2023-02-26 13:07:16 +08:00
parent fafd4c9fc3
commit 2f9f76f1dc
31 changed files with 44 additions and 44 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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

@@ -1,4 +1,4 @@
module github.com/fumiama/docxlib module github.com/fumiama/go-docx
go 1.18 go 1.18

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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