2014-07-21 242 views
-1

我有一個簡單的任務,但我不知道VB。我有excel文件的結構是這樣的:將Excel錶轉換爲文本文件

ID | File name | Title 
------------------------------- 
1 | 1.mim | ABC Song 
2 | 2.mim | Five little monkeys 
3 | 3.mim | Counting bananas 

我需要生成excel文件在下面的表格文本輸出:

<li> 
    <a href="#" onclick="window.plugins.videoPlayer.play('file:///storage/emulated/0/nepal/%id%.mim');"> 
     <img src="img/radiologo/%id%.jpg" alt="" /> 
     <div class="channel-info"> 
      <h1>%Title%</h1> 
     </div> 
    </a> 
</li> 

你能幫我這個請:)

回答

0

OK解決了,這裏是代碼如下

Sub main() 
    Dim fs As Object, f As Object, i As Integer 
    Set fs = CreateObject("Scripting.FileSystemObject") 
    Call createFile(f, fs, "Z:\Tablets\output.html") 
    i = 2 
    While Cells(i, 1) <> "" 
     Call writeTab(f, 2, "<li>") 
     Call writeTab(f, 3, "<a href=""#"" onclick=""window.plugins.videoPlayer.play('file:///storage/emulated/0/nepal/" & Cells(i, 1) & ".mim');"">") 
     Call writeTab(f, 4, "<img src=""img/icons/" & Cells(i, 1) & ".jpg"" alt=""""  />") 
     Call writeTab(f, 4, "<div class=""channel-info"">") 
     Call writeTab(f, 5, "<h1>" & Cells(i, 4) & "</h1>") 
     Call writeTab(f, 4, "</div>") 
     Call writeTab(f, 3, "</a>") 
     Call writeTab(f, 2, "</li>") 
     i = i + 1 
    Wend 
    Set f = Nothing: Set fs = Nothing 
End Sub 
Sub createFile(fileObject As Object, fso As Object, fileName As String, Optional utf16 As Integer = 0) 

    Set fileObject = fso.opentextfile(fileName, 2, True, utf16) 
End Sub 

Sub writeTab(f As Object, ByVal t As Integer, ByVal s As String) 

    Dim tabString As String, i As Integer 
    For i = 1 To t 
     tabString = tabString & Chr(9) 
    Next i 
    f.writeline tabString & s 
End Sub