Jump to content
Sign in to follow this  
MarcusD

Split Text file by InvoiceNo

Recommended Posts

Good morning :)

 

I need you  help / advise. I got a flat CSV invoice file like:

INVNo|ProductName|Description|PRICE

17146330|PRODUCT A|Description|29.30
17146330|PRODUCT B|Description|50.30
17147635|PRODUCT B|Description|50.30
17147635|PRODUCT C|Description|100.00
17147698|PRODUCT D|Description|50.00
17147887|PRODUCT C|Description|100.00
17147887|PRODUCT D|Description|50.00
17149649|PRODUCT A|Description|29.30
17149649|PRODUCT A|Description|29.30
 

For each Invoice No i need a new CSV file - Do you have any idea how this might work?

 

Thanks for helping !

 

Marcus

 

Share this post


Link to post
Share on other sites

Hi @Marcus:)
Take a look at StringSplit(), _FileReadToArray(), and _FileCreate() functions in the Help file ;)


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites

@MarcusD
It depends...

How is it updated this file?
Does it always have the same name?
Where is/are stored the last information (invoice) ? 
Tell us more information, so we can see how we can help you :)


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites

Hi,

i got the invoice (flat) file on a daily base and the structure of the file is fix. 

My question is, how is the best way to regonize a new invoice no .

 

Marcus

Share this post


Link to post
Share on other sites

@MarcusD
If the invoice is added at the end of the file, you could store somewhere the number of rows stored in the file, and with a timer, you could check if there are more rows than there were, your file has been updated.

This is a solution of many :)


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
9 minutes ago, MarcusD said:

that means i got every day a complete new file...

So, your need is to... ?


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites

You just need something like:

#include <Array.au3>
#include <File.au3>

Global $sTargetDir = @ScriptDir & "\Invoices"
    If FileExists($sTargetDir) = 0 Then DirCreate($sTargetDir)
Global $sSource = @ScriptDir & "\Flat.csv"
Global $aSource
_FileReadToArray($sSource, $aSource, 1, "|")
    If @error Then Exit
For $i = 1 To $aSource[0][0]
    FileWrite($sTargetDir & "\" & $aSource[$i][0] & ".csv", _ArrayToString($aSource, ",", $i, $i) & @CRLF)
Next

 

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...