Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions CodeReviews.Console.ExcelReader.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.2.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocumentProcessor.yemiodetola", "DocumentProcessor.yemiodetola\DocumentProcessor.yemiodetola.csproj", "{C9D0FBE3-174F-6FCE-D2C4-7B102ACA0948}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C9D0FBE3-174F-6FCE-D2C4-7B102ACA0948}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C9D0FBE3-174F-6FCE-D2C4-7B102ACA0948}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C9D0FBE3-174F-6FCE-D2C4-7B102ACA0948}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C9D0FBE3-174F-6FCE-D2C4-7B102ACA0948}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7166A67F-77F9-4000-A6B5-FB0681427764}
EndGlobalSection
EndGlobal
12 changes: 12 additions & 0 deletions DocumentProcessor.yemiodetola/Data/AppContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Microsoft.EntityFrameworkCore;
using DocumentProcessor.yemiodetola.Models;
public class DocumentProcessorDbContext : DbContext
{
public DbSet<Contact> Contacts => Set<Contact>();

protected override void OnConfiguring(DbContextOptionsBuilder options)
{
var dbName = System.AppContext.GetData("SqliteDbName") as string ?? "excel_data.db";
options.UseSqlite($"Data Source={dbName}");
}
}
26 changes: 26 additions & 0 deletions DocumentProcessor.yemiodetola/DocumentProcessor.yemiodetola.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup>
<PdfOutputPath>./output.pdf</PdfOutputPath>
<SqliteDbName>excel_data.db</SqliteDbName>
<ExcelFilePath>./sample.xlsx</ExcelFilePath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ClosedXML" Version="0.105.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.0" />
<PackageReference Include="QuestPDF" Version="2025.7.4" />
</ItemGroup>

</Project>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace DocumentProcessor.yemiodetola.Migrations
{
/// <inheritdoc />
public partial class pendingMigrations : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Contacts",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Name = table.Column<string>(type: "TEXT", nullable: false),
Email = table.Column<string>(type: "TEXT", nullable: false),
PhoneNumber = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Contacts", x => x.Id);
});
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Contacts");
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace DocumentProcessor.yemiodetola.Migrations
{
/// <inheritdoc />
public partial class contextupdate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{

}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

#nullable disable

namespace DocumentProcessor.yemiodetola.Migrations
{
[DbContext(typeof(DocumentProcessorDbContext))]
partial class AppDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "9.0.0");

modelBuilder.Entity("DocumentProcessor.yemiodetola.Models.Contact", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");

b.Property<string>("Email")
.IsRequired()
.HasColumnType("TEXT");

b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");

b.Property<string>("PhoneNumber")
.IsRequired()
.HasColumnType("TEXT");

b.HasKey("Id");

b.ToTable("Contacts");
});
#pragma warning restore 612, 618
}
}
}
31 changes: 31 additions & 0 deletions DocumentProcessor.yemiodetola/Models/Contact.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace DocumentProcessor.yemiodetola.Models;

public class Contact
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string PhoneNumber { get; set; } = string.Empty;

public bool ValidateEmailAddress(string email)
{
if (String.IsNullOrEmpty(email))
{
return false;
}
int atIndex = email.IndexOf('@');
int dotIndex = email.LastIndexOf('.');

return atIndex > 0
&& dotIndex > atIndex + 1
&& dotIndex < email.Length - 1;
}

public bool ValidatePhoneNumber(string phoneNumber)
{
return !String.IsNullOrEmpty(phoneNumber)
&& phoneNumber.Length == 11
&& phoneNumber.StartsWith("0")
&& phoneNumber.All(char.IsDigit);
}
}
44 changes: 44 additions & 0 deletions DocumentProcessor.yemiodetola/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Microsoft.Extensions.DependencyInjection;
using System.Threading.Tasks;
using QuestPDF.Infrastructure;
using DocumentProcessor.yemiodetola.Services;

class Program
{
static async Task Main(string[] args)
{
QuestPDF.Settings.License = QuestPDF.Infrastructure.LicenseType.Community;

var services = new ServiceCollection();

services.AddSingleton<IExcelService, ExcelService>();
services.AddSingleton<IPdfService, PdfService>();
var provider = services.BuildServiceProvider();
var excelService = provider.GetRequiredService<IExcelService>();
var pdfService = provider.GetRequiredService<IPdfService>();

var excelPath = AppContext.GetData("ExcelFilePath") as string ?? "./sample.xlsx";
var rows = await excelService.ReadExcelAsync(excelPath);

if (rows == null || rows.Count == 0)
{
Console.WriteLine("Excel file is empty or unreadable.");
return;
}

Console.WriteLine("\nExcel File Contents:\n");
Console.WriteLine($"{"Name",-25} {"Email",-35} {"Phone Number",-15}");
Console.WriteLine(new string('-', 80));
foreach (var contact in rows)
{
Console.WriteLine($"{contact.Name,-25} {contact.Email,-35} {contact.PhoneNumber,-15}");
}
Console.WriteLine(new string('-', 80));

var outputPdf = AppContext.GetData("PdfOutputPath") as string ?? "./output.pdf";

await pdfService.GeneratePdfAsync(outputPdf, rows);

Console.WriteLine($"PDF generated successfully at: {outputPdf}");
}
}
19 changes: 19 additions & 0 deletions DocumentProcessor.yemiodetola/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# DocumentProcessor Console App

## Setup Instructions

1. **Clone the repository**
```sh
cd DocumentProcessor.yemiodetola
```

2. **Add your Excel file**
- Place your Excel file (e.g., `sample.xlsx`) in the project directory. A sample file (`sample.xlsx`) is already provided for testing.
- Ensure the worksheet is named `Contacts` and has columns: Name, Email, Phone Number.

3. **Run the program**
```sh
dotnet run
```

Enjoy!
Loading