https://github.com/RuanVFachini/AutoOpenXML
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.
[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;
}
}
[ExportWorkSheet(
{worksheetname : string}
{ClosedXml.XLTableTheme.Name : string}
)]
[ExportColumn(
{propertyLabel : string},
{columnIndex : int},
{numberFormat : string}
)]
[ExportColumnHeaderBackgoundColor(
{red: int},
{green: int},
{blue: int})]
-string
-int
-bool
-long
-decimal
-long
-DateTime
-int?
-long?
-bool?
-decimal?
-long?
-DateTime?
[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;
}
}
var stream = new ExportManagerBuilder<ModelOrderedProperties>()
.Init()
.SetData(Data.ToList())
.StartExportProcess();
var workbook = new XLWorkbook(stream);
var stream = new MultiExportManagerBuilder()
.Init()
.SetData(VariablesModelDateTimeProperty.Data)
.SetData(VariablesModelDecimalProperty.Data)
.StartExportProcess();
var workbook = new XLWorkbook(stream);
var result = new ImportManagerBuilder<ModelDateTimeProperty>()
.OpenFile(StreamTestFile.GetStreamTestFile(), "Planilha1")
.Init()
.StartImportProcess();
- DateTime properties will be exported like DateTime Excel column format. For importation the same column type is required.
-
- Adjust To Content [Fix]
-
- Formula import support [Feat]
-
- Import: not string fields: cast to string failure [Fix]