Skip to content

Commit

Permalink
examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mustaddon committed Feb 2, 2024
1 parent fba3b53 commit 48ecc99
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions Examples/Example.ConsoleApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ static void Main()
Example5();
Example6();

TestTypes();
TestDictionary();
TestExpandoObject();
TestHashtable();
TestDataTable();
TestObject();
TestTypes();
}

static readonly IEnumerable<SomeItem> SomeItems = Enumerable.Range(1, 10).Select(x => new SomeItem
Expand Down Expand Up @@ -114,6 +114,35 @@ static void Example6()
File.WriteAllBytes($@"..\..\..\..\{nameof(Example6)}.xlsx".ToLower(), excel);
}


// different types + stream
static void TestTypes()
{
var items = Enumerable.Range(1, 100).Select(x => new
{
String = "1) text text text; \n2) text text text !!!",
WrapText = new CellText("1) text text text; \n2) text text text", wrap: true),
Bool = x % 2 == 0,
NullableBool = x % 2 == 0 ? true : (bool?)null,
Int = -x * 100,
Uint = (uint)x * 100,
Long = (long)x * 100,
Double = 1.1d + x,
Float = 1.1f + x,
Decimal = 1.1m + x,
DateTime = DateTime.Now.AddDays(-x),
DateTimeOffset = DateTimeOffset.Now.AddDays(-x),
Uri = new Uri($"https://www.google.com/search?q={x}"),
Hyperlink = new CellHyperlink($"https://www.google.com/search?q={x}", $"link_{x}"),
Formula = new CellFormula(row => $"G{row}+H{row}"),
Percent = new CellPercent(1d / x),
});


using var file = File.Create($@"..\{nameof(TestTypes)}.xlsx");
items.ToExcel(file);
}

// list of dictionaries
static void TestDictionary()
{
Expand Down Expand Up @@ -196,32 +225,4 @@ static void TestObject()

File.WriteAllBytes($@"..\{nameof(TestObject)}.xlsx", excel);
}

// different types + stream
static void TestTypes()
{
var items = Enumerable.Range(1, 100).Select(x => new
{
String = "1) text text text; \n2) text text text !!!",
WrapText = new CellText("1) text text text; \n2) text text text", wrap: true),
Bool = x % 2 == 0,
NullableBool = x % 2 == 0 ? true : (bool?)null,
Int = -x * 100,
Uint = (uint)x * 100,
Long = (long)x * 100,
Double = 1.1d + x,
Float = 1.1f + x,
Decimal = 1.1m + x,
DateTime = DateTime.Now.AddDays(-x),
DateTimeOffset = DateTimeOffset.Now.AddDays(-x),
Uri = new Uri($"https://www.google.com/search?q={x}"),
Hyperlink = new CellHyperlink($"https://www.google.com/search?q={x}", $"link_{x}"),
Formula = new CellFormula(row => $"G{row}+H{row}"),
Percent = new CellPercent(1d / x),
});


using var file = File.Create($@"..\{nameof(TestTypes)}.xlsx");
items.ToExcel(file);
}
}

0 comments on commit 48ecc99

Please sign in to comment.