如何将产品制作成淘宝CSV数据包
2009-02-21 20:00:04 来源:WEB开发网将组织好的数组数据保存为CSV文件的代码:
public static void WriteCSV(string filePathName, bool append, List ls)
{
bool isTaobao = false;
if (ls.Count < 1)
return;
if (ls[0][0].IndexOf("宝贝名称") >= 0)
isTaobao = true;
Encoding code = System.Text.Encoding.Default;
if(isTaobao)
code = System.Text.Encoding.Unicode;
else
code = System.Text.Encoding.GetEncoding("gb2312");
StreamWriter sw = new StreamWriter(filePathName, false,code);
StringBuilder builder = new StringBuilder();
foreach (string[] strArray in ls)
{
for (int i = 0; i < (strArray.Length - 1); i++)
{
if (isTaobao)
{
builder.Append(strArray[i]);
builder.Append("t");
}
else
builder.Append(strArray[i] + ",");
}
if (isTaobao)
{
builder.Append(strArray[strArray.Length - 1]);
builder.Append("t");
}
else
builder.Append(strArray[strArray.Length - 1]);
builder.Append("rn");
}
sw.Write(builder.ToString());
sw.Flush();
sw.Close();
}
更多精彩
赞助商链接