Skip to content

Commit 1909035

Browse files
Add support for .xls extension in the Office Excel module (#1156)
* Add support for .xls extension in the Office Excel module * Add Hyperlink property to ExcelCells * Add test for HyperLink and fix issue in HyperLink setter logic * Fix set HyperlinkValue in poi/xssf/ExcelCells.cs * Upgrade NPOI from 2.5.6 to 2.7.3 to fix issues opening Excel files with PivotTables * Upgrade System.Security.Cryptography.Pkcs to resolve assembly conflict with Gxoffice project * Update GxOffice.csproj to unify version of Microsoft.Extensions.Configuration * Unify System.Security.Cryptography.Pkcs version.
1 parent 56bef53 commit 1909035

19 files changed

+3319
-56
lines changed

dotnet/src/dotnetcore/GxExcel/GxExcel.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
2020
<PackageReference Include="EPPlus" Version="4.5.3.2" />
2121
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
22-
<PackageReference Include="System.Security.Cryptography.Pkcs" Version="8.0.0" />
22+
<PackageReference Include="System.Security.Cryptography.Pkcs" Version="8.0.1" />
2323
</ItemGroup>
2424

2525
<ItemGroup>

dotnet/src/dotnetcore/GxOffice/GxOffice.csproj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
</PropertyGroup>
1010
<ItemGroup>
1111
<Compile Include="..\..\dotnetframework\GxOffice\Constants.cs" Link="Constants.cs" />
12+
<Compile Include="..\..\dotnetframework\GxOffice\ExcelCellGXWrapper.cs" Link="ExcelCellGXWrapper.cs" />
1213
<Compile Include="..\..\dotnetframework\GxOffice\ExcelFactory.cs" Link="ExcelFactory.cs" />
1314
<Compile Include="..\..\dotnetframework\GxOffice\ExcelSpreadsheetGXWrapper.cs" Link="ExcelSpreadsheetGXWrapper.cs" />
15+
<Compile Include="..\..\dotnetframework\GxOffice\ExcelWorksheetGXWrapper.cs" Link="ExcelWorksheetGXWrapper.cs" />
1416
<Compile Include="..\..\dotnetframework\GxOffice\exception\ExcelDocumentNotSupported.cs" Link="exception\ExcelDocumentNotSupported.cs" />
1517
<Compile Include="..\..\dotnetframework\GxOffice\exception\ExcelException.cs" Link="exception\ExcelException.cs" />
1618
<Compile Include="..\..\dotnetframework\GxOffice\exception\ExcelReadonlyException.cs" Link="exception\ExcelReadonlyException.cs" />
@@ -19,6 +21,10 @@
1921
<Compile Include="..\..\dotnetframework\GxOffice\IExcelSpreadsheet.cs" Link="IExcelSpreadsheet.cs" />
2022
<Compile Include="..\..\dotnetframework\GxOffice\IExcelWorksheet.cs" Link="IExcelWorksheet.cs" />
2123
<Compile Include="..\..\dotnetframework\GxOffice\IGXError.cs" Link="IGXError.cs" />
24+
<Compile Include="..\..\dotnetframework\GxOffice\poi\hssf\ExcelCells.cs" Link="poi\hssf\ExcelCells.cs" />
25+
<Compile Include="..\..\dotnetframework\GxOffice\poi\hssf\ExcelSpreadsheet.cs" Link="poi\hssf\ExcelSpreadsheet.cs" />
26+
<Compile Include="..\..\dotnetframework\GxOffice\poi\hssf\ExcelWorksheet.cs" Link="poi\hssf\ExcelWorksheet.cs" />
27+
<Compile Include="..\..\dotnetframework\GxOffice\poi\hssf\StylesCache.cs" Link="poi\hssf\StylesCache.cs" />
2228
<Compile Include="..\..\dotnetframework\GxOffice\poi\xssf\ExcelCells.cs" Link="poi\xssf\ExcelCells.cs" />
2329
<Compile Include="..\..\dotnetframework\GxOffice\poi\xssf\ExcelSpreadsheet.cs" Link="poi\xssf\ExcelSpreadsheet.cs" />
2430
<Compile Include="..\..\dotnetframework\GxOffice\poi\xssf\ExcelWorksheet.cs" Link="poi\xssf\ExcelWorksheet.cs" />
@@ -35,7 +41,7 @@
3541

3642

3743
<ItemGroup>
38-
<PackageReference Include="NPOI" Version="2.5.6" />
44+
<PackageReference Include="NPOI" Version="2.7.3" />
3945
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
4046
</ItemGroup>
4147

@@ -45,6 +51,7 @@
4551

4652
<ItemGroup>
4753
<Folder Include="exception\" />
54+
<Folder Include="poi\hssf\" />
4855
<Folder Include="poi\xssf\" />
4956
<Folder Include="style\" />
5057
</ItemGroup>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System;
2+
using GeneXus.MSOffice.Excel.Style;
3+
4+
namespace GeneXus.MSOffice.Excel
5+
{
6+
7+
public class ExcelCellGXWrapper : IExcelCellRange
8+
{
9+
IExcelCellRange _value;
10+
public ExcelCellGXWrapper(IExcelCellRange value) {
11+
_value = value;
12+
}
13+
public ExcelCellGXWrapper()
14+
{
15+
System.Diagnostics.Debugger.Launch();
16+
}
17+
18+
public int RowStart => _value.RowStart;
19+
20+
public int RowEnd => _value.RowEnd;
21+
22+
public int ColumnStart => _value.ColumnStart;
23+
24+
25+
public int ColumnEnd => _value.ColumnEnd;
26+
27+
public string ValueType => _value.ValueType;
28+
29+
30+
public string Text { get => _value.Text; set => _value.Text=value; }
31+
public decimal NumericValue { get => _value.NumericValue; set => _value.NumericValue=value; }
32+
public DateTime DateValue { get => _value.DateValue; set => _value.DateValue=value; }
33+
public string HyperlinkValue { get => _value.HyperlinkValue; set => _value.HyperlinkValue=value; }
34+
35+
public bool Empty()
36+
{
37+
return _value.Empty();
38+
}
39+
40+
public string GetCellAdress()
41+
{
42+
return _value.GetCellAdress();
43+
}
44+
45+
public ExcelStyle GetCellStyle()
46+
{
47+
return _value.GetCellStyle();
48+
}
49+
50+
public bool MergeCells()
51+
{
52+
return _value.MergeCells();
53+
}
54+
55+
public bool SetCellStyle(ExcelStyle style)
56+
{
57+
return _value.SetCellStyle(style);
58+
}
59+
}
60+
}

dotnet/src/dotnetframework/GxOffice/ExcelFactory.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.IO;
22
using GeneXus.Application;
3-
using GeneXus.MSOffice.Excel.Poi.Xssf;
43

54
namespace GeneXus.MSOffice.Excel
65
{
@@ -17,9 +16,13 @@ public static IExcelSpreadsheet Create(IGXError handler, string filePath, string
1716
template = Path.IsPathRooted(template) ? template : Path.Combine(GxContext.StaticPhysicalPath(), template);
1817
}
1918

20-
if (filePath.EndsWith(ExcelSpreadsheet.DefaultExtension) || string.IsNullOrEmpty(Path.GetExtension(filePath)))
19+
if (filePath.EndsWith(GeneXus.MSOffice.Excel.Poi.Xssf.ExcelSpreadsheet.DefaultExtension) || string.IsNullOrEmpty(Path.GetExtension(filePath)))
2120
{
22-
return new ExcelSpreadsheet(handler, filePath, template);
21+
return new GeneXus.MSOffice.Excel.Poi.Xssf.ExcelSpreadsheet(handler, filePath, template);
22+
}
23+
else if (filePath.EndsWith(GeneXus.MSOffice.Excel.Poi.Hssf.ExcelSpreadsheet.DefaultExtension))
24+
{
25+
return new GeneXus.MSOffice.Excel.Poi.Hssf.ExcelSpreadsheet(handler, filePath, template);
2326
}
2427
throw new ExcelDocumentNotSupported();
2528
}

dotnet/src/dotnetframework/GxOffice/ExcelSpreadsheetGXWrapper.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using GeneXus.MSOffice.Excel.Poi.Xssf;
43

54
namespace GeneXus.MSOffice.Excel
65
{
@@ -130,13 +129,13 @@ private bool SaveAsImpl(string newFileName, string password)
130129
return ok;
131130
}
132131

133-
public ExcelCells GetCell(int rowIdx, int colIdx)
132+
public ExcelCellGXWrapper GetCell(int rowIdx, int colIdx)
134133
{
135134
if (Initialize())
136135
{
137136
try
138137
{
139-
return (ExcelCells)_document.GetCell(_currentWorksheet, rowIdx, colIdx);
138+
return new ExcelCellGXWrapper((IExcelCellRange)_document.GetCell(_currentWorksheet, rowIdx, colIdx));
140139
}
141140
catch (ExcelException e)
142141
{
@@ -158,13 +157,13 @@ public void SetError(string errorMsg, ExcelException e)
158157
GXLogging.Error(logger, errorMsg);
159158
}
160159

161-
public ExcelCells GetCells(int rowIdx, int colIdx, int rowCount, int colCount)
160+
public ExcelCellGXWrapper GetCells(int rowIdx, int colIdx, int rowCount, int colCount)
162161
{
163162
if (Initialize())
164163
{
165164
try
166165
{
167-
return (ExcelCells)_document.GetCells(_currentWorksheet, rowIdx, colIdx, rowCount, colCount);
166+
return new ExcelCellGXWrapper((IExcelCellRange)_document.GetCells(_currentWorksheet, rowIdx, colIdx, rowCount, colCount));
168167
}
169168
catch (ExcelException e)
170169
{
@@ -193,7 +192,7 @@ public bool SetCurrentWorksheetByName(string sheetName)
193192
{
194193
if (Initialize())
195194
{
196-
ExcelWorksheet ws = _document.GetWorkSheet(sheetName);
195+
IExcelWorksheet ws = _document.GetWorkSheet(sheetName);
197196
if (ws != null)
198197
{
199198
_currentWorksheet = ws;
@@ -292,7 +291,7 @@ public bool DeleteSheet(string sheetName)
292291
{
293292
if (Initialize())
294293
{
295-
ExcelWorksheet ws = _document.GetWorkSheet(sheetName);
294+
IExcelWorksheet ws = _document.GetWorkSheet(sheetName);
296295
if (ws != null)
297296
return _document.DeleteSheet(sheetName);
298297
}
@@ -340,24 +339,24 @@ private void SetError(int error, string description)
340339

341340
public string ErrDescription => _errDescription;
342341

343-
public ExcelWorksheet CurrentWorksheet
342+
public ExcelWorksheetGXWrapper CurrentWorksheet
344343
{
345344
get
346345
{
347346
if (Initialize())
348347
{
349-
return (ExcelWorksheet)_currentWorksheet;
348+
return new ExcelWorksheetGXWrapper(_currentWorksheet);
350349
}
351350
return null;
352351
}
353352
}
354353

355-
public List<ExcelWorksheet> GetWorksheets()
354+
public List<IExcelWorksheet> GetWorksheets()
356355
{
357356
if (Initialize())
358357
return _document.GetWorksheets();
359358
else
360-
return new List<ExcelWorksheet>();
359+
return new List<IExcelWorksheet>();
361360
}
362361

363362
private bool SelectFirstDefaultSheet(string sheetName)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
namespace GeneXus.MSOffice.Excel
2+
{
3+
public class ExcelWorksheetGXWrapper : IExcelWorksheet
4+
{
5+
private IExcelWorksheet _value;
6+
7+
public ExcelWorksheetGXWrapper(IExcelWorksheet value)
8+
{
9+
_value = value;
10+
}
11+
12+
public ExcelWorksheetGXWrapper()
13+
{
14+
}
15+
16+
public string Name
17+
{
18+
get => _value.Name;
19+
}
20+
21+
public bool Hidden { get => _value.Hidden; set => _value.Hidden=value; }
22+
23+
public bool Rename(string newName)
24+
{
25+
return _value.Rename(newName);
26+
}
27+
28+
public bool Copy(string newName)
29+
{
30+
return _value.Copy(newName);
31+
}
32+
33+
public void SetProtected(string password)
34+
{
35+
_value.SetProtected(password);
36+
}
37+
}
38+
}

dotnet/src/dotnetframework/GxOffice/GxOffice.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99
<ItemGroup>
1010
<PackageReference Include="EPPlus" Version="4.5.3.2" />
11-
<PackageReference Include="NPOI" Version="2.6.0" />
11+
<PackageReference Include="NPOI" Version="2.7.3" />
1212
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
1313
</ItemGroup>
1414

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/IExcelSpreadsheet.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Collections.Generic;
2-
using GeneXus.MSOffice.Excel.Poi.Xssf;
32

43
namespace GeneXus.MSOffice.Excel
54
{
@@ -18,8 +17,8 @@ public interface IExcelSpreadsheet
1817
bool DeleteColumn(IExcelWorksheet worksheet, int colIdx);
1918

2019
// Worksheets
21-
List<ExcelWorksheet> GetWorksheets();
22-
ExcelWorksheet GetWorkSheet(string name);
20+
List<IExcelWorksheet> GetWorksheets();
21+
IExcelWorksheet GetWorkSheet(string name);
2322
bool InsertWorksheet(string newSheetName, int idx);
2423
bool Autofit { set; }
2524
void SetColumnWidth(IExcelWorksheet worksheet, int colIdx, int width);

dotnet/src/dotnetframework/GxOffice/IExcelWorksheet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public interface IExcelWorksheet
44
{
55
string Name { get; }
66

7-
bool Hidden { get; }
7+
bool Hidden { get; set; }
88

99
bool Rename(string newName);
1010
bool Copy(string newName);

0 commit comments

Comments
 (0)