节省csv文件数据 [英] saving data in csv file

查看:173
本文介绍了节省csv文件数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,将数据保存在.csv文件。

I have a problem to save data in .csv file.

     void WriteLog(DataRow rzad)
    {
            StreamWriter sw = new StreamWriter("log.csv", true);
            int iColCount = 8;

            for (int i = 0; i < iColCount; i++)
            {
                if (!Convert.IsDBNull(rzad[i]))
                {
                    sw.Write(rzad[i].ToString());
                    sw.Write("\t");
                }
            }
            sw.Write("\n");
            sw.Flush();
            sw.Close();
    }

问题是德文件我在一列有数据。我想在粉碎格式的DataRow一排8个部分,分别放入8种不同的列。我的工作的功能,因为它没有看到选项卡(\t)

The problem is tak in file I have data in A column. I want to smash one row in DataRow format to 8 parts, which are put in 8 different columns. My function working as it doesn't see the tab ("\t").

所以我尽量描述csv文件的结果,我不能发表图片:

I cant post images so I try to describe results in csv file:

2011-03-17 14:34:11asdPrzekroczono krytyczną minimalną wymaganą wartość parametru5010050080550

这是我的榜样行,我想将它粉碎到8列:

This is my example row and I want to smash it to 8 columns:

2011-03-17 14:34:11     asd     Przekroczono krytyczną minimalną wymaganą wartość parametru   50     100    500     80      550     

#\t#没有帮助。结果是:

"#\t#" doesn't help. The results is:

"2011-03-17 18:29:17#   #asd#   #Przekroczono krytyczną, maksymalną, wymaganą wartość parametru#    #560#   #100#   #500#   #80#    #550#   #"

有一些制表但我的观点是,有人没有空间,但下一个单元格的过渡:(

There is some tabulation but my point is that was made no space but a transition to the next cell :(

\\\也于事无补。

推荐答案

首先,你说你正在编写一个CSV(逗号分隔值)文件。
但是,你真的写,制表符分隔的文件
和,你需要写字里行间/ R / N:

First, you say you are writing to a CSV (comma seperated values) file. But, you are really writing to a tab-delimited file. And, you need to write /r/n between lines:

本作品:

    StreamWriter sw = new StreamWriter(@"c:\log.csv", true); 
    int iColCount = 8; 
    for (int i = 0; i < iColCount; i++)
    {           
        {
            sw.Write(i.ToString()); 
            sw.Write("\t"); 
        } 
    } 
    sw.Write("\r\n"); 
    sw.Flush(); 
    sw.Close();

这篇关于节省csv文件数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆