# Search the Community

Showing results for tags 'csv'.

• ### Search By Tags

Type tags separated by commas.

### Forums

• General
• Announcements and Site News
• AutoIt v3
• AutoIt Help and Support
• AutoIt Technical Discussion
• AutoIt Example Scripts
• Scripting and Development
• Developer General Discussion
• Language Specific Discussion
• Operating System Deployment
• Windows Client
• Windows Server
• Office

### Categories

• AutoIt Team
• Beta
• MVP
• AutoIt
• Automation
• Databases and web connections
• Data compression
• Encryption and hash
• Games
• Hardware
• Information gathering
• Internet protocol suite
• Maths
• Media
• PDF
• Security
• Social Media and other Website API
• Windows
• Scripting and Development
• Operating System Deployment
• Windows Client
• Windows Server
• Office

• Forum
• AutoIt

### Calendars

• Community Calendar

• 0 Replies

• 0 Reviews

• 0 Views

Found 18 results

1. ## filewritetoarray csv, but with commas in the location

hi all, reviewing the forum, this thread is applicable: I wanted to know if there is now a better way to do this? In essence, I load a tab delimited txt file into an array (works well). I used tab, as some fields in the original csv contains commas. However, I needed autoit to manipulate this array, and output it as a csv. IF my array contains items with a comma, without double quotes around the field, then how best do I get a csv out of this? My current workaround is to filewritefromarray tab delimited, then open it in excel and save as a csv. I will need to check this to see how the address fields behave that contain a comma. Any thoughts would be appreciated.
2. ## Write inputs values into Colum and Raw in CSV

Dear all, Can someone show me how to en hance the below function to write in CSV into column and rows the input values ? I am getting this result: I would like the result to be as this From A1:C1 is for headers From A2:C2 is for input Data Global Const $GUI_EVENT_CLOSE = -3$sDataFilePath = @ScriptDir & "\Records.csv" #region ### START Koda GUI section ### Form= $Form1 = GUICreate("Demo1: New Record", 580, 115)$Input1 = GUICtrlCreateInput("", 10, 30, 270, 21) $Input2 = GUICtrlCreateInput("", 300, 30, 270, 21)$Input3 = GUICtrlCreateInput("", 10, 80, 270, 21) $Label1 = GUICtrlCreateLabel("Name:", 10, 10, 35, 17)$Label2 = GUICtrlCreateLabel("ID:", 300, 10, 18, 17) $Label3 = GUICtrlCreateLabel("Phone No:", 10, 60, 55, 17)$Button1 = GUICtrlCreateButton("Save to CSV", 450, 70, 120, 30) GUISetState(@SW_SHOW) #endregion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch$nMsg Case $GUI_EVENT_CLOSE Exit Case$Button1 _ExportData() MsgBox(64, @ScriptName, "Record Saved.") EndSwitch WEnd Func _ExportData() If Not FileExists($sDataFilePath) Then FileWriteLine($sDataFilePath, "Name;ID;Phone No.;") EndIf For $i =$Input1 To $Input3 FileWrite($sDataFilePath, GUICtrlRead($i) & ";") Next FileWriteLine($sDataFilePath, "") EndFunc ;==>_ExportData May be Excel UDF has be to be added but I can manage that my self Thank you in advance

4. ## Reading CSV with mixed delimiters?

I have a csv file with delimiters "," and @CRLF After trying several different examples (simple ones!) I still haven't resolved an answer #include <Array.au3> #include <File.au3> ;#include "ArrayMultiColSort.au3" Global $BatchDir = "C:\ncat\" FileChangeDir($BatchDir) $sFile = "mod1.csv" ; Read file into a 2D array Global$aArray _FileReadToArray($sFile,$aArray, $FRTA_NOCOUNT, ",") ; And here it is _ArrayDisplay($aArray, "Original", Default, 8) Firstly it throws a MsgBox error "No array variable passed to function" _ArrayDisplay(), so no displayed data Second and probably more important how do I get _FileReadToArray() to split the imported array[][] into rows and columns? I tried "," & @CRLF without success.
5. ## Convert PDF to CSV, and working with it

Good morning guys I'd like to know if there is a way to convert a PDF in CSV or, eventually, in TXT, in order to read from it, like a database... I have a PDF and I think ( I dind't search a lot on the forum ) with AutoIt, but I'd like work with Excel styles... Does anyone know a good program which convert PDF to CSV? PS: the PDF file is 5 MB, and it contains 439 pages... Thanks everyone for the help

12. ## Out of memory error 270MB csv sorting arrays and modifying data

Good Morning All, I have an application that takes csv files - sorts, finds, and tries to make it's own individual csv files... Everything runs smooth until I get to the "_myCSV2DCreator" on extremely large CSV files... like 200+ MB with 100,000 + lines. I get an "out of memory" error from AutoIT when I convert the 2D array to a CSV file using this function "_myCSV2DCreator". I get an "out of memory" error when running the _ArrayInsert($aNewArray, "0",$columnheaders, "", ","). I believe it takes whatever array is in memory and doubles it's size as it writes just one row of data. Any ideas on how to get around this? I'm stumped... Func GEN_SeparateOutCSV03() SendAndLog("GEN_SeparateOutCSV03", $tempzipdir & '\' &$LogFileName01, True) SplashTextOn($ProgramTitle, 'Separating CSV files from data...', 400, 60, (@DesktopWidth / 2) - 200, 10, "", "") Sleep ($sleeptime) $array01 =$twoDarray $aUniqueHostname = _ArrayUnique ($array01, 1) ;_ArrayDisplay ($aUniqueHostname, "UniqueHostname ") For$i01 = Ubound($aUniqueHostname) - 1 to 0 Step - 1 For$j01 = Ubound($array01) - 1 to 0 Step - 1 If$array01[$j01][1] ==$aUniqueHostname[$i01] and StringRegExp($array01[$j01][5], "MY_VALUE.txt") then ;MsgBox(0, "Computer and MY_VALUE.txt",$aUniqueHostname[$i01] & " : " &$array01[$j01][5])$FileName01 = $tempzipdir & "\" &$array01[$j01][3] & "_" &$aUniqueHostname[$i01] & "_" &$array01[$j01][2] & ".csv" ; MsgBox(0, "File Name",$FileName01) Local $avResult = _ArrayFindAll($array01, $aUniqueHostname[$i01], 0, 0, 0, 0, 1) ;_ArrayDisplay($avResult, "$avResult") Local $aNewArray = "" Local$aNewArray[UBound($avResult)][UBound($array01, 2)] SplashTextOn($ProgramTitle, 'Loop - Array search for unique hostname', 400, 60, (@DesktopWidth / 2) - 200, 10, "", "") Sleep ($sleeptime) For $i = 0 To UBound($avResult) -1 ; Loop through the returned index numbers. For $j = 0 To UBound($array01, 2) -1 ; Loop through each of the columns. $aNewArray[$i][$j] =$array01 [$avResult[$i]] [$j] ; Populate the new array. Next Next SplashTextOn($ProgramTitle, 'Loop - Column header modification', 400, 60, (@DesktopWidth / 2) - 200, 10, "", "") Sleep ($sleeptime) ;_ArrayDisplay($twoDarray, "Removed 'User-defined Rules:' in column 3") ;_ArrayInsert($aNewArray, "0",$columnheaders, "", ",") _ArrayInsert($aNewArray, "0",$columnheaders, "", ",") ;_ArrayDisplay($aNewArray, "Inserted 0") ;MsgBox (0, "Out of the loop", "Out of the loop - File Write From Array") _myCSV2DCreator($tempzipdir & "\beta_" & $array01[$j01][3] & "_" & $aUniqueHostname[$i01] & "_" & $array01[$j01][2] & ".csv", $aNewArray, True) ;_FileWriteFromArray($FileName01, $aNewArray) ExitLoop EndIf Next Next SplashTextOn($ProgramTitle, 'Please wait a moment...', 400, 60, (@DesktopWidth / 2) - 200, 10, "", "") Sleep ($sleeptime) SplashOff() SendAndLog("GEN_SeparateOutCSV03 - Okay",$tempzipdir & '\' & $LogFileName01, True) MsgBox(262192,$ProgramTitle, "All files stored here:" & @CR & @CR & $tempzipdir) SendAndLog("Final Message Box - Exit Okay",$tempzipdir & '\' & $LogFileName01, True) Exit EndFunc Func _myCSV2DCreator($hFile, $avArray,$bEraseCreate = True) SplashTextOn($ProgramTitle, '2D to CSV file create', 400, 60, (@DesktopWidth / 2) - 200, 10, "", "") Sleep ($sleeptime) If $bEraseCreate Then FileClose(FileOpen($hFile, 2)) Local $sHoldString = "" For$x = 0 To UBound($avArray) - 1 For$i = 0 To UBound($avArray, 2) - 1$sHoldString &= $avArray[$x][$i] & "," Next$sHoldString &= @CRLF Next Return FileWrite($hFile, StringTrimRight($sHoldString, 3)) EndFunc (out of memory) Is there a better method / solution that I should be using? Thanks Everyone!

17. ## Regexp question

Pleas help me , I am converting HTML to csv using the command stringreg exp. In the example belot, the field Help is not detected. How to change my regexp ? #include <Array.au3> $sString = "<td NOWRAP>cel1</td><td NOWRAP>cel2</td><td NOWRAP>cel3</td><td>Help</td><td NOWRAP>cel4</td>"$aReturn = StringRegExp($sString, '(?s)(?i)<td NOWRAP>(.*?)</td>', 3) _ArrayDisplay($aReturn) thnx.
18. ## Help optimizing CSV conversion

Hi all, I need to convert a .csv file that after conversion will fill an array for futher usage. function used/not used: stringsplit(), stringregexp(),stringinstr(), stringreplace() I know the best way is to use stringsplit given a delimiter (,). But this is not possible here since: Here is some lines fo the .csv Game Title,Quantity,For Sale,Platform,Rating,Number,New After Life,5,2,PC,PG1,23332,Yes Max Payne,4,0,Wii,PG3,109,No Fifa 2009,11,2,DS,PG2,976,Yes "Hellgate, London",3,2,PC,PG2,112,No Logitech Mouse,12,4,mouse, ,No Pinball 2010,1,1,PS3,PG1,065,No As you can see: "Hellgate, London",3,2,PC,PG2,112,No will not work with stringsplit() since the "," it's inside the name of the object Logitech Mouse,12,4,mouse, ,No Here I have blank spaces between "," and the field "Rating" is missing. This is due to the .csv format. When Platform <> PC,Wii,DS,PS1,PS2,PS3,XB,X3 then I need to set Platform = Hardware and Rating = the value found in place of platform (in this case Platform = N, Rating = Hardware) Once this is finished and I have my array built, I need to add 2 more columns to it. I get the columns _arraysearch()ing between the just created array and another file (.xlm). If i found the item I need I add the prices, if not, skip. So now I use this code (working): $exportfile = @ScriptDir & "\filelist.csv" Dim$mydb Global $file2ftp = @TempDir & "\temp2db.txt" Dim$csv_list[1][7] Global $rows Func _exp2db_x() Local$iCounter = 0, $array2db[10000] Local$user2db Local $k = 0 Dim$csv_array _FileReadToArray($exportfile,$csv_array) _FileReadToArray($price_file,$mydb) _ArraySort($mydb)$begin = TimerInit() For $i = 1 To UBound($csv_array) - 1 If StringInStr($csv_array[$i], ", ,") Then ; i'm looking for a ", ," in lines $string = StringReplace($csv_array[$i], ", ,", ",@,", 1) ; if found I change it Else$string = $csv_array[$i] EndIf If StringInStr($string, ", ") Then$string = StringReplace($string, ", ", "^", 1); If I find "," inside the name I need to change it$name_s = _StringBetween($string, "", ",")$name = _cleanfordb($name_s[0]) ; Need to reconvert name with "," and remove " if present$string = StringReplace($string, ",", "*", 1) ; since I can't use stringsplit() i need different separators$string = StringReplace($string, ",", "#", 1) ; since I can't use stringsplit() i need different separators$forsale = StringRegExp($string, "#(.*?),", 1) ; for sale If$forsale[0] > 0 Then $k +=1$string = StringReplace($string, ",", "_", 1) ; since I can't use stringsplit() i need different separators$platform = StringRegExp($string, "_(.*?),", 1) ;platform$rating = StringRegExp($string, ",(.*?),", 1) ;rating If$platform[0] <> "PC" And $platform[0] <> "DS" And$platform[0] <> "Wii" And $platform[0] <> "XB" And$platform[0] <> "X3" And $platform[0] <> "Junk" Then$rating[0] = "Hardware" ; fixed value $platform[0] = "N" ; fixed value EndIf If$platform[0] = "Junk" Then $rating[0] =$platform[0] $platform[0] = "None" EndIf$new = StringRight($string, 2) ; just lasr 2 chars for last item in row If$new = "es" Then $new = "Yes" ReDim$csv_list[$k + 1][7]$csv_list[$k][0] =$name $csv_list[$k][1] = $platform[0] If$rating[0] <> "@" Then $csv_list[$k][2] = $rating[0]$csv_list[$k][3] =$new $csv_list[$k][4] = $forsale[0] ; now I build the string to check vs the main db (I need a partial search)$string = "<z:row c0='" & _normalize_db($csv_list[$k][0]) & "' Rating='" & $csv_list[$k][2] & "' New='" & $csv_list[$k][3] & "' Platform='" & $csv_list[$k][1] ; _normalize_db just change exotic chars into xml_readable sequence $check_string = _ArraySearch($mydb, $string, 39, UBound($mydb), 0, 1) ; first 38 lines is the xml header so I can skip If $check_string <> -1 Then$csv_list[$k][5] = _sellp($check_string) ; I can have 2 possible prices in main DB, best price and street price. If bestprice = 0 I'll use StreetPrice EndIf Next ConsoleWrite("Time to complete: " & TimerDiff($begin) & @CRLF) EndFunc ;==>_exp2db_x Func _cleanfordb($k) If StringInStr($k, "^") Then$k = StringReplace($k, "^", ", ") ; ^ If StringInStr($k, '"') Then $k = StringMid($k, 2, StringLen($k) - 2) Return$k EndFunc ;==>_cleanfordb Func _sellp($cc)$p = StringRegExp($mydb[$cc], "c6='(.*?)' c7",1) If $p[0] = 0 Then$p = StringRegExp($mydb[$cc], "c7='(.*?)'/>",1) Return \$p[0] EndFunc ;==>_sellp Time to complete is 137,000ms, 2'17'', for 1,243 lines of csv (and 30,000 lines of main DB) I need to work, during normal phases, with 10,000 to 30,000 lines so time to complete will be really too high. I ask you, great programmers, if there is a way to optimize this routine (i'm not able to modify the csv since I get it this way from the Store Application Thanks! M.
×

• Wiki

• Back

• Git