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

Formula hyperlinks shouldn't have nodes in worksheet #2055

Merged
merged 3 commits into from
Apr 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion ClosedXML.Examples/Misc/Hyperlinks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,13 @@ public void Create(String filePath)

// Hyperlink via formula
ws.Cell( ++ro, 1 )
.SetFormulaA1("=HYPERLINK(\"mailto:test@test.com\", \"Send Email\")");
.SetFormulaA1("=HYPERLINK(\"mailto:test@test.com\", \"Send Email through formula\")");

ws.Cell(++ro, 1)
.SetFormulaA1("=HYPERLINK(\"[Hyperlinks.xlsx]Hyperlinks!B2:C4\", \"Link to range through formula\")");

ws.Cell(++ro, 1)
.SetFormulaA1("=HYPERLINK(\"[../Test.xlsx]Sheet1!B2:C4\", \"Link to another file through formula\")");

// List all hyperlinks in a worksheet:
var hyperlinksInWorksheet = ws.Hyperlinks;
Expand Down
17 changes: 10 additions & 7 deletions ClosedXML.Tests/Excel/CalcEngine/LookupTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,19 +188,22 @@ public void Hlookup()
public void Hyperlink()
{
using var wb = new XLWorkbook();
var ws = wb.AddWorksheet();
var sheet = wb.AddWorksheet();

var cell = ws.Cell("B3");
var cell = sheet.Cell("B3");
cell.FormulaA1 = "HYPERLINK(\"http://github.com/ClosedXML/ClosedXML\")";
Assert.AreEqual("http://github.com/ClosedXML/ClosedXML", cell.Value);
Assert.True(cell.HasHyperlink);
Assert.AreEqual("http://github.com/ClosedXML/ClosedXML", cell.GetHyperlink().ExternalAddress.ToString());
Assert.False(cell.HasHyperlink);

cell = ws.Cell("B4");
cell = sheet.Cell("B4");
cell.FormulaA1 = "HYPERLINK(\"mailto:jsmith@github.com\", \"jsmith@github.com\")";
Assert.AreEqual("jsmith@github.com", cell.Value);
Assert.True(cell.HasHyperlink);
Assert.AreEqual("mailto:jsmith@github.com", cell.GetHyperlink().ExternalAddress.ToString());
Assert.False(cell.HasHyperlink);

cell = sheet.Cell("B5");
cell.FormulaA1 = "HYPERLINK(\"[Test.xlsx]Sheet1!A5\", \"Cell A5\")";
Assert.AreEqual("Cell A5", cell.Value);
Assert.False(cell.HasHyperlink);
}

[Test]
Expand Down
Binary file modified ClosedXML.Tests/Resource/Examples/Misc/Hyperlinks.xlsx
Binary file not shown.
4 changes: 0 additions & 4 deletions ClosedXML/Excel/CalcEngine/Functions/Lookup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@ private static object Hlookup(List<Expression> p)

private static AnyValue Hyperlink(CalcContext ctx, string linkLocation, ScalarValue? friendlyName)
{
var link = new XLHyperlink(linkLocation);
var cell = ctx.Worksheet.Cell(ctx.FormulaAddress);
cell.SetHyperlink(link);

return friendlyName?.ToAnyValue() ?? linkLocation;
}

Expand Down
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<PropertyGroup>
<Version>0.101.0-rc</Version>
<Version>0.101.0</Version>
</PropertyGroup>

<!-- Set common properties regarding assembly information and nuget packages -->
Expand All @@ -21,7 +21,7 @@
<PackageProjectUrl>https://github.com/ClosedXML/ClosedXML</PackageProjectUrl>
<PackageIcon>nuget-logo.png</PackageIcon>
<PackageTags>Excel OpenXml xlsx</PackageTags>
<Description>See release notes https://github.com/ClosedXML/ClosedXML/releases/tag/0.101.0-rc ClosedXML is a .NET library for reading, manipulating and writing Excel 2007+ (.xlsx, .xlsm) files. It aims to provide an intuitive and user-friendly interface to dealing with the underlying OpenXML API.</Description>
<Description>See release notes https://github.com/ClosedXML/ClosedXML/releases/tag/$(productVersion) ClosedXML is a .NET library for reading, manipulating and writing Excel 2007+ (.xlsx, .xlsm) files. It aims to provide an intuitive and user-friendly interface to dealing with the underlying OpenXML API.</Description>
<PackageReleaseNotes>See https://github.com/ClosedXML/ClosedXML/releases/tag/$(productVersion)</PackageReleaseNotes>
<RepositoryUrl>https://github.com/ClosedXML/ClosedXML</RepositoryUrl>
<RepositoryType>git</RepositoryType>
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ ClosedXML allows you to create Excel files without the Excel application. The ty
:caption: Migrations

migrations/migrate-to-0.100
migrations/migrate-to-0.101

.. toctree::
:maxdepth: 2
Expand Down
9 changes: 8 additions & 1 deletion docs/migrations/migrate-to-0.101.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@ Enum underlaying type

Enums `XLAlignmentReadingOrderValues`, `XLAlignmentHorizontalValues` and
`XLAlignmentVerticalValues` now use `byte` as an underlaying type instead of
`int`. Smaller underlaying type saves memory due to alignment.
`int`. Smaller underlaying type saves memory due to alignment.

**************
Graphic engine
**************

Graphic engine has a new method: `IXLGraphicEngine.GetGlyphBox`. See XML doc
for more details.