-
-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add functionality that allows you to read and write the visibility of…
… excel sheets (Issue #531) (#563) * Read and write excel documents using DynamicExcelSheet and ExcelSheetAttribute * Fix in generating the default sheet name --------- Co-authored-by: Paweł Szybiak <pawel.szybiak@vsoft.pl>
- Loading branch information
Showing
12 changed files
with
453 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using MiniExcelLibs.OpenXml; | ||
using System; | ||
|
||
namespace MiniExcelLibs.Attributes | ||
{ | ||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] | ||
public class ExcelSheetAttribute : Attribute | ||
{ | ||
public string Name { get; set; } | ||
public SheetState State { get; set; } = SheetState.Visible; | ||
} | ||
|
||
public class DynamicExcelSheet : ExcelSheetAttribute | ||
{ | ||
public string Key { get; set; } | ||
public DynamicExcelSheet(string key) | ||
{ | ||
Key = key; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
namespace MiniExcelLibs.OpenXml | ||
{ | ||
public class SheetInfo | ||
{ | ||
public SheetInfo(uint id, uint index, string name, SheetState sheetState) | ||
{ | ||
Id = id; | ||
Index = index; | ||
Name = name; | ||
State = sheetState; | ||
} | ||
|
||
/// <summary> | ||
/// Internal sheet id - depends on the order in which the sheet is added | ||
/// </summary> | ||
public uint Id { get; } | ||
/// <summary> | ||
/// Next sheet index - numbered from 0 | ||
/// </summary> | ||
public uint Index { get; } | ||
/// <summary> | ||
/// Sheet name | ||
/// </summary> | ||
public string Name { get; } | ||
/// <summary> | ||
/// Sheet visibility state | ||
/// </summary> | ||
public SheetState State { get; } | ||
} | ||
|
||
public enum SheetState { Visible, Hidden, VeryHidden } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,38 @@ | ||
namespace MiniExcelLibs.OpenXml | ||
using System; | ||
|
||
namespace MiniExcelLibs.OpenXml | ||
{ | ||
internal sealed class SheetRecord | ||
{ | ||
public SheetRecord(string name, uint id, string rid) | ||
public SheetRecord(string name, string state, uint id, string rid) | ||
{ | ||
Name = name; | ||
State = state; | ||
Id = id; | ||
Rid = rid; | ||
} | ||
|
||
public string Name { get; } | ||
|
||
public string State { get; set; } | ||
|
||
public uint Id { get; } | ||
|
||
public string Rid { get; set; } | ||
|
||
public string Path { get; set; } | ||
|
||
public SheetInfo ToSheetInfo(uint index) | ||
{ | ||
if (string.IsNullOrEmpty(State)) | ||
{ | ||
return new SheetInfo(Id, index, Name, SheetState.Visible); | ||
} | ||
if (Enum.TryParse(State, true, out SheetState stateEnum)) | ||
{ | ||
return new SheetInfo(Id, index, Name, stateEnum); | ||
} | ||
throw new ArgumentException($"Unable to parse sheet state. Sheet name: {Name}"); | ||
} | ||
} | ||
} |
Oops, something went wrong.