Skip to content

Commit 9804ca0

Browse files
author
Sébastien Geiser
committed
Excel file as text source
1 parent 79cdfc8 commit 9804ca0

12 files changed

+621
-41
lines changed

RegexDialog/FodyWeavers.xsd

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@
1717
<xs:documentation>A list of assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks.</xs:documentation>
1818
</xs:annotation>
1919
</xs:element>
20+
<xs:element minOccurs="0" maxOccurs="1" name="ExcludeRuntimeAssemblies" type="xs:string">
21+
<xs:annotation>
22+
<xs:documentation>A list of runtime assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks</xs:documentation>
23+
</xs:annotation>
24+
</xs:element>
25+
<xs:element minOccurs="0" maxOccurs="1" name="IncludeRuntimeAssemblies" type="xs:string">
26+
<xs:annotation>
27+
<xs:documentation>A list of runtime assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks.</xs:documentation>
28+
</xs:annotation>
29+
</xs:element>
2030
<xs:element minOccurs="0" maxOccurs="1" name="Unmanaged32Assemblies" type="xs:string">
2131
<xs:annotation>
2232
<xs:documentation>A list of unmanaged 32 bit assembly names to include, delimited with line breaks.</xs:documentation>
@@ -43,6 +53,16 @@
4353
<xs:documentation>Controls if .pdbs for reference assemblies are also embedded.</xs:documentation>
4454
</xs:annotation>
4555
</xs:attribute>
56+
<xs:attribute name="IncludeRuntimeReferences" type="xs:boolean">
57+
<xs:annotation>
58+
<xs:documentation>Controls if runtime assemblies are also embedded.</xs:documentation>
59+
</xs:annotation>
60+
</xs:attribute>
61+
<xs:attribute name="UseRuntimeReferencePaths" type="xs:boolean">
62+
<xs:annotation>
63+
<xs:documentation>Controls whether the runtime assemblies are embedded with their full path or only with their assembly name.</xs:documentation>
64+
</xs:annotation>
65+
</xs:attribute>
4666
<xs:attribute name="DisableCompression" type="xs:boolean">
4767
<xs:annotation>
4868
<xs:documentation>Embedded assemblies are compressed by default, and uncompressed when they are loaded. You can turn compression off with this option.</xs:documentation>
@@ -73,6 +93,16 @@
7393
<xs:documentation>A list of assembly names to include from the default action of "embed all Copy Local references", delimited with |.</xs:documentation>
7494
</xs:annotation>
7595
</xs:attribute>
96+
<xs:attribute name="ExcludeRuntimeAssemblies" type="xs:string">
97+
<xs:annotation>
98+
<xs:documentation>A list of runtime assembly names to exclude from the default action of "embed all Copy Local references", delimited with |</xs:documentation>
99+
</xs:annotation>
100+
</xs:attribute>
101+
<xs:attribute name="IncludeRuntimeAssemblies" type="xs:string">
102+
<xs:annotation>
103+
<xs:documentation>A list of runtime assembly names to include from the default action of "embed all Copy Local references", delimited with |.</xs:documentation>
104+
</xs:annotation>
105+
</xs:attribute>
76106
<xs:attribute name="Unmanaged32Assemblies" type="xs:string">
77107
<xs:annotation>
78108
<xs:documentation>A list of unmanaged 32 bit assembly names to include, delimited with |.</xs:documentation>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using ClosedXML.Excel;
2+
using Newtonsoft.Json;
3+
using System;
4+
5+
namespace RegexDialog
6+
{
7+
public class ExcelCellTextSource : NotifyPropertyChangedBaseClass
8+
{
9+
public bool IsSelected { get; set; }
10+
11+
public string Name { get; set; }
12+
13+
[JsonIgnore]
14+
public Func<IXLCell, string> GetValue { get; set; }
15+
}
16+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using ClosedXML.Excel;
2+
using DocumentFormat.OpenXml.Bibliography;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text.RegularExpressions;
6+
7+
namespace RegexDialog
8+
{
9+
public class ExcelSheetSelection : NotifyPropertyChangedBaseClass
10+
{
11+
private readonly static Regex simpleCellRegex = new Regex("^[A-Z]+[1-9][0-9]*$", RegexOptions.Compiled);
12+
private readonly static Regex simpleColumnRegex = new Regex("^[A-Z]+$", RegexOptions.Compiled);
13+
private readonly static Regex simpleRowRegex = new Regex("^[1-9][0-9]*$", RegexOptions.Compiled);
14+
private readonly static Regex rangeRegex = new Regex("^[A-Z]+([1-9][0-9]*)?:[A-Z]+([1-9][0-9]*)?|[1-9][0-9]*:[1-9][0-9]*$", RegexOptions.Compiled);
15+
private readonly static Regex interpretedStuffRegex = new Regex(@"\[(?<var>FR|LR|FC|LC)\]", RegexOptions.Compiled | RegexOptions.IgnoreCase);
16+
17+
public bool IsSelected { get; set; } = true;
18+
public string Name { get; set; } = string.Empty;
19+
public string Filter { get; set; } = string.Empty;
20+
21+
public IEnumerable<IXLCell> GetCells(IXLWorksheet sheet)
22+
{
23+
if (string.IsNullOrWhiteSpace(Filter))
24+
{
25+
foreach (var item in sheet.CellsUsed())
26+
{
27+
yield return item;
28+
}
29+
}
30+
31+
foreach (string filter in InterpretStuffInFilter(Filter, sheet).Split(';').Select(filter => filter.Trim().ToUpper()))
32+
{
33+
if (simpleCellRegex.IsMatch(filter))
34+
yield return sheet.Cell(filter);
35+
if (simpleColumnRegex.IsMatch(filter))
36+
{
37+
foreach (var cell in sheet.Column(filter).CellsUsed())
38+
{
39+
yield return cell;
40+
}
41+
}
42+
else if (simpleRowRegex.IsMatch(filter))
43+
{
44+
foreach (var cell in sheet.Row(int.Parse(filter)).CellsUsed())
45+
{
46+
yield return cell;
47+
}
48+
}
49+
else if (rangeRegex.IsMatch(filter))
50+
{
51+
foreach (var cell in sheet.Range(filter).CellsUsed())
52+
{
53+
yield return cell;
54+
}
55+
}
56+
}
57+
}
58+
59+
private string InterpretStuffInFilter(string filter, IXLWorksheet sheet)
60+
{
61+
return interpretedStuffRegex.Replace(filter, match =>
62+
{
63+
switch(match.Groups["var"].Value)
64+
{
65+
case "FR":
66+
return sheet.FirstRowUsed().RangeAddress.FirstAddress.RowNumber.ToString();
67+
case "LR":
68+
return sheet.LastRowUsed().RangeAddress.FirstAddress.RowNumber.ToString();
69+
case "FC":
70+
return sheet.FirstColumnUsed().RangeAddress.FirstAddress.ColumnLetter;
71+
case "LC":
72+
return sheet.LastColumnUsed().RangeAddress.FirstAddress.ColumnLetter;
73+
default:
74+
return "";
75+
}
76+
});
77+
}
78+
}
79+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Text.RegularExpressions;
2+
3+
namespace RegexDialog
4+
{
5+
internal class RegexExcelSheetResult :RegexResult
6+
{
7+
public RegexExcelSheetResult(Regex regex, Capture regexElement, int regexElementNb, string fileName, string sheetName) : base(regex, regexElement, regexElementNb, fileName, 0)
8+
{
9+
SheetName = sheetName;
10+
}
11+
public override string Name => $"Sheet [{SheetName}]: {Children.Count} matches found";
12+
13+
public string SheetName { get; set; }
14+
15+
public override bool IsExpanded { get => true; }
16+
17+
public override void RefreshExpands()
18+
{
19+
Children.ForEach(child => child.RefreshExpands());
20+
}
21+
22+
public override string ElementType => "Excel";
23+
}
24+
}

RegexDialog/Model/RegexGroupResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public override string Name
4747
return result;
4848
}
4949
}
50-
50+
5151
public string GroupName
5252
{
5353
get

RegexDialog/Model/RegexResult.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public virtual string ElementType
3333

3434
public string FileName { get; set; } = string.Empty;
3535

36+
public string InfoSup { get; set; } = string.Empty;
37+
3638
public Capture RegexElement { get; }
3739

3840
public int RegexElementNb { get; }
@@ -53,7 +55,7 @@ public virtual string Name
5355
{
5456
if (RegexElement != null)
5557
{
56-
result = ElementType + " " + RegexElementNb.ToString() + " [" + RegexElement.Index.ToString() + "," + RegexElement.Length.ToString() + "]: ";
58+
result = $"{ElementType} {RegexElementNb.ToString()} [{RegexElement.Index.ToString()},{RegexElement.Length.ToString()}]{(string.IsNullOrEmpty(InfoSup) ? "" : $" - {InfoSup} ")}: ";
5759
}
5860
}
5961
catch

0 commit comments

Comments
 (0)