@@ -170,18 +170,21 @@ func (c *xlsxC) hasValue() bool {
170170}
171171
172172// removeFormula delete formula for the cell.
173- func (c * xlsxC ) removeFormula (ws * xlsxWorksheet ) {
174- if c .F != nil && c .F .T == STCellFormulaTypeShared && c .F .Ref != "" {
175- si := c .F .Si
176- for r , row := range ws .SheetData .Row {
177- for col , cell := range row .C {
178- if cell .F != nil && cell .F .Si != nil && * cell .F .Si == * si {
179- ws .SheetData .Row [r ].C [col ].F = nil
173+ func (f * File ) removeFormula (c * xlsxC , ws * xlsxWorksheet , sheet string ) {
174+ if c .F != nil && c .Vm == nil {
175+ f .deleteCalcChain (f .getSheetID (sheet ), c .R )
176+ if c .F .T == STCellFormulaTypeShared && c .F .Ref != "" {
177+ si := c .F .Si
178+ for r , row := range ws .SheetData .Row {
179+ for col , cell := range row .C {
180+ if cell .F != nil && cell .F .Si != nil && * cell .F .Si == * si {
181+ ws .SheetData .Row [r ].C [col ].F = nil
182+ }
180183 }
181184 }
182185 }
186+ c .F = nil
183187 }
184- c .F = nil
185188}
186189
187190// setCellIntFunc is a wrapper of SetCellInt.
@@ -281,8 +284,8 @@ func (f *File) SetCellInt(sheet, axis string, value int) error {
281284 defer ws .Unlock ()
282285 cellData .S = f .prepareCellStyle (ws , col , row , cellData .S )
283286 cellData .T , cellData .V = setCellInt (value )
284- cellData .removeFormula (ws )
285287 cellData .IS = nil
288+ f .removeFormula (cellData , ws , sheet )
286289 return err
287290}
288291
@@ -308,8 +311,8 @@ func (f *File) SetCellBool(sheet, axis string, value bool) error {
308311 defer ws .Unlock ()
309312 cellData .S = f .prepareCellStyle (ws , col , row , cellData .S )
310313 cellData .T , cellData .V = setCellBool (value )
311- cellData .removeFormula (ws )
312314 cellData .IS = nil
315+ f .removeFormula (cellData , ws , sheet )
313316 return err
314317}
315318
@@ -347,8 +350,8 @@ func (f *File) SetCellFloat(sheet, axis string, value float64, precision, bitSiz
347350 defer ws .Unlock ()
348351 cellData .S = f .prepareCellStyle (ws , col , row , cellData .S )
349352 cellData .T , cellData .V = setCellFloat (value , precision , bitSize )
350- cellData .removeFormula (ws )
351353 cellData .IS = nil
354+ f .removeFormula (cellData , ws , sheet )
352355 return err
353356}
354357
@@ -374,8 +377,8 @@ func (f *File) SetCellStr(sheet, axis, value string) error {
374377 defer ws .Unlock ()
375378 cellData .S = f .prepareCellStyle (ws , col , row , cellData .S )
376379 cellData .T , cellData .V , err = f .setCellString (value )
377- cellData .removeFormula (ws )
378380 cellData .IS = nil
381+ f .removeFormula (cellData , ws , sheet )
379382 return err
380383}
381384
@@ -474,8 +477,8 @@ func (f *File) SetCellDefault(sheet, axis, value string) error {
474477 defer ws .Unlock ()
475478 cellData .S = f .prepareCellStyle (ws , col , row , cellData .S )
476479 cellData .T , cellData .V = setCellDefault (value )
477- cellData .removeFormula (ws )
478480 cellData .IS = nil
481+ f .removeFormula (cellData , ws , sheet )
479482 return err
480483}
481484
@@ -510,13 +513,12 @@ type FormulaOpts struct {
510513}
511514
512515// SetCellFormula provides a function to set formula on the cell is taken
513- // according to the given worksheet name (case-sensitive) and cell formula
514- // settings. The result of the formula cell can be calculated when the
515- // worksheet is opened by the Office Excel application or can be using
516- // the "CalcCellValue" function also can get the calculated cell value. If
517- // the Excel application doesn't calculate the formula automatically when the
518- // workbook has been opened, please call "UpdateLinkedValue" after setting
519- // the cell formula functions.
516+ // according to the given worksheet name and cell formula settings. The result
517+ // of the formula cell can be calculated when the worksheet is opened by the
518+ // Office Excel application or can be using the "CalcCellValue" function also
519+ // can get the calculated cell value. If the Excel application doesn't
520+ // calculate the formula automatically when the workbook has been opened,
521+ // please call "UpdateLinkedValue" after setting the cell formula functions.
520522//
521523// Example 1, set normal formula "=SUM(A1,B1)" for the cell "A3" on "Sheet1":
522524//
@@ -662,11 +664,12 @@ func (ws *xlsxWorksheet) countSharedFormula() (count int) {
662664 return
663665}
664666
665- // GetCellHyperLink provides a function to get cell hyperlink by given
666- // worksheet name and axis. Boolean type value link will be true if the cell
667- // has a hyperlink and the target is the address of the hyperlink. Otherwise,
668- // the value of link will be false and the value of the target will be a blank
669- // string. For example get hyperlink of Sheet1!H6:
667+ // GetCellHyperLink gets a cell hyperlink based on the given worksheet name and
668+ // cell coordinates. If the cell has a hyperlink, it will return 'true' and
669+ // the link address, otherwise it will return 'false' and an empty link
670+ // address.
671+ //
672+ // For example, get a hyperlink to a 'H6' cell on a worksheet named 'Sheet1':
670673//
671674// link, target, err := f.GetCellHyperLink("Sheet1", "H6")
672675//
@@ -765,7 +768,7 @@ func (f *File) SetCellHyperLink(sheet, axis, link, linkType string, opts ...Hype
765768
766769 switch linkType {
767770 case "External" :
768- sheetPath := f .sheetMap [ trimSheetName (sheet )]
771+ sheetPath , _ := f .getSheetXMLPath (sheet )
769772 sheetRels := "xl/worksheets/_rels/" + strings .TrimPrefix (sheetPath , "xl/worksheets/" ) + ".rels"
770773 rID := f .setRels (linkData .RID , sheetRels , SourceRelationshipHyperLink , link , linkType )
771774 linkData = xlsxHyperlink {
0 commit comments