我正在从sql表中写入数据并将其导出到excel文件,但问题在于数据是否仅在一个单元格中出现,并且所有数据之间都有\
符号。其特殊字符我应该使用来移动到下一列C#将数据写入下一列特殊字符
SqlDataReader dr = cmd.ExecuteReader();
using (System.IO.StreamWriter fs1 = new System.IO.StreamWriter(Filename))
{
// Loop through the fields and add headers
for (int i = 0; i < dr.FieldCount; i++)
{
string name = dr.GetName(i);
if (name.Contains(","))
name = "\"" + name + "\"";
fs1.Write(name + "\\");
}
fs1.WriteLine();
// Loop through the rows and output the data
while (dr.Read())
{
for (int i = 0; i < dr.FieldCount; i++)
{
string value = dr[i].ToString();
if (value.Contains(","))
value = "\"" + value + "\"";
fs1.Write(value + "\\");
}
fs1.WriteLine();
}
fs1.Close();
}
输出 A \ B \ C \ d 在一列..我想下一ABCD到每个其他列
很难理解你的问题,如果它使用'\'作为分隔符,请从文件 – 3dd
中发布一行数据的例子,试试'\\'?不知道有什么问题或你在问什么 – Noctis
@ 3dd它的输出是在一个列中..不在旁边对方列..请检查输出 – user3226440