本文介绍了写有颜色代码csv文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写的DataTable的CSV文件。检查下面
I am writing csv file from Datatable. Check my code below
public static void SaveDataTableToCsvFile(string AbsolutePathAndFileName, DataTable TheDataTable, params string[] Options)
{
//variables
string separator;
if (Options.Length > 0)
{
separator = Options[0];
}
else
{
separator = ""; //default
}
string quote = "";
FileInfo info = new FileInfo(AbsolutePathAndFileName);
if (IsFileLocked(info))
{
MessageBox.Show("File is in use, please close the file");
return;
}
//create CSV file
StreamWriter sw = new StreamWriter(AbsolutePathAndFileName);
//write header line
int iColCount = TheDataTable.Columns.Count;
for (int i = 0; i < iColCount; i++)
{
sw.Write(TheDataTable.Columns[i]);
if (i < iColCount - 1)
{
sw.Write(separator);
}
}
sw.Write(sw.NewLine);
//write rows
foreach (DataRow dr in TheDataTable.Rows)
{
for (int i = 0; i < iColCount; i++)
{
if (!Convert.IsDBNull(dr[i]))
{
string data = dr[i].ToString();
data = data.Replace("\"", "\\\"").Replace(",", " ");
sw.Write(quote + data + quote);
}
if (i < iColCount - 1)
{
sw.Write(separator);
}
}
sw.Write(sw.NewLine);
}
sw.Close();
}
代码对我的作品,但我需要的一些细胞中添加颜色代码CSV。
Code works for me ,but I need to add color code in some cells of csv.
我怎么能这样做?
推荐答案
CSV 是没有任何格式的纯数据格式。这毕竟是一个纯文本文件。因此,没有,没有增加颜色的方法。
CSV is a pure data format without any formatting. It's a plain text file after all. So no, there is no way of adding colour.
这篇关于写有颜色代码csv文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!