rows.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. // Copyright 2016 - 2020 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 / XLSM / XLTM files. Supports reading and writing
  7. // spreadsheet documents generated by Microsoft Exce™ 2007 and later. Supports
  8. // complex components by high compatibility, and provided streaming API for
  9. // generating or reading data from a worksheet with huge amounts of data. This
  10. // library needs Go version 1.10 or later.
  11. package excelize
  12. import (
  13. "bytes"
  14. "encoding/xml"
  15. "errors"
  16. "fmt"
  17. "io"
  18. "log"
  19. "math"
  20. "strconv"
  21. "github.com/mohae/deepcopy"
  22. )
  23. // GetRows return all the rows in a sheet by given worksheet name (case
  24. // sensitive). For example:
  25. //
  26. // rows, err := f.GetRows("Sheet1")
  27. // if err != nil {
  28. // fmt.Println(err)
  29. // return
  30. // }
  31. // for _, row := range rows {
  32. // for _, colCell := range row {
  33. // fmt.Print(colCell, "\t")
  34. // }
  35. // fmt.Println()
  36. // }
  37. //
  38. func (f *File) GetRows(sheet string) ([][]string, error) {
  39. rows, err := f.Rows(sheet)
  40. if err != nil {
  41. return nil, err
  42. }
  43. results := make([][]string, 0, 64)
  44. for rows.Next() {
  45. row, err := rows.Columns()
  46. if err != nil {
  47. break
  48. }
  49. results = append(results, row)
  50. }
  51. return results, nil
  52. }
  53. // Rows defines an iterator to a sheet.
  54. type Rows struct {
  55. err error
  56. curRow, totalRow, stashRow int
  57. sheet string
  58. rows []xlsxRow
  59. f *File
  60. decoder *xml.Decoder
  61. }
  62. // Next will return true if find the next row element.
  63. func (rows *Rows) Next() bool {
  64. rows.curRow++
  65. return rows.curRow <= rows.totalRow
  66. }
  67. // Error will return the error when the error occurs.
  68. func (rows *Rows) Error() error {
  69. return rows.err
  70. }
  71. // Columns return the current row's column values.
  72. func (rows *Rows) Columns() ([]string, error) {
  73. var (
  74. err error
  75. inElement string
  76. attrR, cellCol, row int
  77. columns []string
  78. )
  79. if rows.stashRow >= rows.curRow {
  80. return columns, err
  81. }
  82. d := rows.f.sharedStringsReader()
  83. for {
  84. token, _ := rows.decoder.Token()
  85. if token == nil {
  86. break
  87. }
  88. switch startElement := token.(type) {
  89. case xml.StartElement:
  90. inElement = startElement.Name.Local
  91. if inElement == "row" {
  92. row++
  93. if attrR, err = attrValToInt("r", startElement.Attr); attrR != 0 {
  94. row = attrR
  95. }
  96. if row > rows.curRow {
  97. rows.stashRow = row - 1
  98. return columns, err
  99. }
  100. }
  101. if inElement == "c" {
  102. cellCol++
  103. colCell := xlsxC{}
  104. _ = rows.decoder.DecodeElement(&colCell, &startElement)
  105. if colCell.R != "" {
  106. if cellCol, _, err = CellNameToCoordinates(colCell.R); err != nil {
  107. return columns, err
  108. }
  109. }
  110. blank := cellCol - len(columns)
  111. val, _ := colCell.getValueFrom(rows.f, d)
  112. columns = append(appendSpace(blank, columns), val)
  113. }
  114. case xml.EndElement:
  115. inElement = startElement.Name.Local
  116. if row == 0 {
  117. row = rows.curRow
  118. }
  119. if inElement == "row" && row+1 < rows.curRow {
  120. return columns, err
  121. }
  122. }
  123. }
  124. return columns, err
  125. }
  126. // appendSpace append blank characters to slice by given length and source slice.
  127. func appendSpace(l int, s []string) []string {
  128. for i := 1; i < l; i++ {
  129. s = append(s, "")
  130. }
  131. return s
  132. }
  133. // ErrSheetNotExist defines an error of sheet is not exist
  134. type ErrSheetNotExist struct {
  135. SheetName string
  136. }
  137. func (err ErrSheetNotExist) Error() string {
  138. return fmt.Sprintf("sheet %s is not exist", string(err.SheetName))
  139. }
  140. // Rows returns a rows iterator, used for streaming reading data for a
  141. // worksheet with a large data. For example:
  142. //
  143. // rows, err := f.Rows("Sheet1")
  144. // if err != nil {
  145. // fmt.Println(err)
  146. // return
  147. // }
  148. // for rows.Next() {
  149. // row, err := rows.Columns()
  150. // if err != nil {
  151. // fmt.Println(err)
  152. // }
  153. // for _, colCell := range row {
  154. // fmt.Print(colCell, "\t")
  155. // }
  156. // fmt.Println()
  157. // }
  158. //
  159. func (f *File) Rows(sheet string) (*Rows, error) {
  160. name, ok := f.sheetMap[trimSheetName(sheet)]
  161. if !ok {
  162. return nil, ErrSheetNotExist{sheet}
  163. }
  164. if f.Sheet[name] != nil {
  165. // flush data
  166. output, _ := xml.Marshal(f.Sheet[name])
  167. f.saveFileList(name, f.replaceNameSpaceBytes(name, output))
  168. }
  169. var (
  170. err error
  171. inElement string
  172. row int
  173. rows Rows
  174. )
  175. decoder := f.xmlNewDecoder(bytes.NewReader(f.readXML(name)))
  176. for {
  177. token, _ := decoder.Token()
  178. if token == nil {
  179. break
  180. }
  181. switch startElement := token.(type) {
  182. case xml.StartElement:
  183. inElement = startElement.Name.Local
  184. if inElement == "row" {
  185. row++
  186. for _, attr := range startElement.Attr {
  187. if attr.Name.Local == "r" {
  188. row, err = strconv.Atoi(attr.Value)
  189. if err != nil {
  190. return &rows, err
  191. }
  192. }
  193. }
  194. rows.totalRow = row
  195. }
  196. default:
  197. }
  198. }
  199. rows.f = f
  200. rows.sheet = name
  201. rows.decoder = f.xmlNewDecoder(bytes.NewReader(f.readXML(name)))
  202. return &rows, nil
  203. }
  204. // SetRowHeight provides a function to set the height of a single row. For
  205. // example, set the height of the first row in Sheet1:
  206. //
  207. // err := f.SetRowHeight("Sheet1", 1, 50)
  208. //
  209. func (f *File) SetRowHeight(sheet string, row int, height float64) error {
  210. if row < 1 {
  211. return newInvalidRowNumberError(row)
  212. }
  213. if height > MaxRowHeight {
  214. return errors.New("the height of the row must be smaller than or equal to 409 points")
  215. }
  216. ws, err := f.workSheetReader(sheet)
  217. if err != nil {
  218. return err
  219. }
  220. prepareSheetXML(ws, 0, row)
  221. rowIdx := row - 1
  222. ws.SheetData.Row[rowIdx].Ht = height
  223. ws.SheetData.Row[rowIdx].CustomHeight = true
  224. return nil
  225. }
  226. // getRowHeight provides a function to get row height in pixels by given sheet
  227. // name and row index.
  228. func (f *File) getRowHeight(sheet string, row int) int {
  229. ws, _ := f.workSheetReader(sheet)
  230. for i := range ws.SheetData.Row {
  231. v := &ws.SheetData.Row[i]
  232. if v.R == row+1 && v.Ht != 0 {
  233. return int(convertRowHeightToPixels(v.Ht))
  234. }
  235. }
  236. // Optimisation for when the row heights haven't changed.
  237. return int(defaultRowHeightPixels)
  238. }
  239. // GetRowHeight provides a function to get row height by given worksheet name
  240. // and row index. For example, get the height of the first row in Sheet1:
  241. //
  242. // height, err := f.GetRowHeight("Sheet1", 1)
  243. //
  244. func (f *File) GetRowHeight(sheet string, row int) (float64, error) {
  245. if row < 1 {
  246. return defaultRowHeightPixels, newInvalidRowNumberError(row)
  247. }
  248. var ht = defaultRowHeight
  249. ws, err := f.workSheetReader(sheet)
  250. if err != nil {
  251. return ht, err
  252. }
  253. if ws.SheetFormatPr != nil {
  254. ht = ws.SheetFormatPr.DefaultRowHeight
  255. }
  256. if row > len(ws.SheetData.Row) {
  257. return ht, nil // it will be better to use 0, but we take care with BC
  258. }
  259. for _, v := range ws.SheetData.Row {
  260. if v.R == row && v.Ht != 0 {
  261. return v.Ht, nil
  262. }
  263. }
  264. // Optimisation for when the row heights haven't changed.
  265. return ht, nil
  266. }
  267. // sharedStringsReader provides a function to get the pointer to the structure
  268. // after deserialization of xl/sharedStrings.xml.
  269. func (f *File) sharedStringsReader() *xlsxSST {
  270. var err error
  271. f.Lock()
  272. defer f.Unlock()
  273. relPath := f.getWorkbookRelsPath()
  274. if f.SharedStrings == nil {
  275. var sharedStrings xlsxSST
  276. ss := f.readXML("xl/sharedStrings.xml")
  277. if err = f.xmlNewDecoder(bytes.NewReader(namespaceStrictToTransitional(ss))).
  278. Decode(&sharedStrings); err != nil && err != io.EOF {
  279. log.Printf("xml decode error: %s", err)
  280. }
  281. if sharedStrings.UniqueCount == 0 {
  282. sharedStrings.UniqueCount = sharedStrings.Count
  283. }
  284. f.SharedStrings = &sharedStrings
  285. for i := range sharedStrings.SI {
  286. if sharedStrings.SI[i].T != nil {
  287. f.sharedStringsMap[sharedStrings.SI[i].T.Val] = i
  288. }
  289. }
  290. f.addContentTypePart(0, "sharedStrings")
  291. rels := f.relsReader(relPath)
  292. for _, rel := range rels.Relationships {
  293. if rel.Target == "/xl/sharedStrings.xml" {
  294. return f.SharedStrings
  295. }
  296. }
  297. // Update workbook.xml.rels
  298. f.addRels(relPath, SourceRelationshipSharedStrings, "/xl/sharedStrings.xml", "")
  299. }
  300. return f.SharedStrings
  301. }
  302. // getValueFrom return a value from a column/row cell, this function is
  303. // inteded to be used with for range on rows an argument with the spreadsheet
  304. // opened file.
  305. func (c *xlsxC) getValueFrom(f *File, d *xlsxSST) (string, error) {
  306. f.Lock()
  307. defer f.Unlock()
  308. switch c.T {
  309. case "s":
  310. if c.V != "" {
  311. xlsxSI := 0
  312. xlsxSI, _ = strconv.Atoi(c.V)
  313. if len(d.SI) > xlsxSI {
  314. return f.formattedValue(c.S, d.SI[xlsxSI].String()), nil
  315. }
  316. }
  317. return f.formattedValue(c.S, c.V), nil
  318. case "str":
  319. return f.formattedValue(c.S, c.V), nil
  320. case "inlineStr":
  321. if c.IS != nil {
  322. return f.formattedValue(c.S, c.IS.String()), nil
  323. }
  324. return f.formattedValue(c.S, c.V), nil
  325. default:
  326. isNum, precision := isNumeric(c.V)
  327. if isNum && precision > 15 {
  328. val, _ := roundPrecision(c.V)
  329. if val != c.V {
  330. return f.formattedValue(c.S, val), nil
  331. }
  332. }
  333. return f.formattedValue(c.S, c.V), nil
  334. }
  335. }
  336. // roundPrecision round precision for numeric.
  337. func roundPrecision(value string) (result string, err error) {
  338. var num float64
  339. if num, err = strconv.ParseFloat(value, 64); err != nil {
  340. return
  341. }
  342. result = fmt.Sprintf("%g", math.Round(num*numericPrecision)/numericPrecision)
  343. return
  344. }
  345. // SetRowVisible provides a function to set visible of a single row by given
  346. // worksheet name and Excel row number. For example, hide row 2 in Sheet1:
  347. //
  348. // err := f.SetRowVisible("Sheet1", 2, false)
  349. //
  350. func (f *File) SetRowVisible(sheet string, row int, visible bool) error {
  351. if row < 1 {
  352. return newInvalidRowNumberError(row)
  353. }
  354. ws, err := f.workSheetReader(sheet)
  355. if err != nil {
  356. return err
  357. }
  358. prepareSheetXML(ws, 0, row)
  359. ws.SheetData.Row[row-1].Hidden = !visible
  360. return nil
  361. }
  362. // GetRowVisible provides a function to get visible of a single row by given
  363. // worksheet name and Excel row number. For example, get visible state of row
  364. // 2 in Sheet1:
  365. //
  366. // visible, err := f.GetRowVisible("Sheet1", 2)
  367. //
  368. func (f *File) GetRowVisible(sheet string, row int) (bool, error) {
  369. if row < 1 {
  370. return false, newInvalidRowNumberError(row)
  371. }
  372. ws, err := f.workSheetReader(sheet)
  373. if err != nil {
  374. return false, err
  375. }
  376. if row > len(ws.SheetData.Row) {
  377. return false, nil
  378. }
  379. return !ws.SheetData.Row[row-1].Hidden, nil
  380. }
  381. // SetRowOutlineLevel provides a function to set outline level number of a
  382. // single row by given worksheet name and Excel row number. The value of
  383. // parameter 'level' is 1-7. For example, outline row 2 in Sheet1 to level 1:
  384. //
  385. // err := f.SetRowOutlineLevel("Sheet1", 2, 1)
  386. //
  387. func (f *File) SetRowOutlineLevel(sheet string, row int, level uint8) error {
  388. if row < 1 {
  389. return newInvalidRowNumberError(row)
  390. }
  391. if level > 7 || level < 1 {
  392. return errors.New("invalid outline level")
  393. }
  394. ws, err := f.workSheetReader(sheet)
  395. if err != nil {
  396. return err
  397. }
  398. prepareSheetXML(ws, 0, row)
  399. ws.SheetData.Row[row-1].OutlineLevel = level
  400. return nil
  401. }
  402. // GetRowOutlineLevel provides a function to get outline level number of a
  403. // single row by given worksheet name and Excel row number. For example, get
  404. // outline number of row 2 in Sheet1:
  405. //
  406. // level, err := f.GetRowOutlineLevel("Sheet1", 2)
  407. //
  408. func (f *File) GetRowOutlineLevel(sheet string, row int) (uint8, error) {
  409. if row < 1 {
  410. return 0, newInvalidRowNumberError(row)
  411. }
  412. ws, err := f.workSheetReader(sheet)
  413. if err != nil {
  414. return 0, err
  415. }
  416. if row > len(ws.SheetData.Row) {
  417. return 0, nil
  418. }
  419. return ws.SheetData.Row[row-1].OutlineLevel, nil
  420. }
  421. // RemoveRow provides a function to remove single row by given worksheet name
  422. // and Excel row number. For example, remove row 3 in Sheet1:
  423. //
  424. // err := f.RemoveRow("Sheet1", 3)
  425. //
  426. // Use this method with caution, which will affect changes in references such
  427. // as formulas, charts, and so on. If there is any referenced value of the
  428. // worksheet, it will cause a file error when you open it. The excelize only
  429. // partially updates these references currently.
  430. func (f *File) RemoveRow(sheet string, row int) error {
  431. if row < 1 {
  432. return newInvalidRowNumberError(row)
  433. }
  434. ws, err := f.workSheetReader(sheet)
  435. if err != nil {
  436. return err
  437. }
  438. if row > len(ws.SheetData.Row) {
  439. return f.adjustHelper(sheet, rows, row, -1)
  440. }
  441. keep := 0
  442. for rowIdx := 0; rowIdx < len(ws.SheetData.Row); rowIdx++ {
  443. v := &ws.SheetData.Row[rowIdx]
  444. if v.R != row {
  445. ws.SheetData.Row[keep] = *v
  446. keep++
  447. }
  448. }
  449. ws.SheetData.Row = ws.SheetData.Row[:keep]
  450. return f.adjustHelper(sheet, rows, row, -1)
  451. }
  452. // InsertRow provides a function to insert a new row after given Excel row
  453. // number starting from 1. For example, create a new row before row 3 in
  454. // Sheet1:
  455. //
  456. // err := f.InsertRow("Sheet1", 3)
  457. //
  458. // Use this method with caution, which will affect changes in references such
  459. // as formulas, charts, and so on. If there is any referenced value of the
  460. // worksheet, it will cause a file error when you open it. The excelize only
  461. // partially updates these references currently.
  462. func (f *File) InsertRow(sheet string, row int) error {
  463. if row < 1 {
  464. return newInvalidRowNumberError(row)
  465. }
  466. return f.adjustHelper(sheet, rows, row, 1)
  467. }
  468. // DuplicateRow inserts a copy of specified row (by its Excel row number) below
  469. //
  470. // err := f.DuplicateRow("Sheet1", 2)
  471. //
  472. // Use this method with caution, which will affect changes in references such
  473. // as formulas, charts, and so on. If there is any referenced value of the
  474. // worksheet, it will cause a file error when you open it. The excelize only
  475. // partially updates these references currently.
  476. func (f *File) DuplicateRow(sheet string, row int) error {
  477. return f.DuplicateRowTo(sheet, row, row+1)
  478. }
  479. // DuplicateRowTo inserts a copy of specified row by it Excel number
  480. // to specified row position moving down exists rows after target position
  481. //
  482. // err := f.DuplicateRowTo("Sheet1", 2, 7)
  483. //
  484. // Use this method with caution, which will affect changes in references such
  485. // as formulas, charts, and so on. If there is any referenced value of the
  486. // worksheet, it will cause a file error when you open it. The excelize only
  487. // partially updates these references currently.
  488. func (f *File) DuplicateRowTo(sheet string, row, row2 int) error {
  489. if row < 1 {
  490. return newInvalidRowNumberError(row)
  491. }
  492. ws, err := f.workSheetReader(sheet)
  493. if err != nil {
  494. return err
  495. }
  496. if row > len(ws.SheetData.Row) || row2 < 1 || row == row2 {
  497. return nil
  498. }
  499. var ok bool
  500. var rowCopy xlsxRow
  501. for i, r := range ws.SheetData.Row {
  502. if r.R == row {
  503. rowCopy = deepcopy.Copy(ws.SheetData.Row[i]).(xlsxRow)
  504. ok = true
  505. break
  506. }
  507. }
  508. if !ok {
  509. return nil
  510. }
  511. if err := f.adjustHelper(sheet, rows, row2, 1); err != nil {
  512. return err
  513. }
  514. idx2 := -1
  515. for i, r := range ws.SheetData.Row {
  516. if r.R == row2 {
  517. idx2 = i
  518. break
  519. }
  520. }
  521. if idx2 == -1 && len(ws.SheetData.Row) >= row2 {
  522. return nil
  523. }
  524. rowCopy.C = append(make([]xlsxC, 0, len(rowCopy.C)), rowCopy.C...)
  525. f.ajustSingleRowDimensions(&rowCopy, row2)
  526. if idx2 != -1 {
  527. ws.SheetData.Row[idx2] = rowCopy
  528. } else {
  529. ws.SheetData.Row = append(ws.SheetData.Row, rowCopy)
  530. }
  531. return f.duplicateMergeCells(sheet, ws, row, row2)
  532. }
  533. // duplicateMergeCells merge cells in the destination row if there are single
  534. // row merged cells in the copied row.
  535. func (f *File) duplicateMergeCells(sheet string, ws *xlsxWorksheet, row, row2 int) error {
  536. if ws.MergeCells == nil {
  537. return nil
  538. }
  539. if row > row2 {
  540. row++
  541. }
  542. for _, rng := range ws.MergeCells.Cells {
  543. coordinates, err := f.areaRefToCoordinates(rng.Ref)
  544. if err != nil {
  545. return err
  546. }
  547. if coordinates[1] < row2 && row2 < coordinates[3] {
  548. return nil
  549. }
  550. }
  551. for i := 0; i < len(ws.MergeCells.Cells); i++ {
  552. areaData := ws.MergeCells.Cells[i]
  553. coordinates, _ := f.areaRefToCoordinates(areaData.Ref)
  554. x1, y1, x2, y2 := coordinates[0], coordinates[1], coordinates[2], coordinates[3]
  555. if y1 == y2 && y1 == row {
  556. from, _ := CoordinatesToCellName(x1, row2)
  557. to, _ := CoordinatesToCellName(x2, row2)
  558. if err := f.MergeCell(sheet, from, to); err != nil {
  559. return err
  560. }
  561. }
  562. }
  563. return nil
  564. }
  565. // checkRow provides a function to check and fill each column element for all
  566. // rows and make that is continuous in a worksheet of XML. For example:
  567. //
  568. // <row r="15" spans="1:22" x14ac:dyDescent="0.2">
  569. // <c r="A15" s="2" />
  570. // <c r="B15" s="2" />
  571. // <c r="F15" s="1" />
  572. // <c r="G15" s="1" />
  573. // </row>
  574. //
  575. // in this case, we should to change it to
  576. //
  577. // <row r="15" spans="1:22" x14ac:dyDescent="0.2">
  578. // <c r="A15" s="2" />
  579. // <c r="B15" s="2" />
  580. // <c r="C15" s="2" />
  581. // <c r="D15" s="2" />
  582. // <c r="E15" s="2" />
  583. // <c r="F15" s="1" />
  584. // <c r="G15" s="1" />
  585. // </row>
  586. //
  587. // Noteice: this method could be very slow for large spreadsheets (more than
  588. // 3000 rows one sheet).
  589. func checkRow(ws *xlsxWorksheet) error {
  590. for rowIdx := range ws.SheetData.Row {
  591. rowData := &ws.SheetData.Row[rowIdx]
  592. colCount := len(rowData.C)
  593. if colCount == 0 {
  594. continue
  595. }
  596. // check and fill the cell without r attribute in a row element
  597. rCount := 0
  598. for idx, cell := range rowData.C {
  599. rCount++
  600. if cell.R != "" {
  601. lastR, _, err := CellNameToCoordinates(cell.R)
  602. if err != nil {
  603. return err
  604. }
  605. if lastR > rCount {
  606. rCount = lastR
  607. }
  608. continue
  609. }
  610. rowData.C[idx].R, _ = CoordinatesToCellName(rCount, rowIdx+1)
  611. }
  612. lastCol, _, err := CellNameToCoordinates(rowData.C[colCount-1].R)
  613. if err != nil {
  614. return err
  615. }
  616. if colCount < lastCol {
  617. oldList := rowData.C
  618. newlist := make([]xlsxC, 0, lastCol)
  619. rowData.C = ws.SheetData.Row[rowIdx].C[:0]
  620. for colIdx := 0; colIdx < lastCol; colIdx++ {
  621. cellName, err := CoordinatesToCellName(colIdx+1, rowIdx+1)
  622. if err != nil {
  623. return err
  624. }
  625. newlist = append(newlist, xlsxC{R: cellName})
  626. }
  627. rowData.C = newlist
  628. for colIdx := range oldList {
  629. colData := &oldList[colIdx]
  630. colNum, _, err := CellNameToCoordinates(colData.R)
  631. if err != nil {
  632. return err
  633. }
  634. ws.SheetData.Row[rowIdx].C[colNum-1] = *colData
  635. }
  636. }
  637. }
  638. return nil
  639. }
  640. // convertRowHeightToPixels provides a function to convert the height of a
  641. // cell from user's units to pixels. If the height hasn't been set by the user
  642. // we use the default value. If the row is hidden it has a value of zero.
  643. func convertRowHeightToPixels(height float64) float64 {
  644. var pixels float64
  645. if height == 0 {
  646. return pixels
  647. }
  648. pixels = math.Ceil(4.0 / 3.0 * height)
  649. return pixels
  650. }