Code to Clean the CSV File
Code to Clean the CSV File
using System.Collections.Generic;
using System.IO;
using OfficeOpenXml;
class Program
{
static void Main()
{
// Set the license context (Required for EPPlus 5+)
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
string inputFilePath =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
"Downloads", "Fast people search.xlsx");
string outputFilePath =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
"Oklahoma Ok Leads.xlsx");
for (int row = 2; row <= rowCount; row++) // Start from row 2 to skip
headers
{
string fullName = worksheet.Cells[row, 1].Text.Trim();
string address = worksheet.Cells[row, 2].Text.Trim();
string contact = worksheet.Cells[row, 3].Text.Trim();
if (string.IsNullOrEmpty(fullName) ||
string.IsNullOrEmpty(address))
continue; // Skip empty rows
records.Add(new Person
{
FirstName = firstName,
LastName = lastName,
Address = address,
City = "Oklahoma City",
State = "OK",
ZipCode = zipCode,
Contact = contact
});
}
}
// Add headers
worksheet.Cells[1, 1].Value = "First Name";
worksheet.Cells[1, 2].Value = "Last Name";
worksheet.Cells[1, 3].Value = "Address";
worksheet.Cells[1, 4].Value = "City";
worksheet.Cells[1, 5].Value = "State";
worksheet.Cells[1, 6].Value = "ZipCode";
worksheet.Cells[1, 7].Value = "Contact";
int row = 2;
foreach (var person in records)
{
worksheet.Cells[row, 1].Value = person.FirstName;
worksheet.Cells[row, 2].Value = person.LastName;
worksheet.Cells[row, 3].Value = person.Address;
worksheet.Cells[row, 4].Value = person.City;
worksheet.Cells[row, 5].Value = person.State;
worksheet.Cells[row, 6].Value = person.ZipCode;
worksheet.Cells[row, 7].Value = person.Contact;
row++;
}
// Save to file
File.WriteAllBytes(outputFilePath, package.GetAsByteArray());
}