2022-01-09 00:20:42 +08:00
|
|
|
// Copyright 2016 - 2022 The excelize Authors. All rights reserved. Use of
|
2018-09-14 00:44:23 +08:00
|
|
|
// this source code is governed by a BSD-style license that can be found in
|
|
|
|
// the LICENSE file.
|
|
|
|
//
|
2022-02-17 00:09:11 +08:00
|
|
|
// Package excelize providing a set of functions that allow you to write to and
|
|
|
|
// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and
|
|
|
|
// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later.
|
|
|
|
// Supports complex components by high compatibility, and provided streaming
|
|
|
|
// API for generating or reading data from a worksheet with huge amounts of
|
|
|
|
// data. This library needs Go version 1.15 or later.
|
2018-09-14 00:58:48 +08:00
|
|
|
|
2017-05-13 13:28:21 +08:00
|
|
|
package excelize
|
|
|
|
|
|
|
|
import (
|
2019-12-20 00:30:48 +08:00
|
|
|
"bytes"
|
2017-05-13 13:28:21 +08:00
|
|
|
"encoding/json"
|
|
|
|
"encoding/xml"
|
2018-06-23 19:35:27 +08:00
|
|
|
"fmt"
|
2019-12-20 00:30:48 +08:00
|
|
|
"io"
|
|
|
|
"log"
|
2020-03-31 00:02:00 +08:00
|
|
|
"path/filepath"
|
2017-05-13 13:28:21 +08:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2018-08-06 10:21:24 +08:00
|
|
|
// parseFormatCommentsSet provides a function to parse the format settings of
|
|
|
|
// the comment with default value.
|
2018-05-27 11:25:55 +08:00
|
|
|
func parseFormatCommentsSet(formatSet string) (*formatComment, error) {
|
2017-05-13 13:28:21 +08:00
|
|
|
format := formatComment{
|
|
|
|
Author: "Author:",
|
|
|
|
Text: " ",
|
|
|
|
}
|
2018-07-17 15:28:22 +08:00
|
|
|
err := json.Unmarshal([]byte(formatSet), &format)
|
2018-05-27 11:25:55 +08:00
|
|
|
return &format, err
|
2017-05-13 13:28:21 +08:00
|
|
|
}
|
|
|
|
|
2018-08-06 10:21:24 +08:00
|
|
|
// GetComments retrieves all comments and returns a map of worksheet name to
|
|
|
|
// the worksheet comments.
|
2018-09-14 00:24:49 +08:00
|
|
|
func (f *File) GetComments() (comments map[string][]Comment) {
|
|
|
|
comments = map[string][]Comment{}
|
2020-03-31 00:02:00 +08:00
|
|
|
for n, path := range f.sheetMap {
|
2021-04-26 22:51:35 +08:00
|
|
|
target := f.getSheetComments(filepath.Base(path))
|
|
|
|
if target == "" {
|
|
|
|
continue
|
|
|
|
}
|
2021-04-27 12:46:51 +08:00
|
|
|
if !strings.HasPrefix(target, "/") {
|
2021-04-26 22:51:35 +08:00
|
|
|
target = "xl" + strings.TrimPrefix(target, "..")
|
|
|
|
}
|
|
|
|
if d := f.commentsReader(strings.TrimPrefix(target, "/")); d != nil {
|
2022-03-24 00:19:30 +08:00
|
|
|
var sheetComments []Comment
|
2018-09-14 00:24:49 +08:00
|
|
|
for _, comment := range d.CommentList.Comment {
|
|
|
|
sheetComment := Comment{}
|
2021-04-27 12:46:51 +08:00
|
|
|
if comment.AuthorID < len(d.Authors.Author) {
|
|
|
|
sheetComment.Author = d.Authors.Author[comment.AuthorID]
|
2018-09-14 00:24:49 +08:00
|
|
|
}
|
|
|
|
sheetComment.Ref = comment.Ref
|
|
|
|
sheetComment.AuthorID = comment.AuthorID
|
2019-07-15 09:13:55 +08:00
|
|
|
if comment.Text.T != nil {
|
|
|
|
sheetComment.Text += *comment.Text.T
|
|
|
|
}
|
2018-09-14 00:24:49 +08:00
|
|
|
for _, text := range comment.Text.R {
|
2020-04-06 00:23:27 +08:00
|
|
|
if text.T != nil {
|
|
|
|
sheetComment.Text += text.T.Val
|
|
|
|
}
|
2018-09-14 00:24:49 +08:00
|
|
|
}
|
|
|
|
sheetComments = append(sheetComments, sheetComment)
|
|
|
|
}
|
|
|
|
comments[n] = sheetComments
|
2018-06-30 18:37:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-02-23 16:20:44 +08:00
|
|
|
// getSheetComments provides the method to get the target comment reference by
|
2020-03-31 00:02:00 +08:00
|
|
|
// given worksheet file path.
|
|
|
|
func (f *File) getSheetComments(sheetFile string) string {
|
2022-01-23 00:32:34 +08:00
|
|
|
rels := "xl/worksheets/_rels/" + sheetFile + ".rels"
|
2019-09-16 01:17:35 +08:00
|
|
|
if sheetRels := f.relsReader(rels); sheetRels != nil {
|
2021-07-06 00:31:04 +08:00
|
|
|
sheetRels.Lock()
|
|
|
|
defer sheetRels.Unlock()
|
2019-02-26 14:21:44 +08:00
|
|
|
for _, v := range sheetRels.Relationships {
|
|
|
|
if v.Type == SourceRelationshipComments {
|
|
|
|
return v.Target
|
|
|
|
}
|
2019-02-23 16:20:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2017-05-13 13:28:21 +08:00
|
|
|
// AddComment provides the method to add comment in a sheet by given worksheet
|
2017-05-13 14:12:43 +08:00
|
|
|
// index, cell and format set (such as author and text). Note that the max
|
|
|
|
// author length is 255 and the max text length is 32512. For example, add a
|
2017-05-13 13:28:21 +08:00
|
|
|
// comment in Sheet1!$A$30:
|
|
|
|
//
|
2022-08-13 11:21:59 +08:00
|
|
|
// err := f.AddComment("Sheet1", "A30", `{"author":"Excelize: ","text":"This is a comment."}`)
|
2018-05-27 11:25:55 +08:00
|
|
|
func (f *File) AddComment(sheet, cell, format string) error {
|
|
|
|
formatSet, err := parseFormatCommentsSet(format)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-05-13 13:28:21 +08:00
|
|
|
// Read sheet data.
|
2020-11-10 23:48:09 +08:00
|
|
|
ws, err := f.workSheetReader(sheet)
|
2019-04-15 11:22:57 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-05-13 13:28:21 +08:00
|
|
|
commentID := f.countComments() + 1
|
|
|
|
drawingVML := "xl/drawings/vmlDrawing" + strconv.Itoa(commentID) + ".vml"
|
|
|
|
sheetRelationshipsComments := "../comments" + strconv.Itoa(commentID) + ".xml"
|
|
|
|
sheetRelationshipsDrawingVML := "../drawings/vmlDrawing" + strconv.Itoa(commentID) + ".vml"
|
2020-11-10 23:48:09 +08:00
|
|
|
if ws.LegacyDrawing != nil {
|
2017-05-13 13:28:21 +08:00
|
|
|
// The worksheet already has a comments relationships, use the relationships drawing ../drawings/vmlDrawing%d.vml.
|
2020-11-10 23:48:09 +08:00
|
|
|
sheetRelationshipsDrawingVML = f.getSheetRelationshipsTargetByID(sheet, ws.LegacyDrawing.RID)
|
2017-05-13 13:28:21 +08:00
|
|
|
commentID, _ = strconv.Atoi(strings.TrimSuffix(strings.TrimPrefix(sheetRelationshipsDrawingVML, "../drawings/vmlDrawing"), ".vml"))
|
2022-06-12 00:19:12 +08:00
|
|
|
drawingVML = strings.ReplaceAll(sheetRelationshipsDrawingVML, "..", "xl")
|
2017-05-13 13:28:21 +08:00
|
|
|
} else {
|
|
|
|
// Add first comment for given sheet.
|
2022-07-18 00:21:34 +08:00
|
|
|
sheetXMLPath, _ := f.getSheetXMLPath(sheet)
|
|
|
|
sheetRels := "xl/worksheets/_rels/" + strings.TrimPrefix(sheetXMLPath, "xl/worksheets/") + ".rels"
|
2019-09-16 01:17:35 +08:00
|
|
|
rID := f.addRels(sheetRels, SourceRelationshipDrawingVML, sheetRelationshipsDrawingVML, "")
|
|
|
|
f.addRels(sheetRels, SourceRelationshipComments, sheetRelationshipsComments, "")
|
2020-07-18 15:15:16 +08:00
|
|
|
f.addSheetNameSpace(sheet, SourceRelationship)
|
2017-05-13 13:28:21 +08:00
|
|
|
f.addSheetLegacyDrawing(sheet, rID)
|
|
|
|
}
|
|
|
|
commentsXML := "xl/comments" + strconv.Itoa(commentID) + ".xml"
|
2018-06-23 19:35:27 +08:00
|
|
|
var colCount int
|
|
|
|
for i, l := range strings.Split(formatSet.Text, "\n") {
|
|
|
|
if ll := len(l); ll > colCount {
|
|
|
|
if i == 0 {
|
|
|
|
ll += len(formatSet.Author)
|
|
|
|
}
|
|
|
|
colCount = ll
|
|
|
|
}
|
|
|
|
}
|
2019-03-23 20:08:06 +08:00
|
|
|
err = f.addDrawingVML(commentID, drawingVML, cell, strings.Count(formatSet.Text, "\n")+1, colCount)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-03-31 00:02:00 +08:00
|
|
|
f.addComment(commentsXML, cell, formatSet)
|
2017-05-24 14:17:35 +08:00
|
|
|
f.addContentTypePart(commentID, "comments")
|
2018-05-27 11:25:55 +08:00
|
|
|
return err
|
2017-05-13 13:28:21 +08:00
|
|
|
}
|
|
|
|
|
2022-08-19 23:24:13 +08:00
|
|
|
// DeleteComment provides the method to delete comment in a sheet by given
|
|
|
|
// worksheet. For example, delete the comment in Sheet1!$A$30:
|
|
|
|
//
|
|
|
|
// err := f.DeleteComment("Sheet1", "A30")
|
|
|
|
func (f *File) DeleteComment(sheet, cell string) (err error) {
|
|
|
|
sheetXMLPath, ok := f.getSheetXMLPath(sheet)
|
|
|
|
if !ok {
|
|
|
|
err = newNoExistSheetError(sheet)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
commentsXML := f.getSheetComments(filepath.Base(sheetXMLPath))
|
|
|
|
if !strings.HasPrefix(commentsXML, "/") {
|
|
|
|
commentsXML = "xl" + strings.TrimPrefix(commentsXML, "..")
|
|
|
|
}
|
|
|
|
commentsXML = strings.TrimPrefix(commentsXML, "/")
|
|
|
|
if comments := f.commentsReader(commentsXML); comments != nil {
|
|
|
|
for i, cmt := range comments.CommentList.Comment {
|
|
|
|
if cmt.Ref == cell {
|
|
|
|
if len(comments.CommentList.Comment) > 1 {
|
|
|
|
comments.CommentList.Comment = append(
|
|
|
|
comments.CommentList.Comment[:i],
|
|
|
|
comments.CommentList.Comment[i+1:]...,
|
|
|
|
)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
comments.CommentList.Comment = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
f.Comments[commentsXML] = comments
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-08-06 10:21:24 +08:00
|
|
|
// addDrawingVML provides a function to create comment as
|
2017-05-13 13:28:21 +08:00
|
|
|
// xl/drawings/vmlDrawing%d.vml by given commit ID and cell.
|
2019-03-23 20:08:06 +08:00
|
|
|
func (f *File) addDrawingVML(commentID int, drawingVML, cell string, lineCount, colCount int) error {
|
|
|
|
col, row, err := CellNameToCoordinates(cell)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
Huge refactorig for consistent col/row numbering (#356)
* Huge refactorig for consistent col/row numbering
Started from simply changing ToALphaString()/TitleToNumber() logic and related fixes.
But have to go deeper, do fixes, after do related fixes and again and again.
Major improvements:
1. Tests made stronger again (But still be weak).
2. "Empty" returns for incorrect input replaces with panic.
3. Check for correct col/row/cell naming & addressing by default.
4. Removed huge amount of duplicated code.
5. Removed ToALphaString(), TitleToNumber() and it helpers functions at all,
and replaced with SplitCellName(), JoinCellName(), ColumnNameToNumber(), ColumnNumberToName(), CellNameToCoordinates(), CoordinatesToCellName().
6. Minor fixes for internal variable naming for code readability (ex. col, row for input params, colIdx, rowIdx for slice indexes etc).
* Formatting fixes
2019-03-20 00:14:41 +08:00
|
|
|
yAxis := col - 1
|
2017-05-13 13:28:21 +08:00
|
|
|
xAxis := row - 1
|
2019-02-25 00:29:58 +08:00
|
|
|
vml := f.VMLDrawing[drawingVML]
|
|
|
|
if vml == nil {
|
|
|
|
vml = &vmlDrawing{
|
|
|
|
XMLNSv: "urn:schemas-microsoft-com:vml",
|
|
|
|
XMLNSo: "urn:schemas-microsoft-com:office:office",
|
|
|
|
XMLNSx: "urn:schemas-microsoft-com:office:excel",
|
|
|
|
XMLNSmv: "http://macVmlSchemaUri",
|
|
|
|
Shapelayout: &xlsxShapelayout{
|
|
|
|
Ext: "edit",
|
|
|
|
IDmap: &xlsxIDmap{
|
|
|
|
Ext: "edit",
|
|
|
|
Data: commentID,
|
|
|
|
},
|
2017-05-13 13:28:21 +08:00
|
|
|
},
|
2019-02-25 00:29:58 +08:00
|
|
|
Shapetype: &xlsxShapetype{
|
|
|
|
ID: "_x0000_t202",
|
|
|
|
Coordsize: "21600,21600",
|
|
|
|
Spt: 202,
|
|
|
|
Path: "m0,0l0,21600,21600,21600,21600,0xe",
|
|
|
|
Stroke: &xlsxStroke{
|
|
|
|
Joinstyle: "miter",
|
|
|
|
},
|
|
|
|
VPath: &vPath{
|
|
|
|
Gradientshapeok: "t",
|
2020-07-22 20:20:00 +08:00
|
|
|
Connecttype: "rect",
|
2019-02-25 00:29:58 +08:00
|
|
|
},
|
2017-05-13 13:28:21 +08:00
|
|
|
},
|
2019-02-25 00:29:58 +08:00
|
|
|
}
|
2022-08-17 10:59:52 +08:00
|
|
|
// load exist comment shapes from xl/drawings/vmlDrawing%d.vml
|
2022-08-10 10:35:33 +08:00
|
|
|
d := f.decodeVMLDrawingReader(drawingVML)
|
|
|
|
if d != nil {
|
|
|
|
for _, v := range d.Shape {
|
|
|
|
s := xlsxShape{
|
|
|
|
ID: "_x0000_s1025",
|
|
|
|
Type: "#_x0000_t202",
|
|
|
|
Style: "position:absolute;73.5pt;width:108pt;height:59.25pt;z-index:1;visibility:hidden",
|
|
|
|
Fillcolor: "#fbf6d6",
|
|
|
|
Strokecolor: "#edeaa1",
|
|
|
|
Val: v.Val,
|
|
|
|
}
|
|
|
|
vml.Shape = append(vml.Shape, s)
|
|
|
|
}
|
|
|
|
}
|
2017-05-13 13:28:21 +08:00
|
|
|
}
|
|
|
|
sp := encodeShape{
|
|
|
|
Fill: &vFill{
|
|
|
|
Color2: "#fbfe82",
|
|
|
|
Angle: -180,
|
|
|
|
Type: "gradient",
|
|
|
|
Fill: &oFill{
|
|
|
|
Ext: "view",
|
|
|
|
Type: "gradientUnscaled",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Shadow: &vShadow{
|
|
|
|
On: "t",
|
|
|
|
Color: "black",
|
|
|
|
Obscured: "t",
|
|
|
|
},
|
|
|
|
Path: &vPath{
|
|
|
|
Connecttype: "none",
|
|
|
|
},
|
|
|
|
Textbox: &vTextbox{
|
|
|
|
Style: "mso-direction-alt:auto",
|
|
|
|
Div: &xlsxDiv{
|
|
|
|
Style: "text-align:left",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ClientData: &xClientData{
|
|
|
|
ObjectType: "Note",
|
2018-06-23 19:35:27 +08:00
|
|
|
Anchor: fmt.Sprintf(
|
|
|
|
"%d, 23, %d, 0, %d, %d, %d, 5",
|
2018-06-28 10:03:53 +08:00
|
|
|
1+yAxis, 1+xAxis, 2+yAxis+lineCount, colCount+yAxis, 2+xAxis+lineCount),
|
2018-06-23 19:35:27 +08:00
|
|
|
AutoFill: "True",
|
|
|
|
Row: xAxis,
|
|
|
|
Column: yAxis,
|
2017-05-13 13:28:21 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
s, _ := xml.Marshal(sp)
|
|
|
|
shape := xlsxShape{
|
|
|
|
ID: "_x0000_s1025",
|
|
|
|
Type: "#_x0000_t202",
|
|
|
|
Style: "position:absolute;73.5pt;width:108pt;height:59.25pt;z-index:1;visibility:hidden",
|
|
|
|
Fillcolor: "#fbf6d6",
|
|
|
|
Strokecolor: "#edeaa1",
|
|
|
|
Val: string(s[13 : len(s)-14]),
|
|
|
|
}
|
|
|
|
vml.Shape = append(vml.Shape, shape)
|
2019-02-25 00:29:58 +08:00
|
|
|
f.VMLDrawing[drawingVML] = vml
|
2019-03-23 20:08:06 +08:00
|
|
|
return err
|
2017-05-13 13:28:21 +08:00
|
|
|
}
|
|
|
|
|
2018-08-06 10:21:24 +08:00
|
|
|
// addComment provides a function to create chart as xl/comments%d.xml by
|
|
|
|
// given cell and format sets.
|
2017-05-13 13:28:21 +08:00
|
|
|
func (f *File) addComment(commentsXML, cell string, formatSet *formatComment) {
|
2017-05-13 14:12:43 +08:00
|
|
|
a := formatSet.Author
|
|
|
|
t := formatSet.Text
|
2021-11-16 00:40:44 +08:00
|
|
|
if len(a) > MaxFieldLength {
|
|
|
|
a = a[:MaxFieldLength]
|
2017-05-13 14:12:43 +08:00
|
|
|
}
|
|
|
|
if len(t) > 32512 {
|
2021-11-16 00:40:44 +08:00
|
|
|
t = t[:32512]
|
2017-05-13 14:12:43 +08:00
|
|
|
}
|
2019-02-25 00:29:58 +08:00
|
|
|
comments := f.commentsReader(commentsXML)
|
2021-04-27 12:46:51 +08:00
|
|
|
authorID := 0
|
2019-02-25 00:29:58 +08:00
|
|
|
if comments == nil {
|
2021-04-27 12:46:51 +08:00
|
|
|
comments = &xlsxComments{Authors: xlsxAuthor{Author: []string{formatSet.Author}}}
|
|
|
|
}
|
2022-02-13 00:06:30 +08:00
|
|
|
if inStrSlice(comments.Authors.Author, formatSet.Author, true) == -1 {
|
2021-04-27 12:46:51 +08:00
|
|
|
comments.Authors.Author = append(comments.Authors.Author, formatSet.Author)
|
|
|
|
authorID = len(comments.Authors.Author) - 1
|
2017-05-13 13:28:21 +08:00
|
|
|
}
|
2019-04-26 00:24:25 +08:00
|
|
|
defaultFont := f.GetDefaultFont()
|
2021-02-22 20:04:13 +08:00
|
|
|
bold := ""
|
2017-05-13 13:28:21 +08:00
|
|
|
cmt := xlsxComment{
|
|
|
|
Ref: cell,
|
2021-04-27 12:46:51 +08:00
|
|
|
AuthorID: authorID,
|
2017-05-13 13:28:21 +08:00
|
|
|
Text: xlsxText{
|
|
|
|
R: []xlsxR{
|
2017-05-16 20:42:01 +08:00
|
|
|
{
|
2017-05-13 13:28:21 +08:00
|
|
|
RPr: &xlsxRPr{
|
2021-02-22 20:04:13 +08:00
|
|
|
B: &bold,
|
2019-12-23 00:07:40 +08:00
|
|
|
Sz: &attrValFloat{Val: float64Ptr(9)},
|
2017-05-13 13:28:21 +08:00
|
|
|
Color: &xlsxColor{
|
|
|
|
Indexed: 81,
|
|
|
|
},
|
2019-12-23 00:07:40 +08:00
|
|
|
RFont: &attrValString{Val: stringPtr(defaultFont)},
|
|
|
|
Family: &attrValInt{Val: intPtr(2)},
|
2017-05-13 13:28:21 +08:00
|
|
|
},
|
2020-04-06 00:23:27 +08:00
|
|
|
T: &xlsxT{Val: a},
|
2017-05-13 13:28:21 +08:00
|
|
|
},
|
2017-05-16 20:42:01 +08:00
|
|
|
{
|
2017-05-13 13:28:21 +08:00
|
|
|
RPr: &xlsxRPr{
|
2019-12-23 00:07:40 +08:00
|
|
|
Sz: &attrValFloat{Val: float64Ptr(9)},
|
2017-05-13 13:28:21 +08:00
|
|
|
Color: &xlsxColor{
|
|
|
|
Indexed: 81,
|
|
|
|
},
|
2019-12-23 00:07:40 +08:00
|
|
|
RFont: &attrValString{Val: stringPtr(defaultFont)},
|
|
|
|
Family: &attrValInt{Val: intPtr(2)},
|
2017-05-13 13:28:21 +08:00
|
|
|
},
|
2020-04-06 00:23:27 +08:00
|
|
|
T: &xlsxT{Val: t},
|
2017-05-13 13:28:21 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
comments.CommentList.Comment = append(comments.CommentList.Comment, cmt)
|
2019-02-25 00:29:58 +08:00
|
|
|
f.Comments[commentsXML] = comments
|
2017-05-13 13:28:21 +08:00
|
|
|
}
|
|
|
|
|
2018-08-06 10:21:24 +08:00
|
|
|
// countComments provides a function to get comments files count storage in
|
|
|
|
// the folder xl.
|
2017-05-13 13:28:21 +08:00
|
|
|
func (f *File) countComments() int {
|
2019-05-11 09:46:20 +08:00
|
|
|
c1, c2 := 0, 0
|
2021-07-05 00:03:56 +08:00
|
|
|
f.Pkg.Range(func(k, v interface{}) bool {
|
|
|
|
if strings.Contains(k.(string), "xl/comments") {
|
2019-05-11 09:46:20 +08:00
|
|
|
c1++
|
2017-05-13 13:28:21 +08:00
|
|
|
}
|
2021-07-05 00:03:56 +08:00
|
|
|
return true
|
|
|
|
})
|
2019-05-11 09:46:20 +08:00
|
|
|
for rel := range f.Comments {
|
|
|
|
if strings.Contains(rel, "xl/comments") {
|
|
|
|
c2++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if c1 < c2 {
|
|
|
|
return c2
|
|
|
|
}
|
|
|
|
return c1
|
2017-05-13 13:28:21 +08:00
|
|
|
}
|
2019-02-25 00:29:58 +08:00
|
|
|
|
|
|
|
// decodeVMLDrawingReader provides a function to get the pointer to the
|
|
|
|
// structure after deserialization of xl/drawings/vmlDrawing%d.xml.
|
|
|
|
func (f *File) decodeVMLDrawingReader(path string) *decodeVmlDrawing {
|
2019-12-20 00:30:48 +08:00
|
|
|
var err error
|
|
|
|
|
2019-02-25 00:29:58 +08:00
|
|
|
if f.DecodeVMLDrawing[path] == nil {
|
2021-07-05 00:03:56 +08:00
|
|
|
c, ok := f.Pkg.Load(path)
|
|
|
|
if ok && c != nil {
|
2019-12-20 00:30:48 +08:00
|
|
|
f.DecodeVMLDrawing[path] = new(decodeVmlDrawing)
|
2021-07-05 00:03:56 +08:00
|
|
|
if err = f.xmlNewDecoder(bytes.NewReader(namespaceStrictToTransitional(c.([]byte)))).
|
2019-12-20 00:30:48 +08:00
|
|
|
Decode(f.DecodeVMLDrawing[path]); err != nil && err != io.EOF {
|
|
|
|
log.Printf("xml decode error: %s", err)
|
|
|
|
}
|
2019-02-25 00:29:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return f.DecodeVMLDrawing[path]
|
|
|
|
}
|
|
|
|
|
2019-02-25 22:14:34 +08:00
|
|
|
// vmlDrawingWriter provides a function to save xl/drawings/vmlDrawing%d.xml
|
2019-02-25 00:29:58 +08:00
|
|
|
// after serialize structure.
|
|
|
|
func (f *File) vmlDrawingWriter() {
|
|
|
|
for path, vml := range f.VMLDrawing {
|
|
|
|
if vml != nil {
|
|
|
|
v, _ := xml.Marshal(vml)
|
2021-07-05 00:03:56 +08:00
|
|
|
f.Pkg.Store(path, v)
|
2019-02-25 00:29:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// commentsReader provides a function to get the pointer to the structure
|
|
|
|
// after deserialization of xl/comments%d.xml.
|
|
|
|
func (f *File) commentsReader(path string) *xlsxComments {
|
2019-12-20 00:30:48 +08:00
|
|
|
var err error
|
2019-02-25 00:29:58 +08:00
|
|
|
if f.Comments[path] == nil {
|
2021-07-05 00:03:56 +08:00
|
|
|
content, ok := f.Pkg.Load(path)
|
|
|
|
if ok && content != nil {
|
2019-12-20 00:30:48 +08:00
|
|
|
f.Comments[path] = new(xlsxComments)
|
2021-07-05 00:03:56 +08:00
|
|
|
if err = f.xmlNewDecoder(bytes.NewReader(namespaceStrictToTransitional(content.([]byte)))).
|
2019-12-20 00:30:48 +08:00
|
|
|
Decode(f.Comments[path]); err != nil && err != io.EOF {
|
|
|
|
log.Printf("xml decode error: %s", err)
|
|
|
|
}
|
2019-02-25 00:29:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return f.Comments[path]
|
|
|
|
}
|
|
|
|
|
|
|
|
// commentsWriter provides a function to save xl/comments%d.xml after
|
|
|
|
// serialize structure.
|
|
|
|
func (f *File) commentsWriter() {
|
|
|
|
for path, c := range f.Comments {
|
|
|
|
if c != nil {
|
|
|
|
v, _ := xml.Marshal(c)
|
|
|
|
f.saveFileList(path, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|