Skip to content

RuanVFachini/AutoOpenXML

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AutoOpenXML

https://github.com/RuanVFachini/AutoOpenXML

1 Why does this lib exist?

Using C# attributes annotations 'AutoOpenXML' was created to smooth the exportation and importation process of object collections to the worksheet, providing the correct formats without great cost of implementation.

2 How to use

2.1 Class example:

[ExportWorkSheet(Variables.WorksheetName)]
internal class ModelDateTimeProperty
{
    public string Name { get; set; }

    [ExportColumn(Variables.FieldName, 1)]
    public DateTime BirthDay { get; set; }

    public ModelDateTimeProperty() { }

    public ModelDateTimeProperty(string name, DateTime birthDay)
    {
        Name = name;
        BirthDay = birthDay;
    }
}

2.2 Attributres syntax:

2.2.1 Class Attributres:

[ExportWorkSheet(
    {worksheetname : string}
    {ClosedXml.XLTableTheme.Name : string}
)]

2.2.2 Property Attributres:

2.2.2.1 To Export Column:
[ExportColumn(
    {propertyLabel : string},
    {columnIndex : int},
    {numberFormat : string}
)]
2.2.2.2 Header Column Background:
[ExportColumnHeaderBackgoundColor(
    {red: int},
    {green: int},
    {blue: int})]

2.3 Suported Types:

-string
-int
-bool
-long
-decimal
-long
-DateTime
-int?
-long?
-bool?
-decimal?
-long?
-DateTime?

3 Example

3.1 Model Class Exemple:

[ExportWorkSheet("WorksheetName")]
public class ModelOrderedProperties
{
    [ExportColumn("Code", 2, "00000")]
    [ExportColumnHeaderBackgoundColor(0, 255, 0)]
    public int Id { get; set; }

    [ExportColumn("Name", 1)]
    public string Name { get; set; }

    [ExportColumn("Height", 4)]
    public decimal Height { get; set; }

    [ExportColumn("BirthDateLabel", 3)]
    public DateTime BrithDate { get; set; }

    public ModelOrderedProperties() { }

    public ModelOrderedProperties(
        int id,
        string name,
        decimal height,
        DateTime brithDate)
    {
        Id = id;
        Name = name;
        Height = height;
        BrithDate = brithDate;
    }
}

3.1 Export Class Exemple:

3.1.1 Export Once Worksheet:

var stream = new ExportManagerBuilder<ModelOrderedProperties>()
                    .Init()
                    .SetData(Data.ToList())
                    .StartExportProcess();

var workbook = new XLWorkbook(stream);

3.1.2 Export Many Worksheet:

var stream = new MultiExportManagerBuilder()
                    .Init()
                    .SetData(VariablesModelDateTimeProperty.Data)
                    .SetData(VariablesModelDecimalProperty.Data)
                    .StartExportProcess();

var workbook = new XLWorkbook(stream);

3.2 Import Class Exemple:

var result = new ImportManagerBuilder<ModelDateTimeProperty>()
                .OpenFile(StreamTestFile.GetStreamTestFile(), "Planilha1")
                .Init()
                .StartImportProcess();

4 Obs.:

  • DateTime properties will be exported like DateTime Excel column format. For importation the same column type is required.

5 Release notes:

2.0.x

  • 2.0.1

    • Adjust To Content [Fix]
  • 2.0.2

    • Formula import support [Feat]
  • 2.0.3

    • Import: not string fields: cast to string failure [Fix]

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages