Skip to main content

Hyperlink

Struct Hyperlink 

Source
pub struct Hyperlink {
    pub range: Dimensions,
    pub target: Option<String>,
    pub location: Option<String>,
    pub displayed_text: Option<String>,
    pub tooltip: Option<String>,
}
Expand description

A hyperlink declared on an XLSX worksheet.

Hyperlinks are anchored to a cell or cell range and point to one of the link types supported by Excel:

  • A web-based URI such as http://, https://, ftp://, ftps://, mailto: or a custom protocol://domain link — stored in Hyperlink::target.
  • A local file link using the file:// URI (e.g. file:///C:\Temp\Book1.xlsx or file:///Book2.xlsx#'Sales Data'!A1:G5) — stored in Hyperlink::target.
  • An internal link to a cell or range in the same workbook (e.g. 'Sheet2'!B5) — stored in Hyperlink::location, with Hyperlink::target left as None.

A single hyperlink may combine an external target with an internal location, in which case the location acts as a sub-anchor within the target file.

Fields§

§range: Dimensions

Cell or range the hyperlink is anchored to.

§target: Option<String>

External link target.

This holds the subset of Excel link types that resolve to an external resource: web URIs (e.g. https://example.com), email addresses (e.g. mailto:foo@example.com) and local file links (e.g. file:///C:\Temp\Book1.xlsx).

It is None for purely internal hyperlinks, where only Hyperlink::location is set.

§location: Option<String>

In-file location the hyperlink points to, set only for a subset of link types.

For a purely internal link this is the cell, range or named range it targets (e.g. 'Sheet2'!B5). For an external file link it holds the sub-anchor — the part after #, e.g. the Sheet1!A1 in file:///Book2.xlsx#Sheet1!A1 — while Hyperlink::target holds the file itself. None when the hyperlink has no in-file location.

§displayed_text: Option<String>

Optional text displayed in the cell instead of the target.

For example a link to https://www.rust-lang.org/ might be displayed as Rust Programming Language. None when Excel shows the target itself.

§tooltip: Option<String>

Optional tooltip shown when hovering the hyperlink in Excel.

Implementations§

Source

pub fn contains(&self, row: u32, column: u32) -> bool

Returns true if this hyperlink’s anchor range contains the cell at the given zero-based (row, column).

This is a convenience for looking up the hyperlink applied to a specific cell from the vector returned by Xlsx::hyperlinks_by_sheet_name():

use calamine::{open_workbook, Error, Xlsx};

fn main() -> Result<(), Error> {
    let mut workbook: Xlsx<_> = open_workbook("tests/hyperlinks.xlsx")?;
    let hyperlinks = workbook.hyperlinks_by_sheet_name("Links")?;

    let link = hyperlinks.iter().find(|h| h.contains(0, 0));
    assert!(link.is_some());

    Ok(())
}

Trait Implementations§

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.