qax-os / excelize

Go language library for reading and writing Microsoft Excel™ (XLAM / XLSM / XLSX / XLTM / XLTX) spreadsheets
https://xuri.me/excelize
BSD 3-Clause "New" or "Revised" License
17.68k stars 1.69k forks source link

How to clear all the Hyperlinks in the Workbook? #1940

Closed hpstep closed 1 week ago

hpstep commented 1 week ago

I used SetCellHyperLink but it didn't work. Do you have any solutions? Thank you~

xuri commented 1 week ago

Thanks for your issue. Which version of the Excelize library are you using? Could you show us a complete, standalone example program or reproducible demo? Could you follow the issue template to provide more details? If you open an existing workbook, please provide the file attachment without confidential info.

hpstep commented 1 week ago
if err := f.SetCellHyperLink("Sheet1", "A3",
    "", "External", excelize.HyperlinkOpts{
        Display: nil,
        Tooltip: nil,
    }); err != nil {
    fmt.Println(err)
}

我使用以上代码去修改超级链接。但是用Excel打开之后,鼠标指过去还是显示有超级链接。 我想知道是否有函数清除这些超级链接,类似在Excel中右键取消超级链接一样。

xuri commented 1 week ago

Could you follow the issue template to provide more details? If you open an existing workbook, please provide the file attachment without confidential info.

hpstep commented 1 week ago

Description I used SetCellHyperLink but it didn't work. Do you have any solutions? Thank you~

Steps to reproduce the issue: 以下是简单测试的代码

f := excelize.NewFile()
defer func() {
    if err := f.Close(); err != nil {
        fmt.Println(err)
    }
}()
// 创建一个工作表
_, err := f.NewSheet("Sheet2")
if err != nil {
    fmt.Println(err)
    return
}
f.SetCellValue("Sheet1", "A2", "Hello world.")
f.SetCellValue("Sheet2", "A2", "Hello world.")

display, tooltip := "https://github.com/xuri/excelize", "Excelize on GitHub"
if err := f.SetCellHyperLink("Sheet1", "A2",
    display, "External", excelize.HyperlinkOpts{
        Display: &display,
        Tooltip: &tooltip,
    }); err != nil {
    fmt.Println(err)
}

if err := f.SetCellHyperLink("Sheet1", "A2",
    "", "External", excelize.HyperlinkOpts{
        Display: nil,
        Tooltip: nil,
    }); err != nil {
    fmt.Println(err)
}

if err := f.SaveAs("LinkBook.xlsx"); err != nil {
    fmt.Println(err)
}

Describe the results you received: 在Shee1中。A2的超级链接没有被清除,鼠标指过去之后还会出现跳转的提示和鼠标指针变化。右键还是会出现“取消超级链接的菜单项”

Describe the results you expected: 期望可以清除超级链接,例如结果跟(Sheet2的A2一样)

Output of go version: 1.22.4

Excelize version or commit ID: Excelize version 2.8.1

Environment details (OS, Microsoft Excel™ version, physical, etc.): LinkBook LinkBook.xlsx

xuri commented 1 week ago

Thanks for your feedback. This library doesn't support remove hyperlink for a cell, I'll consider adding support for this.

xuri commented 1 week ago

I added remove hyperlink support for the SetCellHyperLink function. Please upgrade to the master branch code by go get -u github.com/xuri/excelize/v2@master, now you can remove hyperlink for cell Sheet1!A2 like this:

if err := f.SetCellHyperLink("Sheet1", "A2", "", "None"); err != nil {
    fmt.Println(err)
}

This feature will be released in the next version.

hpstep commented 1 week ago

谢谢您,我可以使用了~~