forked from JPratama7/gwrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.go
69 lines (56 loc) · 1.43 KB
/
helper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package docs
import (
"strings"
"google.golang.org/api/docs/v1"
)
func ReplaceTextDocs(char, text string) *docs.Request {
tempData := new(docs.Request)
tempData.ReplaceAllText = &docs.ReplaceAllTextRequest{
ContainsText: &docs.SubstringMatchCriteria{MatchCase: true, Text: char},
ReplaceText: text,
}
return tempData
}
func AddTable(column, rows int64) *docs.Request {
temp := new(docs.Request)
table := new(docs.InsertTableRequest)
table.Columns = column
table.Rows = rows
return temp
}
func InsertImage(link string, location *docs.Location, size float64) *docs.Request {
heightweight := docs.Dimension{
Magnitude: size,
Unit: "PT",
ForceSendFields: nil,
NullFields: nil,
}
if size == 0 {
heightweight.Magnitude = 128
}
sizeD := &docs.Size{
Height: &heightweight,
Width: &heightweight,
}
return &docs.Request{
InsertInlineImage: &docs.InsertInlineImageRequest{Location: location, Uri: link, ObjectSize: sizeD},
}
}
func searchTextElement(pattern string, elements ...*docs.ParagraphElement) (res *docs.ParagraphElement) {
if len(elements) < 1 {
return
}
for _, v := range elements {
if v.TextRun == nil {
continue
}
curString1 := strings.ReplaceAll(v.TextRun.Content, "\n", "")
curString2 := strings.ReplaceAll(curString1, "\t", "")
curString3 := strings.ReplaceAll(curString2, " ", "")
if strings.Contains(curString3, pattern) {
res = v
break
}
}
return
}