diff --git a/Program.cs b/Program.cs index f4541f1..4bf4e13 100644 --- a/Program.cs +++ b/Program.cs @@ -19,15 +19,31 @@ static void Main(string[] args) var config = builder.Build(); - Console.WriteLine("Test addRowTotal"); - TestAddRowTotal(config); + BuildMenu(); + //TestBuildDataForPivot(config); + //TestAddRowTotal(config); + //TestBuildPivot(config); + RunAll(config); Console.ReadLine(); } + public static void BuildMenu() + { + + } + + public static void RunAll(IConfigurationRoot config) + { + TestAddRowTotal(config); + //TestBuildPivot(config); + TestPivotAtOnce(config); + } + public static void TestAddRowTotal(IConfigurationRoot config) - { + { + Console.WriteLine("Test addRowTotal"); string sql = @"SELECT TOP 10 ProductName ,sum(quantity) as Bottles_sold @@ -37,16 +53,77 @@ FROM [dbo].[Order Details Extended] var results = GetDataTable(config, sql, null); var file = AppDomain.CurrentDomain.BaseDirectory + "/output/rowtotal.xlsx"; - ExcelHelper eh = ExcelHelper.Create(file); - eh.Dump(results, "SHEET1"); - eh.AddRowTotal("SHEET1"); - //eh.DoPivotTable("SHEET1", "SHEET2", new string[]{"ProductName"}, new string[] {"Subtotal_per_Wine" }); - eh.Save(); + if (System.IO.File.Exists(file)) + { + System.IO.File.Delete(file); + } + ExcelHelper eh = ExcelHelper.Create(file) + .Dump(results, "SHEET1") + //.DoPivotTable("SHEET1","SHEET2", new string[]{"ProductName"}, new string[]{"Bottles_sold"}, new string[]{"Subtotal_per_Wine" }) + .AddRowTotal("SHEET1") + .Save(); eh.Dispose(); Console.WriteLine("file created in " + file); Console.WriteLine("End testAddRowTotal"); } + public static void TestBuildDataForPivot(IConfigurationRoot config) + { + string sql = "SELECT * FROM Invoices ORDER BY OrderDate"; + var results = GetDataTable(config, sql, null); + var file = AppDomain.CurrentDomain.BaseDirectory + "/output/pivot.xlsx"; + ExcelHelper eh = ExcelHelper.Create(file) + .Dump(results, "SHEET1") + .Save(); + eh.Dispose(); + } + + public static void TestBuildPivot(IConfigurationRoot config) + { + Console.WriteLine("Begin TestBuildPivot"); + var file = AppDomain.CurrentDomain.BaseDirectory + "/output/pivot.xlsx"; + if (System.IO.File.Exists(file) != true) + { + TestBuildDataForPivot(config); + } + ExcelHelper eh = ExcelHelper.Create(file) + .DoPivotTable("SHEET1", + "SHEET2", + new string[] { "ShipCountry" }, + new string[] { "ProductName" }, + new string[] { "ExtendedPrice" } + ) + .Save(); + eh.Dispose(); + Console.WriteLine("file created in " + file); + Console.WriteLine("End testBuildPivot"); + + } + + public static void TestPivotAtOnce(IConfigurationRoot config) + { + Console.WriteLine("Begin TestPivotAtOnce"); + string sql = "SELECT * FROM Invoices ORDER BY OrderDate"; + var results = GetDataTable(config, sql, null); + var file = AppDomain.CurrentDomain.BaseDirectory + "/output/pivot_at_once.xlsx"; + if (System.IO.File.Exists(file)) + { + System.IO.File.Delete(file); + } + ExcelHelper eh = ExcelHelper.Create(file) + .Dump(results, "SHEET1") + .DoPivotTable("SHEET1", + "SHEET2", + new string[] { "ShipCountry" }, + new string[] { "ProductName" }, + new string[] { "ExtendedPrice" } + ) + .Save(); + eh.Dispose(); + Console.WriteLine("file created in " + file); + Console.WriteLine("End testPivotAtOnce"); + } + public static DataTable GetDataTable(IConfigurationRoot config, string sql, Hashtable _params = null) { //Console.WriteLine(config["ConnectionString"]); diff --git a/img/pivot1.png b/img/pivot1.png new file mode 100644 index 0000000..5f6853f Binary files /dev/null and b/img/pivot1.png differ diff --git a/img/pivot2.png b/img/pivot2.png new file mode 100644 index 0000000..0e114a5 Binary files /dev/null and b/img/pivot2.png differ diff --git a/img/rowTotal.png b/img/rowTotal.png new file mode 100644 index 0000000..928ff91 Binary files /dev/null and b/img/rowTotal.png differ