Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
hpstep opened this issue Jul 5, 2024 · 7 comments
Closed

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

hpstep opened this issue Jul 5, 2024 · 7 comments
Labels
enhancement New feature or request

Comments

@hpstep
Copy link

hpstep commented Jul 5, 2024

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

@xuri
Copy link
Member

xuri commented Jul 5, 2024

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.

@xuri xuri added the needs more info This issue can't reproduce, need more info label Jul 5, 2024
@hpstep
Copy link
Author

hpstep commented Jul 5, 2024

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

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

@xuri
Copy link
Member

xuri commented Jul 5, 2024

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
Copy link
Author

hpstep commented Jul 5, 2024

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 xuri added enhancement New feature or request and removed needs more info This issue can't reproduce, need more info labels Jul 5, 2024
@xuri
Copy link
Member

xuri commented Jul 5, 2024

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

@xuri xuri added the in progress Working in progress label Jul 6, 2024
@xuri xuri closed this as completed in 53b6515 Jul 7, 2024
@xuri
Copy link
Member

xuri commented Jul 7, 2024

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.

@xuri xuri removed the in progress Working in progress label Jul 7, 2024
@hpstep
Copy link
Author

hpstep commented Jul 8, 2024

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

@xuri xuri moved this to Features in Excelize v2.9.0 Jul 10, 2024
zhangyimingdatiancai pushed a commit to zhangyimingdatiancai/excelize that referenced this issue Aug 6, 2024
… hyperlink by None linkType

- Update unit tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
No open projects
Status: Features
Development

No branches or pull requests

2 participants