From ba0411b97eefd49c8e9b3c49297cbcc956991b85 Mon Sep 17 00:00:00 2001 From: Eeshaan Sawant Date: Mon, 23 Dec 2024 17:56:12 +0530 Subject: [PATCH] UPDATE index.md, changelog FIX grmticl errors --- CHANGELOG.md | 2 +- .../Macros/Samples/Import hyperlinks/index.md | 69 ++++++++++++++----- .../Plugin and Macros/Macros/Samples/index.md | 4 +- 3 files changed, 55 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 93df14751..e8fb7bc61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Change Log - docs api: the editorConfig.customization.mobileForceView parameter is deprecated, please use the editorConfig.customization.mobile parameter instead +- macros: added import hyperlinks in spreadsheet macro sample ## 6.2.0 - docspace js sdk: storybook link @@ -24,7 +25,6 @@ - 404 page - legacy version link - macros: added add comments and change cell colors in spreadsheet macro sample -- macros: added import hyperlinks in spreadsheet macro sample ## 6.1.0 - docspace js sdk: react component diff --git a/site/pages/Docs/Plugin and Macros/Macros/Samples/Import hyperlinks/index.md b/site/pages/Docs/Plugin and Macros/Macros/Samples/Import hyperlinks/index.md index 9a1d13796..030e28a1b 100644 --- a/site/pages/Docs/Plugin and Macros/Macros/Samples/Import hyperlinks/index.md +++ b/site/pages/Docs/Plugin and Macros/Macros/Samples/Import hyperlinks/index.md @@ -1,43 +1,45 @@ --- -order: +order: --- ## Description -Import hyperlinks between different worksheets in the spreadsheet. +Imports hyperlinks between different worksheets in the spreadsheet. ```ts -var oWorksheetA = Api.GetSheet("Sheet1"); -var oWorksheetB = Api.GetSheet("Sheet2"); -var rowIndex = 0; -var titles = []; -var links = []; -while (rowIndex < 10) { +(function () { + var oWorksheetA = Api.GetSheet("Sheet1"); + var oWorksheetB = Api.GetSheet("Sheet2"); + var rowIndex = 0; + var titles = []; + var links = []; + while (rowIndex < 10) { var titleCell = oWorksheetA.GetRangeByNumber(rowIndex, 0); // Assuming title is in column A var linkCell = oWorksheetA.GetRangeByNumber(rowIndex, 1); // Assuming link is in column B var title = titleCell.GetValue(); var link = linkCell.GetValue(); titles.push(title); // Store titles in an array - links.push(link); // Store links in an array + links.push(link); // Store links in an array rowIndex++; // Increment the row index for the next iteration -} -var rangeB = Api.GetSelection(); -rangeB.ForEach(function (cell) { + } + var rangeB = Api.GetSelection(); + rangeB.ForEach(function (cell) { var cellValue = cell.GetValue(); // Check if the cell value matches any of the titles from the array var index = titles.indexOf(cellValue); if (index !== -1) { - var title = titles[index]; - var link = links[index]; - var address = cell.GetAddress(true, true, "xlA1", false); - // Set the hyperlink in oWorksheetB - oWorksheetB.SetHyperlink(address, link, "Your Description", title); + var title = titles[index]; + var link = links[index]; + var address = cell.GetAddress(true, true, "xlA1", false); + // Set the hyperlink in oWorksheetB + oWorksheetB.SetHyperlink(address, link, "Your Description", title); } -}) + }); +})(); ``` Methods used: GetSheet, GetRangeByNumber, GetValue, GetSelection, ForEach, GetAddress, SetHyperlink @@ -47,6 +49,37 @@ Methods used: GetSheet, GetRangeByNumber, GetValue, GetSelection, ForEach, GetAd ```vb +Sub AddHyperlinks() + Dim wsA As Worksheet, wsB As Worksheet + Dim titles() As String, links() As String + Dim rng As Range, cell As Range + Dim i As Integer + + ' Set worksheets + Set wsA = ThisWorkbook.Sheets("Sheet1") + Set wsB = ThisWorkbook.Sheets("Sheet2") + + ' Read first 10 titles and links from Sheet1 + ReDim titles(0 To 9) + ReDim links(0 To 9) + For i = 0 To 9 + titles(i) = wsA.Cells(i + 1, 1).Value ' Column A + links(i) = wsA.Cells(i + 1, 2).Value ' Column B + Next i + + ' Loop through the selection on Sheet1 + Set rng = Selection + For Each cell In rng + For i = LBound(titles) To UBound(titles) + If cell.Value = titles(i) Then + ' Add hyperlink to Sheet2 at same address as the selected cell + wsB.Hyperlinks.Add Anchor:=wsB.Cells(cell.Row, cell.Column), _ + Address:=links(i), _ + TextToDisplay:=titles(i) + End If + Next i + Next cell +End Sub ``` ## Result diff --git a/site/pages/Docs/Plugin and Macros/Macros/Samples/index.md b/site/pages/Docs/Plugin and Macros/Macros/Samples/index.md index fe3cd9155..fce6c7ef9 100644 --- a/site/pages/Docs/Plugin and Macros/Macros/Samples/index.md +++ b/site/pages/Docs/Plugin and Macros/Macros/Samples/index.md @@ -130,7 +130,9 @@ In this example we are adding comments and changing the background colors of sel [More](Add%20comments%20and%20change%20cell%20colors%20in%20spreadsheet/index.md) -## Import hyperlinks in spreadsheet +## Import hyperlinks + +[More](Import%20hyperlinks/index.md) In this example we are importing hyperlinks between different worksheets in the spreadsheet.