- Support insert new lines into shape, relate issue #38, note that the format set parameter of function `AddShape()` changed;
- go test and go doc updated
This commit is contained in:
parent
9928bbc7c8
commit
7bc43301da
|
@ -551,8 +551,10 @@ func TestAddShape(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Log(err)
|
t.Log(err)
|
||||||
}
|
}
|
||||||
xlsx.AddShape("Sheet1", "A30", `{"type":"rect","text":"Rectangle Shape"}`)
|
xlsx.AddShape("Sheet1", "A30", `{"type":"rect","paragraph":[{"text":"Rectangle","font":{"color":"CD5C5C"}},{"text":"Shape","font":{"bold":true,"color":"2980B9"}}]}`)
|
||||||
xlsx.AddShape("Sheet3", "H1", `{"type":"ellipseRibbon", "color":{"line":"#4286f4","fill":"#8eb9ff"}, "font":{"bold":true,"italic":true,"family":"Berlin Sans FB Demi","size":36,"color":"#777777","underline":"single"}, "height": 90}`)
|
xlsx.AddShape("Sheet1", "B30", `{"type":"rect","paragraph":[{"text":"Rectangle"},{}]}`)
|
||||||
|
xlsx.AddShape("Sheet1", "C30", `{"type":"rect","paragraph":[]}`)
|
||||||
|
xlsx.AddShape("Sheet3", "H1", `{"type":"ellipseRibbon", "color":{"line":"#4286f4","fill":"#8eb9ff"}, "paragraph":[{"font":{"bold":true,"italic":true,"family":"Berlin Sans FB Demi","size":36,"color":"#777777","underline":"single"}}], "height": 90}`)
|
||||||
err = xlsx.Save()
|
err = xlsx.Save()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Log(err)
|
t.Log(err)
|
||||||
|
|
61
shape.go
61
shape.go
|
@ -22,15 +22,6 @@ func parseFormatShapeSet(formatSet string) *formatShape {
|
||||||
XScale: 1.0,
|
XScale: 1.0,
|
||||||
YScale: 1.0,
|
YScale: 1.0,
|
||||||
},
|
},
|
||||||
Font: formatFont{
|
|
||||||
Bold: false,
|
|
||||||
Italic: false,
|
|
||||||
Underline: "none",
|
|
||||||
Family: "Calibri",
|
|
||||||
Size: 11,
|
|
||||||
Color: "#000000",
|
|
||||||
},
|
|
||||||
Text: " ",
|
|
||||||
}
|
}
|
||||||
json.Unmarshal([]byte(formatSet), &format)
|
json.Unmarshal([]byte(formatSet), &format)
|
||||||
return &format
|
return &format
|
||||||
|
@ -41,7 +32,7 @@ func parseFormatShapeSet(formatSet string) *formatShape {
|
||||||
// print settings) and properties set. For example, add text box (rect shape) in
|
// print settings) and properties set. For example, add text box (rect shape) in
|
||||||
// Sheet1:
|
// Sheet1:
|
||||||
//
|
//
|
||||||
// xlsx.AddShape("Sheet1", "G6", `{"type":"rect", "text":"Rectangle Shape", "color":{"line":"#4286F4","fill":"#8eb9ff"}, "font":{"bold":true,"italic":true,"family":"Berlin Sans FB Demi","size":36,"color":"#777777","underline":"sng"}, "width": 180, "height": 90}`)
|
// xlsx.AddShape("Sheet1", "G6", `{"type":"rect","color":{"line":"#4286F4","fill":"#8eb9ff"},"paragraph":[{"text":"Rectangle Shape","font":{"bold":true,"italic":true,"family":"Berlin Sans FB Demi","size":36,"color":"#777777","underline":"sng"}}],"width":180,"height": 90}`)
|
||||||
//
|
//
|
||||||
// The following shows the type of chart supported by excelize:
|
// The following shows the type of chart supported by excelize:
|
||||||
//
|
//
|
||||||
|
@ -281,11 +272,6 @@ func (f *File) AddShape(sheet, cell, format string) {
|
||||||
// drawingXMLand format sets.
|
// drawingXMLand format sets.
|
||||||
func (f *File) addDrawingShape(sheet, drawingXML, cell string, formatSet *formatShape) {
|
func (f *File) addDrawingShape(sheet, drawingXML, cell string, formatSet *formatShape) {
|
||||||
textUnderlineType := map[string]bool{"none": true, "words": true, "sng": true, "dbl": true, "heavy": true, "dotted": true, "dottedHeavy": true, "dash": true, "dashHeavy": true, "dashLong": true, "dashLongHeavy": true, "dotDash": true, "dotDashHeavy": true, "dotDotDash": true, "dotDotDashHeavy": true, "wavy": true, "wavyHeavy": true, "wavyDbl": true}
|
textUnderlineType := map[string]bool{"none": true, "words": true, "sng": true, "dbl": true, "heavy": true, "dotted": true, "dottedHeavy": true, "dash": true, "dashHeavy": true, "dashLong": true, "dashLongHeavy": true, "dotDash": true, "dotDashHeavy": true, "dotDotDash": true, "dotDotDashHeavy": true, "wavy": true, "wavyHeavy": true, "wavyDbl": true}
|
||||||
u := formatSet.Font.Underline
|
|
||||||
_, ok := textUnderlineType[u]
|
|
||||||
if !ok {
|
|
||||||
u = "none"
|
|
||||||
}
|
|
||||||
cell = strings.ToUpper(cell)
|
cell = strings.ToUpper(cell)
|
||||||
fromCol := string(strings.Map(letterOnlyMapF, cell))
|
fromCol := string(strings.Map(letterOnlyMapF, cell))
|
||||||
fromRow, _ := strconv.Atoi(strings.Map(intOnlyMapF, cell))
|
fromRow, _ := strconv.Atoi(strings.Map(intOnlyMapF, cell))
|
||||||
|
@ -346,29 +332,56 @@ func (f *File) addDrawingShape(sheet, drawingXML, cell string, formatSet *format
|
||||||
RtlCol: false,
|
RtlCol: false,
|
||||||
Anchor: "t",
|
Anchor: "t",
|
||||||
},
|
},
|
||||||
P: &aP{
|
},
|
||||||
|
}
|
||||||
|
if len(formatSet.Paragraph) < 1 {
|
||||||
|
formatSet.Paragraph = []formatShapeParagraph{
|
||||||
|
{
|
||||||
|
Font: formatFont{
|
||||||
|
Bold: false,
|
||||||
|
Italic: false,
|
||||||
|
Underline: "none",
|
||||||
|
Family: "Calibri",
|
||||||
|
Size: 11,
|
||||||
|
Color: "#000000",
|
||||||
|
},
|
||||||
|
Text: " ",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, p := range formatSet.Paragraph {
|
||||||
|
u := p.Font.Underline
|
||||||
|
_, ok := textUnderlineType[u]
|
||||||
|
if !ok {
|
||||||
|
u = "none"
|
||||||
|
}
|
||||||
|
text := p.Text
|
||||||
|
if text == "" {
|
||||||
|
text = " "
|
||||||
|
}
|
||||||
|
paragraph := &aP{
|
||||||
R: &aR{
|
R: &aR{
|
||||||
RPr: aRPr{
|
RPr: aRPr{
|
||||||
I: formatSet.Font.Italic,
|
I: p.Font.Italic,
|
||||||
B: formatSet.Font.Bold,
|
B: p.Font.Bold,
|
||||||
Lang: "en-US",
|
Lang: "en-US",
|
||||||
AltLang: "en-US",
|
AltLang: "en-US",
|
||||||
U: u,
|
U: u,
|
||||||
Sz: formatSet.Font.Size * 100,
|
Sz: p.Font.Size * 100,
|
||||||
Latin: &aLatin{Typeface: formatSet.Font.Family},
|
Latin: &aLatin{Typeface: p.Font.Family},
|
||||||
SolidFill: &aSolidFill{
|
SolidFill: &aSolidFill{
|
||||||
SrgbClr: &attrValString{
|
SrgbClr: &attrValString{
|
||||||
Val: strings.Replace(strings.ToUpper(formatSet.Font.Color), "#", "", -1),
|
Val: strings.Replace(strings.ToUpper(p.Font.Color), "#", "", -1),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
T: formatSet.Text,
|
T: text,
|
||||||
},
|
},
|
||||||
EndParaRPr: &aEndParaRPr{
|
EndParaRPr: &aEndParaRPr{
|
||||||
Lang: "en-US",
|
Lang: "en-US",
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
},
|
shape.TxBody.P = append(shape.TxBody.P, paragraph)
|
||||||
}
|
}
|
||||||
twoCellAnchor.Sp = &shape
|
twoCellAnchor.Sp = &shape
|
||||||
twoCellAnchor.ClientData = &xdrClientData{
|
twoCellAnchor.ClientData = &xdrClientData{
|
||||||
|
|
|
@ -330,7 +330,7 @@ type aFontRef struct {
|
||||||
// paragraphs multiple runs of text.
|
// paragraphs multiple runs of text.
|
||||||
type xdrTxBody struct {
|
type xdrTxBody struct {
|
||||||
BodyPr *aBodyPr `xml:"a:bodyPr"`
|
BodyPr *aBodyPr `xml:"a:bodyPr"`
|
||||||
P *aP `xml:"a:p"`
|
P []*aP `xml:"a:p"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// formatPicture directly maps the format settings of the picture.
|
// formatPicture directly maps the format settings of the picture.
|
||||||
|
@ -350,11 +350,18 @@ type formatShape struct {
|
||||||
Width int `json:"width"`
|
Width int `json:"width"`
|
||||||
Height int `json:"height"`
|
Height int `json:"height"`
|
||||||
Format formatPicture `json:"format"`
|
Format formatPicture `json:"format"`
|
||||||
Font formatFont `json:"font"`
|
|
||||||
Text string `json:"text"`
|
|
||||||
Color formatShapeColor `json:"color"`
|
Color formatShapeColor `json:"color"`
|
||||||
|
Paragraph []formatShapeParagraph `json:"paragraph"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// formatShapeParagraph directly maps the format settings of the paragraph in
|
||||||
|
// the shape.
|
||||||
|
type formatShapeParagraph struct {
|
||||||
|
Font formatFont `json:"font"`
|
||||||
|
Text string `json:"text"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// formatShapeColor directly maps the color settings of the shape.
|
||||||
type formatShapeColor struct {
|
type formatShapeColor struct {
|
||||||
Line string `json:"line"`
|
Line string `json:"line"`
|
||||||
Fill string `json:"fill"`
|
Fill string `json:"fill"`
|
||||||
|
|
Loading…
Reference in New Issue