rows.go 18 KB

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