.NET生成CSV文件

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();
            }

  

posted @ 2011-10-21 12:46  Nemo_Li  阅读(701)  评论(0编辑  收藏  举报