Jump to content

put text files in html table


Recommended Posts

Hi all,

I'm new with autoit and I trying to do a script that read from 3 txt files and put all rows in a html file as a table

for example:

file1.txt have this data

row 1

row 2

row 3

row 4

...

row n

file2.txt have this data:

row 1b

row 2b

row 3b

row 4b

....

row nb

file3.txt have this data:

row 1c

row 2c

row 3c

row 4c

....

row nc

my question is if is possible in autoit to put this 3 files in a final.html file in a table like this:

row 1 row 1b row 1c

row 2 row 2b row 2c

row 3 row 3b row 3c

row 4 row 4b row 4c

... ..... .......

row n row nb row nc

Can somebody help with this script? I'know how to read the files but I don't know how to join all together in a table

Tnx for your precious help and sorry for my bad english. :P

Edited by superbosu
Link to comment
Share on other sites

FileRead to read in the data from the 3 files, to their own strings

StringSplit to split by @crlf to their own arrays

I'd use XML doms to build the html table.

You will need to make lots of nodes (starting at the <table>, then make the 3 <tr>s, then loop through the above arrays, and add <td>s

http://www.w3schools.com/dom/dom_nodes_create.asp

edit: xml dom would probably be overkill, just concat strings with the proper html tag surrounding it.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Or StringRegExp? There are many ways to do this, just use the help file to find out how to use the functions presented to you in this thread.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

tnx for the quick reply all! I tring to read the 3 files with the array function and i created 3 arrays

_FileReadToArray("D:\file1.txt", $Array1)  

_FileReadToArray("D:\file2.txt", $Array2)
 
_FileReadToArray("D:\file3.txt", $Array3)

but I don't know how to use the loop of these 3 arrays to write in the new file concatenated rows like these:

$file = FileOpen("D:\final.txt", 1)
FileWriteLine($file,'<tr>')
    FileWriteLine($file,'<td>'& row 1 &'</td>')  ; how to put there the first value of the array1 ?
    FileWriteLine($file,'<td>'& row 1b &'</td>')   ; how to put there the first value of the array2 ?
    FileWriteLine($file,'<td>'& row 1c &'</td>')    ; how to put there the first value of the array3 ?
    FileWriteLine($file,'</tr>')

I have to use 3 arrays?

Link to comment
Share on other sites

Use a For loop:

For $i = 1 To UBound ($Array1) - 1
FileWriteLine($file,'<td>' & $Array1[$i] & '</td>')
Next

Make sure to wrap the for loop with your <TR> input

edit: wait a sec, you want the row to be a combo the nTH data point from each file? That's a little different

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

You can do something like this

Edit: I made it dynamic to pick up any number of files...just update the $sFolder to your directory that holds all the files

#include <array.au3>
#include <File.au3>
$sFolder = @DesktopDir & "\DataFiles\"
; Where above dir includes any number of files...example:
; $sFile1 = 'test1a' & @LF & 'test1b' & @LF & 'test1c' ... to however many
; $sFile2 = 'test2a' & @LF & 'test2b' & @LF & 'test2c' ... to however many
; $sFile3 = 'test3a' & @LF & 'test3b' & @LF & 'test3c' ... to however many
; $sFile4 = 'test4a' & @LF & 'test4b' & @LF & 'test4c' ... to however many
$aFiles = _FileListToArray($sFolder, "*", 1)
If $aFiles[0] > 0 Then
 Dim $aFileData[$aFiles[0]]
Else
 MsgBox(1,1,"No files and/or dir=[" & $sFolder & "]")
 Exit
EndIf
; Read in all the file's data
For $i = 1 To UBound ($aFiles) - 1
 Dim $aTemp[1]
 _FileReadToArray($sFolder & $aFiles[$i],$aTemp)
 $aFileData[$i-1] = $aTemp
Next
$iUbound1D = 0
; Get the second dimention needs
For $i = 0 To UBound ($aFileData) - 1
 $aTemp = $aFileData[$i]
 If UBound ($aTemp)-1 > $iUbound1D Then $iUbound1D = UBound ($aTemp)-1
Next
; create an array with proper bounds to house all data
Dim $aAllData[$iUbound1D][$aFiles[0]]
; Transpose the data of the files
For $i = 0 To UBound ($aAllData,2) - 1
 $aTemp = $aFileData[$i]
 For $j = 1 To UBound ($aTemp) - 1
  $aAllData[$j-1][$i] = $aTemp[$j]
 Next
Next
; Just a display of the array
_ArrayDisplay($aAllData)
ConsoleWrite("<HTML>" & @CRLF)
ConsoleWrite("<Table>" & @CRLF)
For $i = 0 To UBound ($aAllData) - 1
 ConsoleWrite("<tr>" & @CRLF)
 For $j = 0 To UBound ($aAllData, 2) - 1
  ConsoleWrite("<td>" & $aAllData[$i][$j] & "</td>" & @CRLF)
 Next
 ConsoleWrite("</tr>" & @CRLF)
Next
ConsoleWrite("</Table>" & @CRLF)
ConsoleWrite("</HTML>" & @CRLF)

output would be:

<HTML>

<Table>

<tr>

<td>test1a</td>

<td>test2a</td>

<td>test3a</td>

<td>test4a</td>

</tr>

<tr>

<td>test1b</td>

<td>test2b</td>

<td>test3b</td>

<td>test4b</td>

</tr>

<tr>

<td>test1c</td>

<td>test2c</td>

<td>test3c</td>

<td>test4c</td>

</tr>

<tr>

<td>test1d</td>

<td>test2d</td>

<td>test3d</td>

<td>test4d</td>

</tr>

<tr>

<td>test1e</td>

<td>test2e</td>

<td>test3e</td>

<td>test4e</td>

</tr>

</Table>

</HTML>

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

superbosu,

If you don't understand the basics of Arrays, then I suggest reading http://www.autoitscript.com/wiki/Arrays as this is a good start to understanding the basics.

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...