Skip to content

Commit ae9c084

Browse files
Add Hyperlink property to ExcelCells
1 parent 65296ca commit ae9c084

File tree

4 files changed

+123
-4
lines changed

4 files changed

+123
-4
lines changed

dotnet/src/dotnetframework/GxOffice/ExcelCellGXWrapper.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ public ExcelCellGXWrapper()
2626

2727
public string ValueType => _value.ValueType;
2828

29+
2930
public string Text { get => _value.Text; set => _value.Text=value; }
3031
public decimal NumericValue { get => _value.NumericValue; set => _value.NumericValue=value; }
3132
public DateTime DateValue { get => _value.DateValue; set => _value.DateValue=value; }
33+
public string HyperlinkValue { get => _value.HyperlinkValue; set => _value.HyperlinkValue=value; }
3234

3335
public bool Empty()
3436
{

dotnet/src/dotnetframework/GxOffice/IExcelCellRange.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public interface IExcelCellRange
2828

2929
decimal NumericValue { get; set; }
3030

31+
string HyperlinkValue { get; set; }
32+
3133
DateTime DateValue { get; set; }
3234

3335
bool Empty();

dotnet/src/dotnetframework/GxOffice/poi/hssf/ExcelCells.cs

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using NPOI.HSSF.UserModel;
55
using NPOI.SS.UserModel;
66
using NPOI.SS.Util;
7-
using NPOI.XSSF.UserModel;
7+
88

99
namespace GeneXus.MSOffice.Excel.Poi.Hssf
1010
{
@@ -176,6 +176,37 @@ public bool SetDate(DateTime value)
176176
}
177177
return false;
178178
}
179+
public bool SetHyperlink(string value)
180+
{
181+
CheckReadonlyDocument();
182+
183+
try
184+
{
185+
for (int i = 1; i <= cellCount; i++)
186+
{
187+
pCells[i].Hyperlink.Address = value;
188+
}
189+
return true;
190+
}
191+
catch (Exception)
192+
{
193+
throw new ExcelException(7, "Invalid cell value");
194+
}
195+
}
196+
public string GetHyperlink()
197+
{
198+
string returnValue = string.Empty;
199+
try
200+
{
201+
if (pCells[1].Hyperlink!=null)
202+
returnValue = pCells[1].Hyperlink.Address;
203+
}
204+
catch (Exception)
205+
{
206+
throw new ExcelException(7, "Invalid cell value");
207+
}
208+
return returnValue;
209+
}
179210

180211
public DateTime GetDate()
181212
{
@@ -861,7 +892,34 @@ public decimal NumericValue
861892
}
862893
}
863894
}
864-
895+
public string HyperlinkValue
896+
{
897+
get
898+
{
899+
try
900+
{
901+
return GetHyperlink();
902+
}
903+
catch (ExcelException e)
904+
{
905+
_errorHandler.SetErrCod((short)e.ErrorCode);
906+
_errorHandler.SetErrDes(e.ErrorDescription);
907+
}
908+
return string.Empty;
909+
}
910+
set
911+
{
912+
try
913+
{
914+
SetHyperlink(value);
915+
}
916+
catch (ExcelException e)
917+
{
918+
_errorHandler.SetErrCod((short)e.ErrorCode);
919+
_errorHandler.SetErrDes(e.ErrorDescription);
920+
}
921+
}
922+
}
865923
public DateTime DateValue
866924
{
867925
get

dotnet/src/dotnetframework/GxOffice/poi/xssf/ExcelCells.cs

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ public decimal GetNumber()
134134
throw new ExcelException(7, "Invalid cell value");
135135
}
136136
}
137-
138137
public bool SetDate(DateTime value)
139138
{
140139
CheckReadonlyDocument();
@@ -178,6 +177,37 @@ public bool SetDate(DateTime value)
178177
}
179178
return false;
180179
}
180+
public bool SetHyperlink(string value)
181+
{
182+
CheckReadonlyDocument();
183+
184+
try
185+
{
186+
for (int i = 1; i <= cellCount; i++)
187+
{
188+
pCells[i].Hyperlink.Address = value;
189+
}
190+
return true;
191+
}
192+
catch (Exception)
193+
{
194+
throw new ExcelException(7, "Invalid cell value");
195+
}
196+
}
197+
public string GetHyperlink()
198+
{
199+
string returnValue = string.Empty;
200+
try
201+
{
202+
if (pCells[1].Hyperlink!=null)
203+
returnValue = pCells[1].Hyperlink.Address;
204+
}
205+
catch (Exception)
206+
{
207+
throw new ExcelException(7, "Invalid cell value");
208+
}
209+
return returnValue;
210+
}
181211

182212
public DateTime GetDate()
183213
{
@@ -897,7 +927,34 @@ public decimal NumericValue
897927
}
898928
}
899929
}
900-
930+
public string HyperlinkValue
931+
{
932+
get
933+
{
934+
try
935+
{
936+
return GetHyperlink();
937+
}
938+
catch (ExcelException e)
939+
{
940+
_errorHandler.SetErrCod((short)e.ErrorCode);
941+
_errorHandler.SetErrDes(e.ErrorDescription);
942+
}
943+
return string.Empty;
944+
}
945+
set
946+
{
947+
try
948+
{
949+
SetHyperlink(value);
950+
}
951+
catch (ExcelException e)
952+
{
953+
_errorHandler.SetErrCod((short)e.ErrorCode);
954+
_errorHandler.SetErrDes(e.ErrorDescription);
955+
}
956+
}
957+
}
901958
public DateTime DateValue
902959
{
903960
get

0 commit comments

Comments
 (0)