Skip to content

Commit b6cde30

Browse files
author
Sébastien Geiser
committed
Evaluate filter + hyperlinks as excel text source
1 parent 94a1f57 commit b6cde30

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed

RegexDialog/Model/ExcelSheetSelection.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
using ClosedXML.Excel;
22
using DocumentFormat.OpenXml.Bibliography;
3+
using Newtonsoft.Json;
4+
using System;
35
using System.Collections.Generic;
46
using System.Linq;
57
using System.Text.RegularExpressions;
8+
using System.Windows;
9+
using System.Windows.Input;
610

711
namespace RegexDialog
812
{
@@ -18,6 +22,22 @@ public class ExcelSheetSelection : NotifyPropertyChangedBaseClass
1822
public string Name { get; set; } = string.Empty;
1923
public string Filter { get; set; } = string.Empty;
2024

25+
[JsonIgnore]
26+
public ICommand EvaluateCommand => new RelayCommand(_ =>
27+
{
28+
using(IXLWorkbook workbook = new XLWorkbook(Config.Instance.TextSourceExcelPath))
29+
{
30+
try
31+
{
32+
MessageBox.Show(InterpretStuffInFilter(Filter, workbook.Worksheet(Name)));
33+
}
34+
catch(Exception exception)
35+
{
36+
MessageBox.Show(exception.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
37+
}
38+
}
39+
});
40+
2141
public IEnumerable<IXLCell> GetCells(IXLWorksheet sheet)
2242
{
2343
if (string.IsNullOrWhiteSpace(Filter))

RegexDialog/RegExToolDialog.xaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@
896896
Grid.IsSharedSizeScope="True">
897897
<ItemsControl.ItemTemplate>
898898
<DataTemplate DataType="local:ExcelSheetSelection">
899-
<AutoGrid Columns="Auto,*" ColumnsSharedSizeGroups="Sheet">
899+
<AutoGrid Columns="Auto,*,Auto" ColumnsSharedSizeGroups="Sheet">
900900
<CheckBox Content="{Binding Name}"
901901
IsChecked="{Binding IsSelected, UpdateSourceTrigger=PropertyChanged}" />
902902
<TextBox Text="{Binding Filter}"
@@ -919,6 +919,11 @@
919919
</StackPanel>
920920
</TextBox.ToolTip>
921921
</TextBox>
922+
<Button Content="="
923+
Padding="5,0"
924+
ToolTip="Evaluate expressions of the Filter and show the result filter"
925+
Command="{Binding EvaluateCommand}"/>
926+
922927
</AutoGrid>
923928
</DataTemplate>
924929
</ItemsControl.ItemTemplate>

RegexDialog/RegexDialog.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@
5757
<Reference Include="CodingSeb.Layouts, Version=1.0.4.0, Culture=neutral, processorArchitecture=MSIL">
5858
<HintPath>..\packages\CodingSeb.Layouts.1.0.4\lib\net47\CodingSeb.Layouts.dll</HintPath>
5959
</Reference>
60+
<Reference Include="CodingSeb.Mvvm, Version=1.2.4.0, Culture=neutral, processorArchitecture=MSIL">
61+
<HintPath>..\packages\CodingSeb.Mvvm.1.2.4\lib\net45\CodingSeb.Mvvm.dll</HintPath>
62+
</Reference>
6063
<Reference Include="Costura, Version=5.7.0.0, Culture=neutral, processorArchitecture=MSIL">
6164
<HintPath>..\packages\Costura.Fody.5.7.0\lib\netstandard1.0\Costura.dll</HintPath>
6265
</Reference>

RegexDialog/Utils/Config.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ private void Init()
103103
GetValue = cell => cell.HasComment ? cell.GetComment().Author : ""
104104
},
105105
new ExcelCellTextSource()
106+
{
107+
Name = "Hyperlink",
108+
GetValue = cell => cell.HasHyperlink ? (cell.GetHyperlink().IsExternal ? cell.GetHyperlink().ExternalAddress.AbsoluteUri : cell.GetHyperlink().InternalAddress) : ""
109+
},
110+
new ExcelCellTextSource()
106111
{
107112
Name = "Cell address",
108113
GetValue = cell => cell.Address.ToString()

RegexDialog/packages.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<package id="CodingSeb.Converters" version="1.0.5" targetFramework="net47" />
66
<package id="CodingSeb.ExpressionEvaluator" version="1.4.40" targetFramework="net47" />
77
<package id="CodingSeb.Layouts" version="1.0.4" targetFramework="net47" />
8+
<package id="CodingSeb.Mvvm" version="1.2.4" targetFramework="net47" />
89
<package id="Costura.Fody" version="5.7.0" targetFramework="net47" developmentDependency="true" />
910
<package id="CS-Script.bin" version="3.30.5.1" targetFramework="net46" />
1011
<package id="CS-Script.lib" version="3.30.5.1" targetFramework="net46" />

0 commit comments

Comments
 (0)