在多个线路上写入数据但是在csv的同一个单元格内? [英] write data on multiple lines BUT within the same cell of csv?

查看:83
本文介绍了在多个线路上写入数据但是在csv的同一个单元格内?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



在数据库表格中我有单格列中的数据格式 -





这是测试< br />

问题< br />

for< br />

电子学习



当我们写csv文件时它应该在同一个单元格中并且像这样相同

但它会在其他每个鱼尾结束后的细胞。



如果我这样做,这是测试< br />问题< br /> for< br />电子教学



它在同一个单元格中写得很好。但是我通过ckeditor输入数据所以我们需要按一下时间输入所以数据有多行。

解决方案

你必须要了解的是,没有单元格一个.csv文件。它只是一个包含特定字段/记录分隔符的文本文件(表格,逗号,分号,回车符......)。



因此存储带换行符的字段在.csv文件中不可能原样。



因此,为了能够核心地存储您的价值,您需要摆脱CR-您的数据中的LF。



这可以通过以下代码实现,例如:



< pre lang =c#> // 这里我假设您将数据库中的值输入< var> columnValue<的/ var>变量。
columnValue = columnValue.Replace(Environment.NewLine, string .Empty);





这里我们用空白字符替换新行字符,实际上是抑制换行符。但是你可以用另一个角色代替,如果你想知道哪些换行被删除了。



希望这会有所帮助。


如果您正在讨论在csv文件中的字段内存储换行符,您可以尝试使用双引号等文本分隔符。

Col1 ,Col2,Col3 .... 
..... col3在下一行继续,Col4,Col5


hi All,

In databse table i have data this format in single sigle column -


This is test<br />
Question<br />
for<br />
Elearning

when we write csv file the it should be in same cell and same like this
but it is going in other cell after each roe end.

if i do this as This is test<br />Question<br />for<br />Elearning

It writing fine in same cell. But I am entering data through ckeditor so we need press some time enter so data goes in multiple lines.

解决方案

What you have to understand is that there is no cell in a .csv file. It is just a text file with specific fields/records separators (tabulations, commas, semicolons, carriage return...).

Thus storing a field with a line break is not possible ''as is'' in a .csv file.

So, to be able to store your value corectly, you need to get rid of CR-LF in your data.

This could be achieved with the following code, for example :

// Here I assume you got the value from database into the <var>columnValue</var> variable.
columnValue = columnValue.Replace(Environment.NewLine, string.Empty);



Here we replace the new-line characters with a blank one, actually suppressing the line break. But you could replace by another character, if you want to be able to know which line breaks were removed.

Hope this helps.


If you are talking about storing a line break inside a field in a csv file, you can try using a text delimiter like double quotes.

"Col1", "Col2", "Col3....
.....col3 continued in next line", "Col4", "Col5"


这篇关于在多个线路上写入数据但是在csv的同一个单元格内?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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