2013-10-16 37 views
0

我有一个包含100多个.txt文件巫婆我要导入的每个一文中的文件夹(可以这么结束了超过100篇)在我的Joomla网站批量导入查询 - 的Joomla

看来,最简单的方法是导入我的.txt在使用像我现有的MySQL:

LOAD DATA LOCAL INFILE 'example.txt' INTO TABLE example_table 

但我怎么能导入所有我的文件一次(批量导入)?

回答

0

我用这个宏(在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!