[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4688: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4690: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4691: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4692: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
Poco Forums • View topic - writing a CSV file

writing a CSV file

Scripting questions and ideas

Moderators: Eric, Tomas, robin, Michael

writing a CSV file

Postby ronenya » Thu Dec 23, 2004 11:45 am

Hello,

I want to do some parsing on the contect an incoming message and used save the parsed information to a CSV that as a second step will be imported to an excel sheet. I could find anything else but doing it this way:

Code: Select all
...
....
....
CreateMessage %auctionDetails
AppendToFile true
Set $auctionLine $artikelNummerLine
AddStrings $auctionLine "," $kundenNameLine "," $strasseLine "," $ortLine
AssignBody %auctionDetails $auctionLine
SaveMessage %auctionDetails "auctions.log"
Return


The problems ist that it is saved as a message with all the headers and the Makro in excel fails. I thought of writing a batch which will accept all the parse information as paramters and will falsh it into a file., but I would prefer a Poco intern solution if exists.

Merry Christmas to ones who celebrate.

Ronen
Try to live every day as if it was the last day of your life.
ronenya
Drop-in Visitor
 
Posts: 5
Joined: Wed Sep 29, 2004 8:27 pm

Postby Michael » Thu Dec 23, 2004 12:04 pm

A very Merry Christmas to you and yours Ronen.

Try using the AppendBody command to create multi-line variables and then convert this to CSV format using the WriteCSV command. Use the SaveBody command to save the file as a text file.
Michael
Moderator
 
Posts: 866
Joined: Mon Jul 26, 2004 12:14 pm
Location: Victoria BC, Canada

Postby Pete » Mon Jan 17, 2005 2:04 am

Hi Ronen,

This continues a brief offline discussion that we had about your question. Both of the following scripts read the body of the message (without headers or attachments) and write the contents to a disk file.

This first example simply appends the entire body to the disk file:
Code: Select all
Set $OnErrorMessage ""
AddStrings $OnErrorMessage "Error in " $pocoScriptName
Set $OnErrorGoTo "POCO_ERROR"

ReadBody $body %message
Trim $body
If $body = "" Then DONE
AppendToFile True
SaveBody $body "auctions.log"

:DONE
Exit

:POCO_ERROR
Exit



This second example shows how to process the body one line at a time and then append the result to the disk file. Note that all processing is performed in memory and the script doesn't write anything to the disk file until the very end:
Code: Select all
Set $OnErrorMessage ""
AddStrings $OnErrorMessage "Error in " $pocoScriptName
Set $OnErrorGoTo "POCO_ERROR"

ReadBody $body %message
Trim $body
LineCount #totalLines $body
If #totalLines = 0 Then DONE
Set $auctionDetails ""
Set #i -1

:LOOP
Inc #i
If #i = #totalLines Then FINISH
GetLine $line #index $body
{ parse the line here }
AddStrings $auctionDetails $line "\n"
Goto LOOP

:FINISH
AppendToFile True
SaveBody $auctionDetails "auctions.log"

:DONE
Exit

:POCO_ERROR
Exit


Neither of these scripts address using CSV, but I don't think that anyone can help you with this portion unless you show us an example email message and tell us exactly how you want to change its content before writing it to the disk file.
Pete
 


Return to PocoScript Help and How-To

Who is online

Users browsing this forum: No registered users and 1 guest

cron