Click here to Skip to main content
15,889,719 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

i am new in c#. I have found code to convert the CSV file to Xls. Now i need to set the cells color and font size for my output the (Xls) file.

Is there any easy way to do it ?

Thanks
C#
static void Main(string[] args)
{
 string csvFilePath = @"D:\sample.csv";
 string excelFilePath = @"D:\sample.xls";
 
 string worksheetsName = "TEST";
 bool firstRowIsHeader = false;
 
 var excelTextFormat = new ExcelTextFormat();
 excelTextFormat.Delimiter = ',';
 excelTextFormat.EOL = "\r";
 
 var excelFileInfo = new FileInfo(excelFilePath);
 var csvFileInfo = new FileInfo(csvFilePath);
 
 using (ExcelPackage package = new ExcelPackage(excelFileInfo))
 {
  ExcelWorksheet worksheet = package.Workbook.Worksheets.Add(worksheetsName);
  worksheet.Cells["A1"].LoadFromText(csvFileInfo, excelTextFormat, OfficeOpenXml.Table.TableStyles.Medium25, firstRowIsHeader);
  package.Save();
 }
 
 Console.WriteLine("Converted!");
 Console.ReadLine();
}


What I have tried:

i have tried to find easy way to do it
Posted
Updated 3-May-17 21:43pm

1 solution

Use this to read the CSV file: A Fast CSV Reader[^]
Then use this to write the XLS file: Google Code Archive - Long-term storage for Google Code Project Hosting.[^]
 
Share this answer
 
Comments
Alshaikhli 4-May-17 4:49am    
can i edit this code to set the color for the formula header ? Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900