cell.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. // Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of
  2. // this source code is governed by a BSD-style license that can be found in
  3. // the LICENSE file.
  4. //
  5. // Package excelize providing a set of functions that allow you to write to
  6. // and read from XLSX files. Support reads and writes XLSX file generated by
  7. // Microsoft Excel™ 2007 and later. Support save file without losing original
  8. // charts of XLSX. This library needs Go version 1.8 or later.
  9. package excelize
  10. import (
  11. "encoding/xml"
  12. "errors"
  13. "fmt"
  14. "reflect"
  15. "strconv"
  16. "strings"
  17. "sync"
  18. "time"
  19. )
  20. const (
  21. // STCellFormulaTypeArray defined the formula is an array formula.
  22. STCellFormulaTypeArray = "array"
  23. // STCellFormulaTypeDataTable defined the formula is a data table formula.
  24. STCellFormulaTypeDataTable = "dataTable"
  25. // STCellFormulaTypeNormal defined the formula is a regular cell formula.
  26. STCellFormulaTypeNormal = "normal"
  27. // STCellFormulaTypeShared defined the formula is part of a shared formula.
  28. STCellFormulaTypeShared = "shared"
  29. )
  30. var rwMutex sync.RWMutex
  31. // GetCellValue provides a function to get formatted value from cell by given
  32. // worksheet name and axis in XLSX file. If it is possible to apply a format
  33. // to the cell value, it will do so, if not then an error will be returned,
  34. // along with the raw value of the cell.
  35. func (f *File) GetCellValue(sheet, axis string) (string, error) {
  36. return f.getCellStringFunc(sheet, axis, func(x *xlsxWorksheet, c *xlsxC) (string, bool, error) {
  37. val, err := c.getValueFrom(f, f.sharedStringsReader())
  38. if err != nil {
  39. return val, false, err
  40. }
  41. return val, true, err
  42. })
  43. }
  44. // SetCellValue provides a function to set value of a cell. The following
  45. // shows the supported data types:
  46. //
  47. // int
  48. // int8
  49. // int16
  50. // int32
  51. // int64
  52. // uint
  53. // uint8
  54. // uint16
  55. // uint32
  56. // uint64
  57. // float32
  58. // float64
  59. // string
  60. // []byte
  61. // time.Duration
  62. // time.Time
  63. // bool
  64. // nil
  65. //
  66. // Note that default date format is m/d/yy h:mm of time.Time type value. You can
  67. // set numbers format by SetCellStyle() method.
  68. func (f *File) SetCellValue(sheet, axis string, value interface{}) error {
  69. var err error
  70. switch v := value.(type) {
  71. case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:
  72. err = f.setCellIntFunc(sheet, axis, v)
  73. case float32:
  74. err = f.SetCellFloat(sheet, axis, float64(v), -1, 32)
  75. case float64:
  76. err = f.SetCellFloat(sheet, axis, v, -1, 64)
  77. case string:
  78. err = f.SetCellStr(sheet, axis, v)
  79. case []byte:
  80. err = f.SetCellStr(sheet, axis, string(v))
  81. case time.Duration:
  82. err = f.SetCellDefault(sheet, axis, strconv.FormatFloat(v.Seconds()/86400.0, 'f', -1, 32))
  83. if err != nil {
  84. return err
  85. }
  86. err = f.setDefaultTimeStyle(sheet, axis, 21)
  87. case time.Time:
  88. err = f.setCellTimeFunc(sheet, axis, v)
  89. case bool:
  90. err = f.SetCellBool(sheet, axis, v)
  91. case nil:
  92. err = f.SetCellStr(sheet, axis, "")
  93. default:
  94. err = f.SetCellStr(sheet, axis, fmt.Sprintf("%v", value))
  95. }
  96. return err
  97. }
  98. // setCellIntFunc is a wrapper of SetCellInt.
  99. func (f *File) setCellIntFunc(sheet, axis string, value interface{}) error {
  100. var err error
  101. switch v := value.(type) {
  102. case int:
  103. err = f.SetCellInt(sheet, axis, v)
  104. case int8:
  105. err = f.SetCellInt(sheet, axis, int(v))
  106. case int16:
  107. err = f.SetCellInt(sheet, axis, int(v))
  108. case int32:
  109. err = f.SetCellInt(sheet, axis, int(v))
  110. case int64:
  111. err = f.SetCellInt(sheet, axis, int(v))
  112. case uint:
  113. err = f.SetCellInt(sheet, axis, int(v))
  114. case uint8:
  115. err = f.SetCellInt(sheet, axis, int(v))
  116. case uint16:
  117. err = f.SetCellInt(sheet, axis, int(v))
  118. case uint32:
  119. err = f.SetCellInt(sheet, axis, int(v))
  120. case uint64:
  121. err = f.SetCellInt(sheet, axis, int(v))
  122. }
  123. return err
  124. }
  125. // setCellTimeFunc provides a method to process time type of value for
  126. // SetCellValue.
  127. func (f *File) setCellTimeFunc(sheet, axis string, value time.Time) error {
  128. excelTime, err := timeToExcelTime(value)
  129. if err != nil {
  130. return err
  131. }
  132. if excelTime > 0 {
  133. err = f.SetCellDefault(sheet, axis, strconv.FormatFloat(excelTime, 'f', -1, 64))
  134. if err != nil {
  135. return err
  136. }
  137. err = f.setDefaultTimeStyle(sheet, axis, 22)
  138. if err != nil {
  139. return err
  140. }
  141. } else {
  142. err = f.SetCellStr(sheet, axis, value.Format(time.RFC3339Nano))
  143. if err != nil {
  144. return err
  145. }
  146. }
  147. return err
  148. }
  149. // SetCellInt provides a function to set int type value of a cell by given
  150. // worksheet name, cell coordinates and cell value.
  151. func (f *File) SetCellInt(sheet, axis string, value int) error {
  152. rwMutex.Lock()
  153. defer rwMutex.Unlock()
  154. xlsx, err := f.workSheetReader(sheet)
  155. if err != nil {
  156. return err
  157. }
  158. cellData, col, _, err := f.prepareCell(xlsx, sheet, axis)
  159. if err != nil {
  160. return err
  161. }
  162. cellData.S = f.prepareCellStyle(xlsx, col, cellData.S)
  163. cellData.T = ""
  164. cellData.V = strconv.Itoa(value)
  165. return err
  166. }
  167. // SetCellBool provides a function to set bool type value of a cell by given
  168. // worksheet name, cell name and cell value.
  169. func (f *File) SetCellBool(sheet, axis string, value bool) error {
  170. rwMutex.Lock()
  171. defer rwMutex.Unlock()
  172. xlsx, err := f.workSheetReader(sheet)
  173. if err != nil {
  174. return err
  175. }
  176. cellData, col, _, err := f.prepareCell(xlsx, sheet, axis)
  177. if err != nil {
  178. return err
  179. }
  180. cellData.S = f.prepareCellStyle(xlsx, col, cellData.S)
  181. cellData.T = "b"
  182. if value {
  183. cellData.V = "1"
  184. } else {
  185. cellData.V = "0"
  186. }
  187. return err
  188. }
  189. // SetCellFloat sets a floating point value into a cell. The prec parameter
  190. // specifies how many places after the decimal will be shown while -1 is a
  191. // special value that will use as many decimal places as necessary to
  192. // represent the number. bitSize is 32 or 64 depending on if a float32 or
  193. // float64 was originally used for the value. For Example:
  194. //
  195. // var x float32 = 1.325
  196. // f.SetCellFloat("Sheet1", "A1", float64(x), 2, 32)
  197. //
  198. func (f *File) SetCellFloat(sheet, axis string, value float64, prec, bitSize int) error {
  199. rwMutex.Lock()
  200. defer rwMutex.Unlock()
  201. xlsx, err := f.workSheetReader(sheet)
  202. if err != nil {
  203. return err
  204. }
  205. cellData, col, _, err := f.prepareCell(xlsx, sheet, axis)
  206. if err != nil {
  207. return err
  208. }
  209. cellData.S = f.prepareCellStyle(xlsx, col, cellData.S)
  210. cellData.T = ""
  211. cellData.V = strconv.FormatFloat(value, 'f', prec, bitSize)
  212. return err
  213. }
  214. // SetCellStr provides a function to set string type value of a cell. Total
  215. // number of characters that a cell can contain 32767 characters.
  216. func (f *File) SetCellStr(sheet, axis, value string) error {
  217. rwMutex.Lock()
  218. defer rwMutex.Unlock()
  219. xlsx, err := f.workSheetReader(sheet)
  220. if err != nil {
  221. return err
  222. }
  223. cellData, col, _, err := f.prepareCell(xlsx, sheet, axis)
  224. if err != nil {
  225. return err
  226. }
  227. if len(value) > 32767 {
  228. value = value[0:32767]
  229. }
  230. // Leading space(s) character detection.
  231. if len(value) > 0 && value[0] == 32 {
  232. cellData.XMLSpace = xml.Attr{
  233. Name: xml.Name{Space: NameSpaceXML, Local: "space"},
  234. Value: "preserve",
  235. }
  236. }
  237. cellData.S = f.prepareCellStyle(xlsx, col, cellData.S)
  238. cellData.T = "str"
  239. cellData.V = value
  240. return err
  241. }
  242. // SetCellDefault provides a function to set string type value of a cell as
  243. // default format without escaping the cell.
  244. func (f *File) SetCellDefault(sheet, axis, value string) error {
  245. xlsx, err := f.workSheetReader(sheet)
  246. if err != nil {
  247. return err
  248. }
  249. cellData, col, _, err := f.prepareCell(xlsx, sheet, axis)
  250. if err != nil {
  251. return err
  252. }
  253. cellData.S = f.prepareCellStyle(xlsx, col, cellData.S)
  254. cellData.T = ""
  255. cellData.V = value
  256. return err
  257. }
  258. // GetCellFormula provides a function to get formula from cell by given
  259. // worksheet name and axis in XLSX file.
  260. func (f *File) GetCellFormula(sheet, axis string) (string, error) {
  261. return f.getCellStringFunc(sheet, axis, func(x *xlsxWorksheet, c *xlsxC) (string, bool, error) {
  262. if c.F == nil {
  263. return "", false, nil
  264. }
  265. if c.F.T == STCellFormulaTypeShared {
  266. return getSharedForumula(x, c.F.Si), true, nil
  267. }
  268. return c.F.Content, true, nil
  269. })
  270. }
  271. // SetCellFormula provides a function to set cell formula by given string and
  272. // worksheet name.
  273. func (f *File) SetCellFormula(sheet, axis, formula string) error {
  274. rwMutex.Lock()
  275. defer rwMutex.Unlock()
  276. xlsx, err := f.workSheetReader(sheet)
  277. if err != nil {
  278. return err
  279. }
  280. cellData, _, _, err := f.prepareCell(xlsx, sheet, axis)
  281. if err != nil {
  282. return err
  283. }
  284. if formula == "" {
  285. cellData.F = nil
  286. f.deleteCalcChain(f.GetSheetIndex(sheet), axis)
  287. return err
  288. }
  289. if cellData.F != nil {
  290. cellData.F.Content = formula
  291. } else {
  292. cellData.F = &xlsxF{Content: formula}
  293. }
  294. return err
  295. }
  296. // GetCellHyperLink provides a function to get cell hyperlink by given
  297. // worksheet name and axis. Boolean type value link will be ture if the cell
  298. // has a hyperlink and the target is the address of the hyperlink. Otherwise,
  299. // the value of link will be false and the value of the target will be a blank
  300. // string. For example get hyperlink of Sheet1!H6:
  301. //
  302. // link, target, err := f.GetCellHyperLink("Sheet1", "H6")
  303. //
  304. func (f *File) GetCellHyperLink(sheet, axis string) (bool, string, error) {
  305. // Check for correct cell name
  306. if _, _, err := SplitCellName(axis); err != nil {
  307. return false, "", err
  308. }
  309. xlsx, err := f.workSheetReader(sheet)
  310. if err != nil {
  311. return false, "", err
  312. }
  313. axis, err = f.mergeCellsParser(xlsx, axis)
  314. if err != nil {
  315. return false, "", err
  316. }
  317. if xlsx.Hyperlinks != nil {
  318. for _, link := range xlsx.Hyperlinks.Hyperlink {
  319. if link.Ref == axis {
  320. if link.RID != "" {
  321. return true, f.getSheetRelationshipsTargetByID(sheet, link.RID), err
  322. }
  323. return true, link.Location, err
  324. }
  325. }
  326. }
  327. return false, "", err
  328. }
  329. // SetCellHyperLink provides a function to set cell hyperlink by given
  330. // worksheet name and link URL address. LinkType defines two types of
  331. // hyperlink "External" for web site or "Location" for moving to one of cell
  332. // in this workbook. Maximum limit hyperlinks in a worksheet is 65530. The
  333. // below is example for external link.
  334. //
  335. // err := f.SetCellHyperLink("Sheet1", "A3", "https://github.com/360EntSecGroup-Skylar/excelize", "External")
  336. // // Set underline and font color style for the cell.
  337. // style, err := f.NewStyle(`{"font":{"color":"#1265BE","underline":"single"}}`)
  338. // err = f.SetCellStyle("Sheet1", "A3", "A3", style)
  339. //
  340. // A this is another example for "Location":
  341. //
  342. // err := f.SetCellHyperLink("Sheet1", "A3", "Sheet1!A40", "Location")
  343. //
  344. func (f *File) SetCellHyperLink(sheet, axis, link, linkType string) error {
  345. // Check for correct cell name
  346. if _, _, err := SplitCellName(axis); err != nil {
  347. return err
  348. }
  349. xlsx, err := f.workSheetReader(sheet)
  350. if err != nil {
  351. return err
  352. }
  353. axis, err = f.mergeCellsParser(xlsx, axis)
  354. if err != nil {
  355. return err
  356. }
  357. var linkData xlsxHyperlink
  358. if xlsx.Hyperlinks == nil {
  359. xlsx.Hyperlinks = new(xlsxHyperlinks)
  360. }
  361. if len(xlsx.Hyperlinks.Hyperlink) > 65529 {
  362. return errors.New("over maximum limit hyperlinks in a worksheet")
  363. }
  364. switch linkType {
  365. case "External":
  366. linkData = xlsxHyperlink{
  367. Ref: axis,
  368. }
  369. rID := f.addSheetRelationships(sheet, SourceRelationshipHyperLink, link, linkType)
  370. linkData.RID = "rId" + strconv.Itoa(rID)
  371. case "Location":
  372. linkData = xlsxHyperlink{
  373. Ref: axis,
  374. Location: link,
  375. }
  376. default:
  377. return fmt.Errorf("invalid link type %q", linkType)
  378. }
  379. xlsx.Hyperlinks.Hyperlink = append(xlsx.Hyperlinks.Hyperlink, linkData)
  380. return nil
  381. }
  382. // MergeCell provides a function to merge cells by given coordinate area and
  383. // sheet name. For example create a merged cell of D3:E9 on Sheet1:
  384. //
  385. // err := f.MergeCell("Sheet1", "D3", "E9")
  386. //
  387. // If you create a merged cell that overlaps with another existing merged cell,
  388. // those merged cells that already exist will be removed.
  389. func (f *File) MergeCell(sheet, hcell, vcell string) error {
  390. hcol, hrow, err := CellNameToCoordinates(hcell)
  391. if err != nil {
  392. return err
  393. }
  394. vcol, vrow, err := CellNameToCoordinates(vcell)
  395. if err != nil {
  396. return err
  397. }
  398. if hcol == vcol && hrow == vrow {
  399. return err
  400. }
  401. // Correct the coordinate area, such correct C1:B3 to B1:C3.
  402. if vcol < hcol {
  403. hcol, vcol = vcol, hcol
  404. }
  405. if vrow < hrow {
  406. hrow, vrow = vrow, hrow
  407. }
  408. hcell, _ = CoordinatesToCellName(hcol, hrow)
  409. vcell, _ = CoordinatesToCellName(vcol, vrow)
  410. xlsx, err := f.workSheetReader(sheet)
  411. if err != nil {
  412. return err
  413. }
  414. if xlsx.MergeCells != nil {
  415. ref := hcell + ":" + vcell
  416. // Delete the merged cells of the overlapping area.
  417. for _, cellData := range xlsx.MergeCells.Cells {
  418. cc := strings.Split(cellData.Ref, ":")
  419. if len(cc) != 2 {
  420. return fmt.Errorf("invalid area %q", cellData.Ref)
  421. }
  422. c1, _ := checkCellInArea(hcell, cellData.Ref)
  423. c2, _ := checkCellInArea(vcell, cellData.Ref)
  424. c3, _ := checkCellInArea(cc[0], ref)
  425. c4, _ := checkCellInArea(cc[1], ref)
  426. if !(!c1 && !c2 && !c3 && !c4) {
  427. return nil
  428. }
  429. }
  430. xlsx.MergeCells.Cells = append(xlsx.MergeCells.Cells, &xlsxMergeCell{Ref: ref})
  431. } else {
  432. xlsx.MergeCells = &xlsxMergeCells{Cells: []*xlsxMergeCell{{Ref: hcell + ":" + vcell}}}
  433. }
  434. return err
  435. }
  436. // SetSheetRow writes an array to row by given worksheet name, starting
  437. // coordinate and a pointer to array type 'slice'. For example, writes an
  438. // array to row 6 start with the cell B6 on Sheet1:
  439. //
  440. // err := f.SetSheetRow("Sheet1", "B6", &[]interface{}{"1", nil, 2})
  441. //
  442. func (f *File) SetSheetRow(sheet, axis string, slice interface{}) error {
  443. col, row, err := CellNameToCoordinates(axis)
  444. if err != nil {
  445. return err
  446. }
  447. // Make sure 'slice' is a Ptr to Slice
  448. v := reflect.ValueOf(slice)
  449. if v.Kind() != reflect.Ptr || v.Elem().Kind() != reflect.Slice {
  450. return errors.New("pointer to slice expected")
  451. }
  452. v = v.Elem()
  453. for i := 0; i < v.Len(); i++ {
  454. cell, err := CoordinatesToCellName(col+i, row)
  455. // Error should never happens here. But keep ckecking to early detect regresions
  456. // if it will be introduced in furure
  457. if err != nil {
  458. return err
  459. }
  460. f.SetCellValue(sheet, cell, v.Index(i).Interface())
  461. }
  462. return err
  463. }
  464. // getCellInfo does common preparation for all SetCell* methods.
  465. func (f *File) prepareCell(xlsx *xlsxWorksheet, sheet, cell string) (*xlsxC, int, int, error) {
  466. var err error
  467. cell, err = f.mergeCellsParser(xlsx, cell)
  468. if err != nil {
  469. return nil, 0, 0, err
  470. }
  471. col, row, err := CellNameToCoordinates(cell)
  472. if err != nil {
  473. return nil, 0, 0, err
  474. }
  475. prepareSheetXML(xlsx, col, row)
  476. return &xlsx.SheetData.Row[row-1].C[col-1], col, row, err
  477. }
  478. // getCellStringFunc does common value extraction workflow for all GetCell*
  479. // methods. Passed function implements specific part of required logic.
  480. func (f *File) getCellStringFunc(sheet, axis string, fn func(x *xlsxWorksheet, c *xlsxC) (string, bool, error)) (string, error) {
  481. xlsx, err := f.workSheetReader(sheet)
  482. if err != nil {
  483. return "", err
  484. }
  485. axis, err = f.mergeCellsParser(xlsx, axis)
  486. if err != nil {
  487. return "", err
  488. }
  489. _, row, err := CellNameToCoordinates(axis)
  490. if err != nil {
  491. return "", err
  492. }
  493. lastRowNum := 0
  494. if l := len(xlsx.SheetData.Row); l > 0 {
  495. lastRowNum = xlsx.SheetData.Row[l-1].R
  496. }
  497. // keep in mind: row starts from 1
  498. if row > lastRowNum {
  499. return "", nil
  500. }
  501. for rowIdx := range xlsx.SheetData.Row {
  502. rowData := &xlsx.SheetData.Row[rowIdx]
  503. if rowData.R != row {
  504. continue
  505. }
  506. for colIdx := range rowData.C {
  507. colData := &rowData.C[colIdx]
  508. if axis != colData.R {
  509. continue
  510. }
  511. val, ok, err := fn(xlsx, colData)
  512. if err != nil {
  513. return "", err
  514. }
  515. if ok {
  516. return val, nil
  517. }
  518. }
  519. }
  520. return "", nil
  521. }
  522. // formattedValue provides a function to returns a value after formatted. If
  523. // it is possible to apply a format to the cell value, it will do so, if not
  524. // then an error will be returned, along with the raw value of the cell.
  525. func (f *File) formattedValue(s int, v string) string {
  526. if s == 0 {
  527. return v
  528. }
  529. styleSheet := f.stylesReader()
  530. ok := builtInNumFmtFunc[styleSheet.CellXfs.Xf[s].NumFmtID]
  531. if ok != nil {
  532. return ok(styleSheet.CellXfs.Xf[s].NumFmtID, v)
  533. }
  534. return v
  535. }
  536. // prepareCellStyle provides a function to prepare style index of cell in
  537. // worksheet by given column index and style index.
  538. func (f *File) prepareCellStyle(xlsx *xlsxWorksheet, col, style int) int {
  539. if xlsx.Cols != nil && style == 0 {
  540. for _, c := range xlsx.Cols.Col {
  541. if c.Min <= col && col <= c.Max {
  542. style = c.Style
  543. }
  544. }
  545. }
  546. return style
  547. }
  548. // mergeCellsParser provides a function to check merged cells in worksheet by
  549. // given axis.
  550. func (f *File) mergeCellsParser(xlsx *xlsxWorksheet, axis string) (string, error) {
  551. axis = strings.ToUpper(axis)
  552. if xlsx.MergeCells != nil {
  553. for i := 0; i < len(xlsx.MergeCells.Cells); i++ {
  554. ok, err := checkCellInArea(axis, xlsx.MergeCells.Cells[i].Ref)
  555. if err != nil {
  556. return axis, err
  557. }
  558. if ok {
  559. axis = strings.Split(xlsx.MergeCells.Cells[i].Ref, ":")[0]
  560. }
  561. }
  562. }
  563. return axis, nil
  564. }
  565. // checkCellInArea provides a function to determine if a given coordinate is
  566. // within an area.
  567. func checkCellInArea(cell, area string) (bool, error) {
  568. col, row, err := CellNameToCoordinates(cell)
  569. if err != nil {
  570. return false, err
  571. }
  572. rng := strings.Split(area, ":")
  573. if len(rng) != 2 {
  574. return false, err
  575. }
  576. firstCol, firstRow, _ := CellNameToCoordinates(rng[0])
  577. lastCol, lastRow, _ := CellNameToCoordinates(rng[1])
  578. return col >= firstCol && col <= lastCol && row >= firstRow && row <= lastRow, err
  579. }
  580. // getSharedForumula find a cell contains the same formula as another cell,
  581. // the "shared" value can be used for the t attribute and the si attribute can
  582. // be used to refer to the cell containing the formula. Two formulas are
  583. // considered to be the same when their respective representations in
  584. // R1C1-reference notation, are the same.
  585. //
  586. // Note that this function not validate ref tag to check the cell if or not in
  587. // allow area, and always return origin shared formula.
  588. func getSharedForumula(xlsx *xlsxWorksheet, si string) string {
  589. for _, r := range xlsx.SheetData.Row {
  590. for _, c := range r.C {
  591. if c.F != nil && c.F.Ref != "" && c.F.T == STCellFormulaTypeShared && c.F.Si == si {
  592. return c.F.Content
  593. }
  594. }
  595. }
  596. return ""
  597. }