从文本文件中提取数据到Excel [英] Extract data from text file to excel

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

问题描述

我想从复杂的文本文件内容中提取数据时,代码会如何?

May i know how will the code be if i want to extract data from a complicated text file content?

我希望它自动从文本文件中提取数据,然后将其在excel文件中对齐.

i want it to automatic pick up data from text file,then align it in excel file.

例如文本文件数据:

[四月[0] HA = 204 VA = 360 HT = 858 VT = 525 FR = 30 P]
[4月[1] HA = 612 VA = 1080 HT = 2184 VT = 1134 FR = 60 P]
[五月[2] HA = 1920 VA = 1080 HT = 2184 VT = 1134 FR = 60 P]
[五月[5] HA = 204 VA = 360 HT = 858 VT = 525 FR = 120 P]

[April [0] HA= 204 VA= 360 HT= 858 VT= 525 FR= 30 P]
[April [1] HA= 612 VA=1080 HT=2184 VT=1134 FR= 60 P]
[May [2] HA=1920 VA=1080 HT=2184 VT=1134 FR= 60 P]
[May [5] HA= 204 VA= 360 HT= 858 VT= 525 FR= 120 P]

我希望excel将这些数据填充到单独的列中:

i want excel to fill these data in separate column:

--------------------------------------------------- --------

-------------------------------------------------------

4月| 0 | 204  | 360  | 858  | 525  | 30 |

April | 0 | 204  | 360   | 858   | 525   | 30 |

4月| 1 | 612  | 1080 | 2184 | 1134 | 60 |

April | 1 | 612  | 1080 | 2184 | 1134 | 60 |

五月| 2 | 1920 | 1080 | 2184 | 1134 | 60 |

May | 2 | 1920 | 1080 | 2184 | 1134 | 60 |

........

--------------------------------------------------- -------

------------------------------------------------------

有人可以帮忙吗?

谢谢!

推荐答案

你好,

行内数据的分离是基本的字符串解析.对于将数据插入Excel,请查看创建OleDbDataAdapter,为数据适配器创建insert对象,然后您可以将解析后的数据从文件循环到Excel.

Separation of data within the lines is basic string parsing. For the inserting of data into Excel look at creating an OleDbDataAdapter, create the insert object for the data adapter then you can loop through parsed data from the file into Excel.

我没有C#版本的 以下,但翻译没有太大不同.如果在解决适配器方面不起作用,而又没有其他人的适当答复,那么我可以创建一个C#示例以与今天晚些时候的vb.net示例匹配.

I don't have a C# version of the following but the translation is not very different. If that does not work for you in regards to figuring out the adapter and not a suitable reply from others I can create a C# example to match the vb.net example later today.


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

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