将CSV文件转换为特定的Excel模板 [英] Convert CSV file to specific excel template
本文介绍了将CSV文件转换为特定的Excel模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我是c#的新手。我找到了将CSV文件转换为Xls的代码。现在我需要为我的输出设置单元格颜色和字体大小(Xls)文件。
有没有简单的方法呢?
谢谢
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
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();
}
我的尝试:
i试图找到简单的方法
What I have tried:
i have tried to find easy way to do it
推荐答案
使用它来读取CSV文件:快速CSV阅读器 [ ^ ]
然后使用它来编写XLS文件:Google代码存档 - Google代码项目托管的长期存储空间。 [ ^ ]
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.[^]
这篇关于将CSV文件转换为特定的Excel模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文