zoukankan      html  css  js  c++  java
  • 导出CSV 换行问题。

    程序方面:

    1.Windows 中的换行符" "

    2.Unix/Linux 平台换行符是 " "。

    3.MessageBox.Show() 的换行符为 " "

    4.Console 的换行符为 " "

    为保持平台的通用性,可以用系统默认换行符 System.Environment.NewLine。

    sql server:换行

    select subscriber_id,subscriber_email,company_name from [dbo].[NewsLetterSystem_Subscriber]
    where subscriber_id=6967035
    
    update [NewsLetterSystem_Subscriber] 
    set company_name=N'ALLY CATERING SOLUTION LIMITED'+CHAR(13)+CHAR(10) +N'安聯餐飲設備有限公司'
    where subscriber_id=6967035
    
    update [NewsLetterSystem_Subscriber] 
    set company_name=N'ALLY CATERING SOLUTION LIMITED'+CHAR(10) +N'安聯餐飲設備有限公司'
    where subscriber_id=6967035
    
    
    update [NewsLetterSystem_Subscriber] 
    set company_name=N'ALLY CATERING SOLUTION LIMITED'+CHAR(13) +N'安聯餐飲設備有限公司'
    where subscriber_id=6967035

    C# 程序:

      public static string ExportReportInCsv(DataTable dt, string filename, string tmpDir)
            {
                string tmpFilename = DateTime.Now.Ticks + "_" + filename;
                string tmpFilenameWithPath = tmpDir + tmpFilename;
                FileStream fs = new FileStream(tmpFilenameWithPath, System.IO.FileMode.Create, System.IO.FileAccess.Write);
                //var encoding = GetFileEncodeType(fs);
                StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.UTF8);
                StringBuilder sb = new StringBuilder();
                //写出列名称
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    sb.Append(dt.Columns[i].ColumnName.ToString());
                    if (i < dt.Columns.Count - 1)
                    {
                        sb.Append(",");
                    }
                }
                sw.WriteLine(sb.ToString());
    
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    sb.Clear();
                    for (int j = 0; j < dt.Columns.Count; j++)
                    {
                        string rowsText = dt.Rows[i][j].ToString();
                        rowsText = HandleWrap(rowsText);
                        sb.Append(rowsText);
                        if (j < dt.Columns.Count - 1)
                        {
                            sb.Append(",");
                        }
                    }
                    sw.WriteLine(sb.ToString());
                }
                sw.Close();
                fs.Close();
                return tmpFilenameWithPath;
            }
    
    
      public static string HandleWrap(string content)
            {
                if (content.Contains(Environment.NewLine))
                {
                    var list = content.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    content = string.Join(" ",list);
                }
      
                content = content.Replace(@"
    ", " ").Replace(@"
    ", " ").Replace((char)13,' ').Replace((char)10, ' ');
                return content;
            }
  • 相关阅读:
    ffmpeg中的sws_scale算法性能测试
    ffmpeg 新老接口问题及对照集锦
    入门视频采集与处理(显示YUV数据)
    RGB与YUV图像视频格式的相互转换
    ffmpeg视频解码简明教程
    FFmpeg源代码简单分析——sws_getContext()
    FFmpeg解码H264及swscale缩放详解
    我所理解的ThreadLocal
    网络通信Socket模块实现文件传输
    设计一个基于flask的高并发高可用的查询ip的http服务
  • 原文地址:https://www.cnblogs.com/zoro-zero/p/7340077.html
Copyright © 2011-2022 走看看