且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在实际字段中导入具有换行符的CSV

更新时间:2023-02-09 10:13:44

我也有这个问题,没有找到一种正确读取数据的方法。

I had that problem too and did not find an way to read the data correctly.

在我的例子中,这是一次性导入,所以我制作了一个脚本,搜索列中的所有换行符并替换为 ##### 。然后我导入数据并替换为换行符。

In my case it was an one-time-import, so i made an script that searched for all line-breaks within an column and replaced it with something like #####. Then I imported the data and replaced that by linebreaks.

如果你需要一个常规导入,你可以写自己的CSV解析器,处理这个问题。如果文本列在中,则可以将两个之间的一切视为一列在内容中转义)。

If you need an regular import you could write you own CSV-Parser, that handles the problem. If the text-columns are within "" you could treat everything between two "" as one columns (with check for escaped " within the content).