This application can export an Excel file using queried data, which is student`s course enrollment detail from Database.
DB Setup file is included together. The focus of this app is to convert the query result from Database into data table type and further export it to an Excel file.
-
MS SQL : Making EnrollmentDetail View using
INNER JOIN
and saving the calling procedure into Stored procedure. -
C# : Converting query result, which is a List of Objects into DataTable type using
System.Reflection
and exporting to an Excel file usingDocumentFormat.OpenXml
-
Conversion process of a List of objects to a DataTable type is described in my C# snippet repository : List to DataTable Converter
Inside Tester.ModuleTester, there's a test code for the conversion of List to DataTable. You can paste commented code to Program.cs and see whether it's format changed to DataTable correctly.
-
Exporting an Excel file consists of creating a workbookPart -> a worksheetPart -> workwheet and loading data through SheetData. Below is SpreadSheetDocument component's diagram, but you don't really need to memorize the process since it`s rather building blocks like LEGOs than some logics behind.
-
Once a Excel document is created, we move contents inside DataTable to
SheetData
cell by cell and later by row :sheetData.AppendChild(new Row(new List<Cell>));
-
Finally save the Workbook !
-