Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions ExcelExtensions/Interfaces/Export/IExporter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Dominic Schira <domshyra@gmail.com>. All Rights Reserved.

using ExcelExtensions.Models;
using ExcelExtensions.Models.Columns;
using ExcelExtensions.Models.Export;
using OfficeOpenXml;
using System.Collections.Generic;
using static ExcelExtensions.Enums.Enums;
Expand All @@ -12,6 +13,8 @@ namespace ExcelExtensions.Interfaces.Export
/// </summary>
public interface IExporter
{
//TODO: fix for LazyColumn
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove


/// <summary>
/// Export a table to an <see cref="ExcelWorksheet"/>
/// </summary>
Expand Down Expand Up @@ -42,10 +45,11 @@ public interface IExporter
/// Format the column of an <see cref="ExcelWorksheet"/>
/// </summary>
/// <param name="sheet"></param>
/// <param name="column"></param>
/// <param name="columnNumber"></param>
/// <param name="formatter"></param>
/// <param name="decimalPrecision"></param>
void FormatColumn(ref ExcelWorksheet sheet, string column, FormatType formatter, int? decimalPrecision = null);
void FormatColumn(ref ExcelWorksheet sheet, int columnNumber, FormatType formatter, int? decimalPrecision = null);
void FormatColumn(ref ExcelWorksheet sheet, string columnLetter, FormatType formatter, int? decimalPrecision = null);
/// <summary>
/// Format the column range of an <see cref="ExcelWorksheet"/>
/// </summary>
Expand All @@ -55,6 +59,7 @@ public interface IExporter
/// <param name="format"></param>
/// <param name="decimalPrecision"></param>
void FormatColumnRange(ExcelWorksheet itemcodeSheet, string startColumn, string endColumn, FormatType format, int? decimalPrecision = null);
void FormatColumnRange(ExcelWorksheet itemcodeSheet, int startColumn, int endColumn, FormatType format, int? decimalPrecision = null);
/// <summary>
/// Style the table header row by the max column in columns of an <see cref="ExcelWorksheet"/>
/// </summary>
Expand Down
14 changes: 8 additions & 6 deletions ExcelExtensions/Interfaces/IExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Dominic Schira <domshyra@gmail.com>. All Rights Reserved.

using ExcelExtensions.Models;
using ExcelExtensions.Models.Columns;
using ExcelExtensions.Models.Columns.Import;
using System;
using System.Collections.Generic;

Expand Down Expand Up @@ -104,12 +106,12 @@ public interface IExtensions

///

KeyValuePair<string, ParseException> LogDeveloperException(string worksheetName, ImportColumnTemplate displayName, string cellAddress, string message, string modelPropertyName);
KeyValuePair<int, ParseException> LogDeveloperException(string worksheetName, ImportColumnTemplate displayName, string cellAddress, int rowNumber, string message);
KeyValuePair<string, ParseException> LogNullReferenceException(string worksheetName, ImportColumnTemplate displayName, string cellAddress, string modelPropertyName);
KeyValuePair<int, ParseException> LogNullReferenceException(string worksheetName, ImportColumnTemplate displayName, string cellAddress, int rowNumber);
KeyValuePair<int, ParseException> LogCellException(string worksheetName, ImportColumnTemplate displayName, string cellAddress, int rowNumber);
KeyValuePair<string, ParseException> LogCellException(string worksheetName, ImportColumnTemplate displayName, string cellAddress, string modelPropertyName);
KeyValuePair<string, ParseException> LogDeveloperException(string worksheetName, ImportColumn column, string cellAddress, string message, string modelPropertyName);
KeyValuePair<int, ParseException> LogDeveloperException(string worksheetName, ImportColumn column, string cellAddress, int rowNumber, string message);
KeyValuePair<string, ParseException> LogNullReferenceException(string worksheetName, ImportColumn column, string cellAddress, string modelPropertyName);
KeyValuePair<int, ParseException> LogNullReferenceException(string worksheetName,ImportColumn column, string cellAddress, int rowNumber);
KeyValuePair<int, ParseException> LogCellException(string worksheetName, ImportColumn column, string cellAddress, int rowNumber);
KeyValuePair<string, ParseException> LogCellException(string worksheetName, ImportColumn column, string cellAddress, string modelPropertyName);

}
}
75 changes: 75 additions & 0 deletions ExcelExtensions/Interfaces/Import/IColumnMap.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright (c) Dominic Schira <domshyra@gmail.com>. All Rights Reserved.

using ExcelExtensions.Models;
using ExcelExtensions.Models.Columns;
using ExcelExtensions.Models.Columns.Export;
using ExcelExtensions.Models.Columns.Import;
using System;
using System.Collections.Generic;
using System.Reflection;
using static ExcelExtensions.Enums.Enums;

namespace ExcelExtensions.Interfaces.Import
{
//todo fix these comments
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO

/// <summary>
/// Provides methods to give to the parse methods from models
/// </summary>
public interface IColumnMap
{
/// <summary>
///
/// </summary>
/// <param name="import"></param>
/// <param name="currentColumnNumber"></param>
/// <param name="columnsUsed"></param>
/// <param name="modelPropertyName"></param>
/// <param name="attribute"></param>
/// <returns></returns>
int GetAttributeColumnNumber(bool import, int currentColumnNumber, Dictionary<int, string> columnsUsed, string modelPropertyName, ColumnAttribute attribute);
/// <summary>
///
/// </summary>
/// <param name="modelType"></param>
/// <param name="item"></param>
/// <param name="formatType"></param>
/// <param name="modelPropertyName"></param>
/// <param name="displayName"></param>
/// <param name="attribute"></param>
/// <param name="format"></param>
/// <param name="required"></param>
void GetColumnAttributes(Type modelType, PropertyInfo item, FormatType formatType, out string modelPropertyName, out string displayName, out ColumnAttribute attribute, out FormatType format, out bool required);
/// <summary>
///
/// </summary>
/// <param name="modelType"></param>
/// <param name="formatType"></param>
/// <param name="startColumnNumber"></param>
/// <returns></returns>
List<ExportColumn> GetExportColumns(Type modelType, FormatType formatType = FormatType.String, int startColumnNumber = 1);
/// <summary>
///
/// </summary>
/// <param name="modelType"></param>
/// <param name="formatType"></param>
/// <param name="startColumnNumber"></param>
/// <returns></returns>
List<InAndOutColumn> GetInAndOutColumns(Type modelType, FormatType formatType = FormatType.String, int startColumnNumber = 1);
/// <summary>
///
/// </summary>
/// <param name="modelType"></param>
/// <param name="formatType"></param>
/// <param name="startColumnNumber"></param>
/// <returns></returns>
List<InformedImportColumn> GetInformedImportColumns(Type modelType, FormatType formatType = FormatType.String, int startColumnNumber = 1);
/// <summary>
///
/// </summary>
/// <param name="modelType"></param>
/// <param name="formatType"></param>
/// <param name="startColumnNumber"></param>
/// <returns></returns>
List<UninformedImportColumn> GetUninformedImportColumns(Type modelType, FormatType formatType = FormatType.String, int startColumnNumber = 1);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Dominic Schira <domshyra@gmail.com>. All Rights Reserved.

using ExcelExtensions.Models;
using ExcelExtensions.Models.Import;
using OfficeOpenXml;

namespace ExcelExtensions.Interfaces.Import
Expand Down
5 changes: 3 additions & 2 deletions ExcelExtensions/Interfaces/Import/Parse/ITableParser.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Dominic Schira <domshyra@gmail.com>. All Rights Reserved.

using ExcelExtensions.Models;
using ExcelExtensions.Models.Columns.Import;
using OfficeOpenXml;
using System.Collections.Generic;

Expand All @@ -12,7 +13,7 @@ namespace ExcelExtensions.Interfaces.Import.Parse
/// <typeparam name="T">Object the excel data is being mapped to.</typeparam>
public interface ITableParser<T>
{
ParsedTable<T> ScanForColumnsAndParseTable(List<ImportColumnTemplate> columns, ExcelWorksheet workSheet, int headerRowNumber = 1, int maxScanHeaderRowThreashold = 100);
ParsedTable<T> ParseTable(List<ImportColumnTemplate> columns, ExcelWorksheet workSheet, int headerRowNumber = 1);
ParsedTable<T> UninformedParseTable(List<UninformedImportColumn> columns, ExcelWorksheet workSheet, int headerRowNumber = 1, int maxScanHeaderRowThreashold = 100);
ParsedTable<T> InformedParseTable(List<InformedImportColumn> columns, ExcelWorksheet workSheet, int headerRowNumber = 1);
}
}
File renamed without changes.
69 changes: 0 additions & 69 deletions ExcelExtensions/Models/Column.cs

This file was deleted.

83 changes: 83 additions & 0 deletions ExcelExtensions/Models/ColumnAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright (c) Dominic Schira <domshyra@gmail.com>. All Rights Reserved.

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Reflection;
using static ExcelExtensions.Enums.Enums;

namespace ExcelExtensions.Models
{
/// <summary>
/// Provides extensions to models for import and export with excel extensions
/// </summary>
[AttributeUsage(AttributeTargets.Property, Inherited = false)]
public class ColumnAttribute : Attribute
{
/// <summary>
/// Represent the list of options for the header name
/// <para>Default will look at the <see cref="PropertyInfo.Name"/> and the <see cref="DisplayAttribute.Name"/></para>
/// </summary>
public List<string> ImportColumnTitleOptions { get; set; }

/// <summary>
/// If required then <see cref="ParseExceptionSeverity.Error"/> if not then <see cref="ParseExceptionSeverity.Warning"/>
/// </summary>
public bool IsRequired { get; set; }

//Might be able to deprecate this ????????? who knows yet
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add more descript comment as to why I can deprecate it

/// <summary>
/// Represents the format type for the excel object
/// </summary>
public FormatType Format { get; set; }
/// <summary>
/// Represents the number of decimal places in the output for export
/// </summary>
public int? DecimalPrecision { get; set; }

/// <summary>
/// Represents the export location
/// </summary>
public string? ExportColumnLetter { get; set; }
/// <summary>
/// Represents the export location
/// </summary>
public int? ExportColumnNumber { get; set; }
/// <summary>
/// Represents the import location
/// </summary>
public string? ImportColumnLetter { get; set; }
/// <summary>
/// Represents the import location
/// </summary>
public int? ImportColumnNumber { get; set; }

public ColumnAttribute()
{
IsRequired = true;
}

//todo summary
/// <summary>
///
/// </summary>
/// <param name="format"></param>
/// <param name="titleOptions"></param>
/// <param name="precision"></param>
public ColumnAttribute(FormatType format, List<string> titleOptions = null, int? precision = null)
{
if (titleOptions is not null)
{
ImportColumnTitleOptions = titleOptions;
}

if (precision is not null)
{
DecimalPrecision = precision;
}

Format = format;
IsRequired = true;
}
}
}
42 changes: 42 additions & 0 deletions ExcelExtensions/Models/Columns/Column.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) Dominic Schira <domshyra@gmail.com>. All Rights Reserved.

using ExcelExtensions.Interfaces;
using System;
using static ExcelExtensions.Enums.Enums;

namespace ExcelExtensions.Models.Columns
{
/// <summary>
/// Represents an excel column
/// </summary>
public class Column
{
public string ModelProperty { get; set; }
/// <summary>
/// Represents the human readable column header name/title
/// </summary>
public string DisplayName { get; set; }
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HeaderTitle

/// <summary>
/// Represents the format type for the excel object
/// </summary>
public FormatType Format { get; set; }
/// <summary>
/// Represents the number of decimal places in the output for export
/// </summary>
public int? DecimalPrecision { get; set; }

public int? ColumnNumber { get; set; }
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add description


public Column()
{

}
public Column(string modelPropertyName, string displayName, FormatType format, int? decimalPrecision = null)
{
ModelProperty = modelPropertyName;
DisplayName = displayName;
Format = format;
DecimalPrecision = decimalPrecision;
}
}
}
Loading