rkskaras Posted August 5, 2019 Share Posted August 5, 2019 (edited) Hello there, Is it possible to copy each line of the text file and put it into a table in html file ? Example File1.txt : line1 line2 line3 line4 and convert it to HTML File like this <table> <tr><td>line1</td></tr> <tr><td>line2</td></tr> <tr><td>line3</td></tr> <tr><td>line4</td></tr> </table> Thank you. Edited August 5, 2019 by rkskaras Link to comment Share on other sites More sharing options...
water Posted August 5, 2019 Share Posted August 5, 2019 Sure. Use FileReadLine, FileWriteLine and the concatenation operator (&). My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
rkskaras Posted August 5, 2019 Author Share Posted August 5, 2019 Thank you but what to do when i am generating a text file from test tool and the number of lines can be different ? Link to comment Share on other sites More sharing options...
water Posted August 5, 2019 Share Posted August 5, 2019 Do FileReadLine in a loop until you get an error. Then exit the loop. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
rkskaras Posted August 5, 2019 Author Share Posted August 5, 2019 @water i have done a script but i got a issue that output file html.html is empty i cant fix it. #include <file.au3> $file = FileOpen(@ScriptDir & "\test.txt") $html = FileOpen(@ScriptDir & "\html.html", 1) For $i = 1 to _FileCountLines($file) $line = FileReadLine($file, $i) _FileWriteToLine($html, $i, $line, 1 ) Next Link to comment Share on other sites More sharing options...
Danp2 Posted August 5, 2019 Share Posted August 5, 2019 From the remarks section of the help file entry for _FileWriteToLine -- Quote By default, the function will return an error if the line does not exist in the file, but setting the $bFill parameter to True will force it will add blank lines to pad the file to a size allowing the line to be written. rkskaras 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
water Posted August 5, 2019 Share Posted August 5, 2019 (edited) You are a bit overcomplicating things. I suggest (untested): #include <FileConstants.au3> $hInfile = FileOpen(@ScriptDir & "\test.txt") $hOutfile = FileOpen(@ScriptDir & "\test.html", $FO_OVERWRITE) FileWriteLine($hOutFile, "<html><Body><table>") While 1 $sInLine = FileReadLine($hInfile) If @error = -1 Then ExitLoop ; EOF has been reached FileWriteLine($hOutfile, "<tr><td>" & $sInline & "</td></tr>") WEnd FileWriteLine($hOutFile, "</table></Body></html>") FileClose(@ScriptDir & "\test.txt") FileClose(@ScriptDir & "\test.html") Edited August 5, 2019 by water Next/WEnd error fixed rkskaras 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
rkskaras Posted August 5, 2019 Author Share Posted August 5, 2019 @water Your script works you had just one error there should be WEND not NEXT but after after 9 lines the <tr> tag duplicates like this <tr><tr><td>line10</tr></tr></td>. Link to comment Share on other sites More sharing options...
rkskaras Posted August 5, 2019 Author Share Posted August 5, 2019 @water Ouch Sorry It works completly fine Thank you very much. The thing was in my test.text file somehow my lanes were filled with <td> and </td> Link to comment Share on other sites More sharing options...
water Posted August 5, 2019 Share Posted August 5, 2019 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Nine Posted August 5, 2019 Share Posted August 5, 2019 The file closes are incorrect. It should be : FileClose($hInfile) FileClose($hOutfile) “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
water Posted August 5, 2019 Share Posted August 5, 2019 OMG, so many bugs in just a few lines of code 😥 Nine 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
jchd Posted August 5, 2019 Share Posted August 5, 2019 (edited) 3 hours ago, water said: so many bugs in just a few lines of code That's what results from monkeys been given keyboards 🐵🐵🐵 Of course I count as one in the hord. Edited August 5, 2019 by jchd This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
water Posted August 5, 2019 Share Posted August 5, 2019 I'm number two. So the question now is: who is number 3? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
mikell Posted August 5, 2019 Share Posted August 5, 2019 $txt = "line1" & @crlf & _ "line2" & @crlf & _ @crlf & _ "line3" & @crlf & _ "line4" $res = "<html><Body><table>" & @crlf & StringRegExpReplace($txt, '(?m)^(.*)\R?', "<tr><td>$1</td></tr>" & @crlf ) & "</table></Body></html>" Msgbox(0,"", $res) Link to comment Share on other sites More sharing options...
Nine Posted August 5, 2019 Share Posted August 5, 2019 5 hours ago, water said: I'm number two. So the question now is: who is number 3? I am fine I am number 9... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
water Posted August 6, 2019 Share Posted August 6, 2019 😂 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Deye Posted August 6, 2019 Share Posted August 6, 2019 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now