我有一个包含50个文本文件的文件夹,我需要一个可以读取这些文本文件并将它们转换为表格的C#或.NET程序,我希望主键是文本文件本身的名称。如何从文件夹中读取文本文件并将其转换为MySQL中的表格
//sample contents of my 1.txt file is as follows
atro
astrology
king
moon
monkey
seven
skin //
所有文本文件都包含相同格式的信息。 我已经写了一个宏,它可以读取上述数据格式的文本文件,然后当我尝试在Excel中运行宏时,我收到一个错误,指出内存不足。
enter code here
子rameshc() ' ' 拉梅什宏 ' ' 快捷键:Ctrl + K ' 昏暗nxt_row只要
'Change Path
Const strPath As String = "C:\Users\roo\Desktop\Volumes\eGo\tags\0\"
Dim strExtension As String
'Stop Screen Flickering
Application.ScreenUpdating = False
ChDir strPath
'Change extension
strExtension = Dir(strPath & "*.txt")
Do While strExtension <> ""
'Adds File Name as title on next row
Range("A65536").End(xlUp).Offset(1, 0).Value = strExtension
'Sets Row Number for Data to Begin
nxt_row = Range("A65536").End(xlUp).Offset(1, 0).Row
'Below is from a recorded macro importing a text file
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & strPath & strExtension, Destination:=Range("$A$" & nxt_row))
.Name = strExtension
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
'Delimiter Settings:
.TextFileConsecutiveDelimiter = True
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = True
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = True
.TextFileOtherDelimiter = "="
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
strExtension = Dir
Loop
Application.ScreenUpdating = True
结束子 子拉梅什() ' 'ramesh宏 ' '键盘快捷键:Ctrl + l ' Selection.Copy ActiveCell.Offset(0,1).Range(“A1”)。Select Selection.PasteSpecial Paste:= xlPasteAll,Operation:= xlNone,SkipBlanks:= _ False,Transpose:= True End Sub
你能读一个文件夹中的所有文件,并生成SQL代码,将创建每个数据表的。所有你需要做的就是复制粘贴生成的SQL并在MySQL中执行它。 – 2013-02-25 10:59:45
@rameshkumar我是新来的,所以我请你简单介绍一下程序 – rameshkumar 2013-02-25 11:10:58
你真正的问题是什么?你卡在哪里?我们不能为你写这个程序。 – mattmanser 2013-02-25 11:53:45