AutoHotkey Community

It is currently May 27th, 2012, 12:45 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 45 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject:
PostPosted: January 9th, 2012, 7:56 pm 
ops teste.csv input is> 1111;1111
sorry


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 9th, 2012, 8:00 pm 
Your errors marked in red
Code:
CSV_Load("teste.csv","AA",",")
CSV_ModifyCell("AA",7777,1,1)
CSV_ModifyCell("AA",7777,1,2)
CSV_Save("teste.csv","AA",1)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 9th, 2012, 9:31 pm 
Offline

Joined: January 9th, 2012, 7:58 pm
Posts: 2
Location: Brazil
Thank u for answer so fast.
Code:
CSV_Load("teste.csv","AA",";")
CSV_ModifyCell("AA",2020,1,1)
CSV_Save("teste.csv","AA",1)

when it modify only one cell, the script delete the last row
csv in: 1010;1010
csv out: 2020


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 9th, 2012, 10:03 pm 
I can not replicate your problem with this test script
Code:
f= ; create test file
(join`r`n
1111;1111
)
filedelete,f.csv
fileappend,%f%,teste.csv

CSV_Load("teste.csv is OK","AA",";")
CSV_ModifyCell("AA",2020,1,1)
MsgBox % CSV_ReadCell("AA",1,1) ":" CSV_ReadCell("AA",1,2)
CSV_Save("teste.csv","AA",1)

teste.csv wrote:
2020;1111


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 9th, 2012, 10:04 pm 
That should be
Code:
CSV_Load("teste.csv","AA",";")
of course


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 9th, 2012, 11:41 pm 
Offline

Joined: January 9th, 2012, 7:58 pm
Posts: 2
Location: Brazil
Ok, it's work, thank u


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 11th, 2012, 2:07 pm 
Offline

Joined: February 2nd, 2011, 9:36 am
Posts: 28
Some regex sugestion to improve CSV load:

pre filter EOL inside encapsulations (in this change `r`n or `n inside encapsulation e to `r )
Code:
String = a,b,c`r`nd,e,f,,"g`r`n",h`r`nB,`n"C`nC",D
e:= """" ; the encapsulation character (tipical ")

; change `r`n or `n inside encapsulation e to `r
RegExNeedle:= "\n(?=[^" e "]*" e "([^" e "]*" e "[^" e "]*" e ")*([^" e "]*)\z)"
String := RegExReplace(String, RegExNeedle , "" )

StringReplace,String, String,`r,@,All ;only for see msgbox
msgbox, : %String% :


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 11th, 2012, 2:22 pm 
It's a shame kdoske doesn't seem to be around to include the fixes.
But perhaps someone will prepare a new AutoHotkey v2 compatible version when v2 is out of alpha ;-)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 11th, 2012, 9:47 pm 
How can i get this to not break when the csv has a new line in it?
One of my cells contains this:
Code:
<!--URLs OF IMAGES USED IN THIS LISTING

photo1:
url1
...

But alls i get is this from the cell.
Code:
<!--URLs OF IMAGES USED IN THIS LISTING


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2012, 6:50 pm 
There seems to be a bug in CSV_Load
It wont detect the correct number of colums. first it loops the correct amount, then it loops and sets it back to 1, at least with my csv. i corrected it with this.

Code:
CSV_Load(FileName, CSV_Identifier="", Delimiter="`,")
{
  Local Row
  Local Col
  temp :=  %CSV_Identifier%CSVFile
  FileRead, temp, %FileName%
  StringReplace, temp, temp, `r`n`r`n, `r`n, all   ;Remove all blank lines from the CSV file
  loopnumber = 1
  Loop, Parse, temp, `n, `r
  {
    if loopnumber = 1
    Col := ReturnDSVArray(A_LoopField, CSV_Identifier . "CSV_Row" . A_Index . "_Col", Delimiter)
    loopnumber ++
    Row := A_Index
    Loop, Parse, A_LoopReadLine, %Delimiter%
    {
      Col := A_Index
      %CSV_Identifier%CSV_Row%Row%_Col%Col% := A_LoopField
    }
  }
  %CSV_Identifier%CSV_TotalRows := Row
  %CSV_Identifier%CSV_TotalCols := Col
  %CSV_Identifier%CSV_Delimiter := Delimiter
  SplitPath, FileName, %CSV_Identifier%CSV_FileName, %CSV_Identifier%CSV_Path

  IfNotInString, FileName, `\
  {
    %CSV_Identifier%CSV_FileName := FileName
    %CSV_Identifier%CSV_Path := A_ScriptDir
  }
  %CSV_Identifier%CSV_FileNamePath := %CSV_Identifier%CSV_Path . "\" . %CSV_Identifier%CSV_FileName
}


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2012, 8:19 pm 
You can (must really) remove the inner loop the ReturnDSVArray already does what the inner loop does so no need for the repetition.
Code:
Loop, Parse, temp, `n, `r
  {
    if loopnumber = 1
    Col := ReturnDSVArray(A_LoopField, CSV_Identifier . "CSV_Row" . A_Index . "_Col", Delimiter)
    loopnumber ++
    Row := A_Index
;    Loop, Parse, A_LoopReadLine, %Delimiter% ; don't need this, comment or remove
;    {
;      Col := A_Index
;      %CSV_Identifier%CSV_Row%Row%_Col%Col% := A_LoopField
    }
  }


CSV_Load / ReturnDSVArray also returns columns 1 if the very last field in the last row isn't closed properly, either if there is a missing " in case it needs one OR if is actually an empty line.


Report this post
Top
  
Reply with quote  
 Post subject: Re: CSV Library [lib]
PostPosted: May 11th, 2012, 6:19 pm 
Offline

Joined: November 3rd, 2010, 7:54 pm
Posts: 2
Location: Rio de Janeiro
i trying to save the loaded csv file back in the same file that it was loaded from, but it only save the first column,when i call the number of columns it returns only 1 even though i can read from the other columns. i know its probably a noob mistake but i tryed and i can't solve it, my first time posting,sorry if i did something wrong


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: CSV Library [lib]
PostPosted: May 11th, 2012, 6:24 pm 
Check the post above yours and read the last remark. Your last line in your CSV file is probably either an empty line or it is not closed of properly with an " if there actually should be one. Fix that in your CSV and it will work. Also note the couple of bug fixes posted a few pages back.


Report this post
Top
  
Reply with quote  
 Post subject: Re: CSV Library [lib]
PostPosted: May 11th, 2012, 6:41 pm 
Offline

Joined: November 3rd, 2010, 7:54 pm
Posts: 2
Location: Rio de Janeiro
thx for the fast reply,i will check the others posts later, but for now i just wanted to know if theres some way to save exactly what its load in the CSV_load, because my .csv will have empty lines in some cases, why can't i save what im reading,i just need to modify some cells and save it again no fancy formating,do i need to put something in the end of the last data. like dog;cat";" i will check the other posts later but i need a quick solution for now,just don't have much time to finish the code, thx in advance.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: CSV Library [lib]
PostPosted: May 11th, 2012, 10:12 pm 
YOu can't save because it is a bug of the csv lib posted in the first post of this thread. So there is no quick solution. Kdoske left the forum (at least he hast returned in the last 18 months even though I pm-ed him). You can try the TSV library http://www.autohotkey.net/~faqbot/faq.html#csv which can handle CSV as well.


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 45 posts ]  Go to page Previous  1, 2, 3

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bon, Google Feedfetcher, maul.esel, Yahoo [Bot] and 17 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group