Need to take your Excel data and load it into your database to get the analysts started?
Instead of taking weeks to develop a new data pipeline, create structure, and work with the business to load your new client data in, just drop the file in Perigee. We will take care of everything from finding and getting the data loaded, to creating a table in only a few seconds. You’ll be a hero!
The Data
Here's a typical messed up Excel file where data is shifted and there are unwanted headers.
The Code
usingMicrosoft.Extensions.Logging;usingPerigee;usingPerigee.Database.MSSQL;usingPerigee.FileFormats.Excel;usingSystem.Data;// Visit https://docs.perigee.software to learn more// Visit https://perigee.software to purchase a license!PerigeeApplication.ApplicationNoInit("Quick Data Loads", (c) => { //Registerc.RegisterConnectionString("MSSQL","main"); //ReadusingMemoryStream ms =newMemoryStream(File.ReadAllBytes("SampleExcel.xlsx")); var dtex = ExcelReader.ReadDataTable(ms, "UserData", out var ddt, true, false, tablename: "clientData", schema: "dbo");
//Printvar stats =ddt.GetStatistics(); c.GetLogger<Program>().LogInformation("Loaded {r} rows, header is on row {n}. Column names: {@c}. Fill Rate %: {Fill:N2}", dtex.Rows.Count, ddt.HeaderRow + 1, dtex.Columns.OfType<DataColumn>().Select(f => f.ColumnName).ToArray(), (stats.FillRate?.Average(f => f.Value) ?? 0.0m) * 100.0m);
foreach (var col instats?.FillRate?.Reverse() ??Array.Empty<KeyValuePair<uint,decimal>>()) { c.GetLogger<Program>().LogInformation("{Column} fill rate %: {fr}", stats!.ColumnNames[col.Key], col.Value * 100.0m);
} //Load, create or drop. MSSQLProcessUtilities.ProcessToSQL(dtex, "MSSQL", true, new SQLTableColumnDefaults() { StringType = SqlDbType.NVarChar }, DropTableIfNotExists: true);
});
After running the application, you'll see the log showing how many rows it found, where the header was since it wasn't on the top row, and the column's detected. It even prints out the fill rates per column!
Taking a peak at our database, we see the data loaded into our new table dbo.clientData:
Which came directly from the Excel file linked below