我有一個包含100多個.txt文件巫婆我要導入的每個一文中的文件夾(可以這麼結束了超過100篇)在我的Joomla網站批量導入查詢 - 的Joomla
看來,最簡單的方法是導入我的.txt在使用像我現有的MySQL:
LOAD DATA LOCAL INFILE 'example.txt' INTO TABLE example_table
但我怎麼能導入所有我的文件一次(批量導入)?
我有一個包含100多個.txt文件巫婆我要導入的每個一文中的文件夾(可以這麼結束了超過100篇)在我的Joomla網站批量導入查詢 - 的Joomla
看來,最簡單的方法是導入我的.txt在使用像我現有的MySQL:
LOAD DATA LOCAL INFILE 'example.txt' INTO TABLE example_table
但我怎麼能導入所有我的文件一次(批量導入)?
我用這個宏(在Visual Basic)導入所有的.TXT到Excel工作表:
'~~> Change path here
Const sPath As String = "C:\Users\Desktop\file\"
Sub Sample()
Dim wb As Workbook
Dim ws As Worksheet
Dim MyData As String, tmpData() As String, strData() As String
Dim strFileName As String
'~~> Your requirement is of 267 files of 1 line each but I created
'~~> an array big enough to to handle 1000 files
Dim ResultArray(1000, 3) As String
Dim i As Long, n As Long
Debug.Print "Process Started At : " & Now
n = 1
Set wb = ThisWorkbook
'~~> Change this to the relevant sheet
Set ws = wb.Sheets("Sheet1")
strFileName = Dir(sPath & "\*.txt")
'~~> Loop through folder to get the text files
Do While Len(strFileName) > 0
'~~> open the file in one go and read it into an array
Open sPath & "\" & strFileName For Binary As #1
MyData = Space$(LOF(1))
Get #1, , MyData
Close #1
strData() = Split(MyData, vbCrLf)
'~~> Collect the info in result array
For i = LBound(strData) To UBound(strData)
If Len(Trim(strData(i))) <> 0 Then
tmpData = Split(strData(i), ",")
ResultArray(n, 0) = Replace(tmpData(0), Chr(34), "")
ResultArray(n, 1) = Replace(tmpData(1), Chr(34), "")
ResultArray(n, 2) = Replace(tmpData(2), Chr(34), "")
ResultArray(n, 3) = Replace(tmpData(3), Chr(34), "")
n = n + 1
End If
Next i
'~~> Get next file
strFileName = Dir
Loop
'~~> Write the array to the Excel Sheet
ws.Range("A1").Resize(UBound(ResultArray), _
UBound(Application.Transpose(ResultArray))) = ResultArray
Debug.Print "Process ended At : " & Now
End Sub
所以,現在各行對應the.txt之一。
組織表中想要將.txt導入到表中的列。 例如,如果你想導入joomla中的文章,你應該是列: ID標題別名title_alias introtext全文狀態sectionid掩碼catid創建created_by created_by_alias修改modified_by checked_out checked_out_time publish_up publish_down圖像urls attribs版本parentid排序metakey metadesc訪問命中元數據
如果您希望mysql在上傳過程中自動增加id,請將id字段留空。
保存表爲.csv和與phpMyAdmin導入MySQL中(選擇要導入你.csv文件,然後選擇導入選項卡表。
!!如果你在你的內容有西文字符(如é,à...)將表格保存爲.xlsm,然後在Open Office Calc中打開它,然後將其保存爲.csv。在彈出的選擇中,保留相同的格式,然後保留西文字符。 're done!