您的位置:首页 > 其它

.NET生成CSV文件

2011-10-13 16:03 302 查看
StreamWriter sw = null;
try
{
//string sql = "SELECT ProductID,ProductMode,ProductName,Warranty,Weight,ParentMode,NetWeight,WeightUnit FROM Product";
//DataSet ds = DBHelper.RunSQLReturnDS(sql);

string filePath = Server.MapPath("/csv");
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}

string name = filePath + "/labelprint_template.csv";

if (File.Exists(name))
{
File.Delete(name);
}

sw = new StreamWriter(name, true, System.Text.Encoding.UTF8, 200);
StringBuilder sbTitle = new StringBuilder();
sbTitle.Append("Check,Status,Bill NO,Download Batch NO,Order Time,E-source,");
sbTitle.Append("Print Date,Warehouse Name,Item #,Item Name,Listing Item Name,");
sbTitle.Append("ebayTransactionID,ebayItemID,Company Name,Contact,Address 1,Address 2,");
sbTitle.Append("City,State,Zip,Phone,Email,Quantity,Weight,Length,Width,Height,");
sbTitle.Append("Price,Signature,ServiceType,Sender_company,Sender_contact,Sender_email,");
sbTitle.Append("Sender_code,Sender_address1,Sender_address2,Sender_city,Sender_zip,Sender_state");
sw.WriteLine(sbTitle.ToString());

StringBuilder sbContent = new StringBuilder();
sbContent.Append(",Normal,Jasya Siliceo-Kellman,,,,");
sbContent.Append(",,Jan-64,Wooden Playpen Recall Parts,,");
sbContent.Append(",,Aosom,Aosom,21447 SW 108th Ave,,");
sbContent.Append("Tualatin,OR,97062,5036120860,service@aosom.com,1,12,39,27,3,");
sbContent.Append(",No,GND,,Jasya Siliceo-Kellman,jbsiliceo@gmail.com,");
sbContent.Append(",75 West End Avenue,R-34D,New York,10023,NY");
sw.WriteLine(sbContent.ToString());
Response.Write("生成成功");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
sw.Close();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: