Jump to content

filewritetoarray csv, but with commas in the location


 Share

Recommended Posts

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.

 

Link to comment
Share on other sites

@MrCheese
A very raw solution:

Global $strTabFile = @ScriptDir & "\Tab.txt", _
       $strCSVFile = @ScriptDir & "\CSVFile.csv", _
       $arrFileContent


_FileReadToArray($strTabFile, $arrFileContent, $FRTA_NOCOUNT, @TAB)
_ArrayDisplay($arrFileContent, "Before formatting:")
FormatCSV($arrFileContent)
_ArrayDisplay($arrFileContent, "After formatting:")
_FileWriteFromArray($strCSVFile, $arrFileContent, Default, Default, ",")


Func FormatCSV(ByRef $arrArray)

    For $i = 0 To UBound($arrArray) - 1 Step 1
        For $j = 0 To UBound($arrArray, $UBOUND_COLUMNS) - 1 Step 1
            $arrArray[$i][$j] = '"' & $arrArray[$i][$j] & '"'
        Next
    Next

EndFunc

 

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

I use the CSV.au3 written by ProgAnd:

 

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

Thanks @FrancescoDiMuro

and thanks @water

so i see that my problem that I need to attend to first is initially loading it.

I need to load it correctly as a CSV, so I can export it accordingly.

The CSV.au3 that you've linked to does everything perfectly; I've kept my current import process (as its scripted out of sql already), and just utilised this as an export. Thanks 

 

Edited by MrCheese
Link to comment
Share on other sites

:) 

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

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

×
×
  • Create New...