Skip to content

Hyperlink for formatted cells#16

Merged
y-bonfire merged 4 commits intoy-bonfire:masterfrom
Shelvak:hyperlink_format
Aug 11, 2025
Merged

Hyperlink for formatted cells#16
y-bonfire merged 4 commits intoy-bonfire:masterfrom
Shelvak:hyperlink_format

Conversation

@Shelvak
Copy link

@Shelvak Shelvak commented Aug 11, 2025

With this patch we can get the "real hyperlink" doing rows[1,2].hyperlink . And let us add more cell properties in the future.

Fix the original issue gimite#423.

Thanks @y-bonfire for reviving this project.

@y-bonfire y-bonfire merged commit 84d0270 into y-bonfire:master Aug 11, 2025
@y-bonfire
Copy link
Owner

y-bonfire commented Aug 11, 2025

@Shelvak
Thanks for the PR.🤗

The cell class was added spontaneously as a hack, so I feel adding a large number of properties is a bit iffy. However, when it comes to text styling, such as hyperlinks, bold, text color, and background color, a simple array alone feels insufficient.

The 2D array is accessed like a string, but I feel like it should really be a cell object, but that would change things significantly, so it's difficult.
ex.

# write
ws[1,1] = cell.new(text: "xxx", hyperlink:"yyy", background_color: "zzz")

# read
ws[1,1].text
ws[1,1].hyperlink
ws[1,1].background_color

Anyway,
It would be difficult to test if I couldn't not only read but also write, so I added a set function.🤔

I made it so that it can be set like this.

# write
worksheet.set_hyperlink_rich(1,1,1,1, "google", "https://www.google.com/")
worksheet[2,1].set_hyperlink_rich("gemini", "https://gemini.google.com/")

# read
# =>  "https://www.google.com/"
worksheet[1,1].hyperlink 

@Shelvak Shelvak deleted the hyperlink_format branch August 11, 2025 12:30
@Shelvak
Copy link
Author

Shelvak commented Aug 11, 2025

Great job @y-bonfire 🤝

@y-bonfire
Copy link
Owner

@Shelvak

I found the format supported by the Google API.
https://developers.google.com/workspace/sheets/api/reference/rest/v4/spreadsheets/cells#HyperlinkDisplayType

There are a huge number of formatting options.
Wrapping, alignment, padding, styles, rotation, smart tips, etc.
I don't think it's realistic to fully implement and test all of them. Of course, if you're motivated, I'd be happy to do it.♥️

Even if we could do this, there might be some discussion about whether we need charts or pivot tables.
Maybe it would be okay to just do it if there's a request or someone wants to do it.🤔

@Shelvak
Copy link
Author

Shelvak commented Aug 11, 2025

@y-bonfire yeah, I saw that and that's why I didn't implement the "assign" part, because there's no much need more than read it and assign =HYPERLINK(url, alias).

I don't think we need more magic from a script/background tool. Let's keep it as you did 🤝
Thanks again 👌

@y-bonfire
Copy link
Owner

Indeed, this worked (although I felt it might not work because it's a formula).🤔

worksheet[1,1] = "=HYPERLINK(\"https://www.google.com/\", \"google\")"

@y-bonfire y-bonfire mentioned this pull request Aug 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants