背景:
我在Asp.Net (C#) web应用程序中使用了CSV作为数据交换格式。该文件通常用于对请求进行批量上载。到目前为止,它还能正常工作,而且仍然有效。
然而,在对文化的研究中,我们发现csv文件存在许多问题。最大的问题之一是分隔符是由区域设置来决定的。当用户在Ms Excel中编辑文件时会发生这种情况。例如,分隔符在US为逗号,在欧洲某些地区为分号。
我已经搜查了很长一段时间了,但我还没有找到任何处理这种案子的灵丹妙药。现在我想知道:
- The file is plain text (not encoded file like ms excel xlsx)
- It is invariant culture. I don't mean to handle decimal separator but at least invariant at delimiter
- It is supported in spreadsheet applications such as Ms Excel
- (optional) It can be read by OleDb engine
或者,如果有的话,是否有使用平面文件进行表格数据交换的良好做法?
更新:
到目前为止,这里总结了给出的解决方案的利弊。
- Supported by many processor such as Excel and OleDb
- Easy to read
- Easy to manipulate using notepad缺点:
- Has delimiter culture problem when editing with ms excel
- Need to escape or handle delimiter characters
- Supported by many processor such as Excel and xml serializer
- Easy to manipulate using notepad
- Represent structural format缺点:
- Need additional handling when being processed in excel
- Using tags resulting in more content inside the xml
- Represent structural format
- Easy to manipulate using notepad缺点:
- Not natively supported by spreadsheet processor such as excel (need to ensure)
发布于 2013-05-10 19:06:33
使用选项卡作为分隔符是一个简单的开关,似乎大多数库都支持读或写,并且使用Excel。
发布于 2013-05-10 17:06:54
对CSV的一个简单的替代可以是JSON --它是一个非常简单的格式,在不同的平台上都有很多支持。
与CSV有关的问题的主要好处在于它没有这些问题--它不依赖于文化。
它也有缺点,但这些都是与CSV共享的(例如,没有数据类型)。
发布于 2013-05-10 17:10:50
XML是一种比CSV更好的数据交换方法。
https://stackoverflow.com/questions/16487382
复制相似问题