对齐 Tag v1.5.0 (By AI)
This commit is contained in:
parent
b71cb7f48f
commit
2a715c11ef
11
go.mod
11
go.mod
@ -3,17 +3,18 @@ module apigo.cc/go/document
|
||||
go 1.25.0
|
||||
|
||||
require (
|
||||
apigo.cc/go/cast v1.3.3
|
||||
apigo.cc/go/file v1.3.2
|
||||
apigo.cc/go/cast v1.5.0
|
||||
apigo.cc/go/file v1.5.0
|
||||
apigo.cc/go/jsmod v1.5.0
|
||||
github.com/dslipak/pdf v0.0.2
|
||||
github.com/xuri/excelize/v2 v2.10.1
|
||||
github.com/young2j/oxmltotext v1.0.3
|
||||
)
|
||||
|
||||
require (
|
||||
apigo.cc/go/encoding v1.3.1 // indirect
|
||||
apigo.cc/go/rand v1.3.1 // indirect
|
||||
apigo.cc/go/safe v1.3.1 // indirect
|
||||
apigo.cc/go/encoding v1.5.0 // indirect
|
||||
apigo.cc/go/rand v1.5.0 // indirect
|
||||
apigo.cc/go/safe v1.5.0 // indirect
|
||||
github.com/andybalholm/brotli v1.0.5 // indirect
|
||||
github.com/dgrr/quickxml v0.0.0-20201022091424-4977de546d6c // indirect
|
||||
github.com/klauspost/compress v1.17.0 // indirect
|
||||
|
||||
22
go.sum
22
go.sum
@ -1,13 +1,15 @@
|
||||
apigo.cc/go/cast v1.3.3 h1:aln5eDR5DZVWVzZ/y5SJh1gQNgWv2sT82I25NaO9g34=
|
||||
apigo.cc/go/cast v1.3.3/go.mod h1:lGlwImiOvHxG7buyMWhFzcdvQzmSaoKbmr7bcDfUpHk=
|
||||
apigo.cc/go/encoding v1.3.1 h1:y8O58KYAyulkThg1O2ji2BqjnFoSvk42sit9I3z+K7Y=
|
||||
apigo.cc/go/encoding v1.3.1/go.mod h1:xAJk5b83VZ31mXMTnyp0dfMoBKfT/AHDn0u+cQfojgY=
|
||||
apigo.cc/go/file v1.3.2 h1:pu4oiDyiqgj3/eykfnJf+/6+A9v/Z0b3ClP5XK+lwG4=
|
||||
apigo.cc/go/file v1.3.2/go.mod h1:vci4h0Pz94mV6dkniQkuyBYERVYeq7/LX4jJVuCg9hs=
|
||||
apigo.cc/go/rand v1.3.1 h1:7FvsI6PtQ5XrWER0dTiLVo0p7GIxRidT/TBKhVy93j8=
|
||||
apigo.cc/go/rand v1.3.1/go.mod h1:mZ/4Soa3bk+XvDaqPWJuUe1bfEi4eThBj1XmEAuYxsk=
|
||||
apigo.cc/go/safe v1.3.1 h1:irTCqPAC97gGsX/Lw5AzLelDt1xXLEZIAaVhLELWe9Q=
|
||||
apigo.cc/go/safe v1.3.1/go.mod h1:XdOpBhN2vkImalaykYXXmEpczqWa1y3ah6/Q72cdRqE=
|
||||
apigo.cc/go/cast v1.5.0 h1:UBGJtFQ8eJPMQXs37cUgqd7YQo1zI9opuSDBDmn2/pE=
|
||||
apigo.cc/go/cast v1.5.0/go.mod h1:z2GW5p5WCZGEqVVIJUdhl232vRbLf2Qu4EDlEakX/D8=
|
||||
apigo.cc/go/encoding v1.5.0 h1:EJNdRVDOMoI2DAvZwQNQTbYuqB/6zsEzvg7lS5pQI+I=
|
||||
apigo.cc/go/encoding v1.5.0/go.mod h1:8++NfZj3hWig0qh2g7GQRw/4LpSvCYMWUZ+8J+x58cA=
|
||||
apigo.cc/go/file v1.5.0 h1:Fh1NSDBqaxjuXYJ71yPHPXVJ8BFEv/AGS3l+jkLi5uw=
|
||||
apigo.cc/go/file v1.5.0/go.mod h1:4YhOGgBINTpmmmgws3H8LAyXQQBGzBp44hYUoCS+kr0=
|
||||
apigo.cc/go/jsmod v1.5.0 h1:JgQtJNiJWy1NOP9AzE8NX5VXJkpO/x3GqLsCCSny5Ec=
|
||||
apigo.cc/go/jsmod v1.5.0/go.mod h1:bmyeZtOAP/j5am+YRnaiM89smysK24K7ebk0koFtsSw=
|
||||
apigo.cc/go/rand v1.5.0 h1:1o8hh8fhdBuk1/h02IvugvamuT3dkWbVJrqEJVQKB2E=
|
||||
apigo.cc/go/rand v1.5.0/go.mod h1:Lh98S2dm9UY0X+M+kNQQEKyXHG5pcCKSFPyXN0QCGdk=
|
||||
apigo.cc/go/safe v1.5.0 h1:W1NblmcU8cex1f9Y5z8mNLUJOzZTE1s6fszb3FbhGnk=
|
||||
apigo.cc/go/safe v1.5.0/go.mod h1:OfQ5d6COePSGEuPvMeOk6KagX2sezw7nvKh7exj9SeM=
|
||||
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
|
||||
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
|
||||
93
js_export.go
Normal file
93
js_export.go
Normal file
@ -0,0 +1,93 @@
|
||||
package document
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"apigo.cc/go/file"
|
||||
"apigo.cc/go/jsmod"
|
||||
)
|
||||
|
||||
func init() {
|
||||
jsmod.Register("document", map[string]any{
|
||||
"open": func(ctx context.Context, filename string, password ...string) (*jsDocument, error) {
|
||||
p, err := file.VerifyPathForSafeMode(ctx, filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
doc, err := Open(p, password...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &jsDocument{ctx: ctx, d: doc}, nil
|
||||
},
|
||||
"create": func(ctx context.Context, ext string) (*jsDocument, error) {
|
||||
doc, err := Create(ext)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &jsDocument{ctx: ctx, d: doc}, nil
|
||||
},
|
||||
"newExcel": func(ctx context.Context) *jsDocument {
|
||||
return &jsDocument{ctx: ctx, d: NewExcel()}
|
||||
},
|
||||
"newGraph": func(ctx context.Context) *jsDocument {
|
||||
return &jsDocument{ctx: ctx, d: NewGraph()}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
type jsDocument struct {
|
||||
ctx context.Context
|
||||
d Document
|
||||
}
|
||||
|
||||
func (j *jsDocument) ToJSON() string { return j.d.ToJSON() }
|
||||
func (j *jsDocument) ToMarkdown() string { return j.d.ToMarkdown() }
|
||||
|
||||
func (j *jsDocument) Save(filename ...string) error {
|
||||
var targetPath string
|
||||
if len(filename) > 0 {
|
||||
p, err := file.VerifyPathForSafeMode(j.ctx, filename[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
targetPath = p
|
||||
}
|
||||
return j.d.Save(targetPath)
|
||||
}
|
||||
|
||||
// Excel 增强方法 (如果底层是 Excel)
|
||||
func (j *jsDocument) Get(sheetName string, start, end string) ([][]any, error) {
|
||||
if x, ok := j.d.(*Excel); ok {
|
||||
return x.Get(sheetName, start, end)
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (j *jsDocument) GetData(sheetName string, start, end string) ([]map[string]any, error) {
|
||||
if x, ok := j.d.(*Excel); ok {
|
||||
return x.GetData(sheetName, start, end)
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (j *jsDocument) Set(sheetName string, table [][]any, start, end string) error {
|
||||
if x, ok := j.d.(*Excel); ok {
|
||||
return x.Set(sheetName, table, start, end)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (j *jsDocument) SetData(sheetName string, data []map[string]any, start, end string) error {
|
||||
if x, ok := j.d.(*Excel); ok {
|
||||
return x.SetData(sheetName, data, start, end)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (j *jsDocument) Sheets() []string {
|
||||
if x, ok := j.d.(*Excel); ok {
|
||||
return x.Sheets()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user