csv读写 [英] csv read write

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

问题描述

大家好,


我在网上搜索了我如何阅读csv文件(特定单元格)但

并没有找到太多。

任何人都可以给我一个链接或帮助如何读取或写入csv文件中特定的

单元格?

使用SQL可以很棒。


TIA。

解决方案

我一般不会搜索我的csv文件 - 我一般解析整个文件

导入什么。


但基本上我所做的是将文件加载到StringReader然后拆分

每行由分隔以获取每个单独的单元格。


例如:

reader = new StreamReader(FileUploadImport.PostedFile.InputStream);

while(reader.Peek()> = 0)//不是eof

{

String line = reader.ReadLine();

String [] items = line.Split('','');

//现在你可以获得单元格

String name = items [0];

}


你可以引用Interop.Excel Com对象并使用

oXL.Workbooks.OpenText

其中oXL是Excel。应用程序。


你可以循环使用Usedrange获取no。使用的行和列。


您有Cells.Offset或Cell.Select来获取单个单元格。


问候,
Vincent


" XOR"写道:


我一般不会搜索我的csv文件 - 我通常会解析整个文件

导入什么的。


但基本上我所做的是将文件加载到StringReader中,然后将每行分开

以分隔每个单元格。


例如:

reader = new StreamReader(FileUploadImport.PostedFile.InputStream);

while(reader.Peek()> = 0)//不是eof

{

String line = reader.ReadLine();

String [] items = line.Split('','');

//现在你可以获得单元格

String name = items [0];

}




XOR写道:


我一般不会搜索我的csv文件 - 我通常会解析整个文件为

导入什么的。


但基本上我所做的是将文件加载到StringReader中然后分割

每一行用分隔符来获取每个单独的单元格。


例如:

reader = new StreamReader(FileUploadImport.PostedFile .InputStream);

while(reader.Peek()> = 0)//不是eof

{

String line = reader。 ReadLine();

String [] items = line.Split('','');

//现在你可以得到细胞

String name = items [0];

}



您好XOR并感谢您的回复,

如果用户在单元格中插入'',''作为文本,你的解决方案将无法工作。

我该怎么办?


Hi All,

I searched the web to see how i can read csv file (specific cells) but
didn''t find much.
Can anyone give me a link or help how to read or write to a specific
cell in csv file?
Using SQL can be great.

TIA.

解决方案

I generally dont search my csv files - I generally parse the entire file for
an import or something.

But basically what I do is load the file into a StringReader and then split
each line by the delimited to get each individual cell.

eg:
reader = new StreamReader( FileUploadImport.PostedFile.InputStream);
while (reader.Peek() >= 0) //not eof
{
String line = reader.ReadLine();
String[] items = line.Split('','');
//now you can get the cells
String name = items[0];
}


you can reference Interop.Excel Com object and use
oXL.Workbooks.OpenText
where oXL is the Excel.Application.

you can loop through the Usedrange to get the no. of rows and columns used.

You have Cells.Offset or Cell.Select to get the individual cell.

Regards,
Vincent

"XOR" wrote:

I generally dont search my csv files - I generally parse the entire file for
an import or something.

But basically what I do is load the file into a StringReader and then split
each line by the delimited to get each individual cell.

eg:
reader = new StreamReader( FileUploadImport.PostedFile.InputStream);
while (reader.Peek() >= 0) //not eof
{
String line = reader.ReadLine();
String[] items = line.Split('','');
//now you can get the cells
String name = items[0];
}



XOR wrote:

I generally dont search my csv files - I generally parse the entire file for
an import or something.

But basically what I do is load the file into a StringReader and then split
each line by the delimited to get each individual cell.

eg:
reader = new StreamReader( FileUploadImport.PostedFile.InputStream);
while (reader.Peek() >= 0) //not eof
{
String line = reader.ReadLine();
String[] items = line.Split('','');
//now you can get the cells
String name = items[0];
}

Hello XOR and thanks for the reply,

Your solution won''t work if user insert '','' into cell as text.
What can i do about it?


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

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