CSV output question..

 

Hi,

Can anyone have this same problem ? I wrote some code to write string values to CSV. the formatting seems correct but when i actually open the csv file, values are not divided into columns but instead are shown like this:

ADS Securities LLC;EURUSD

the code:

//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

//--
string filename;
string tradelog="DailyStats";
string broker,symbol;
double dailyOpen,dailyHigh,dailyLow;
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
   //--
   initBasic();
   //--
   broker=AccountCompany();
   symbol=Symbol();
   //dailyOpen
   dailyHigh=MarketInfo(Symbol(),MODE_HIGH);
   dailyLow=MarketInfo(Symbol(),MODE_LOW);
   //--
   log(broker,symbol);
   //--   
//----
   return(0);
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
void initBasic()
{
//--
   //--
   Print("----------------------------  Script Begins --------------------------------");
   Print("Account #: "+ AccountNumber() +"|| Account Opening Balance:$" + DoubleToStr(AccountBalance(),2));   
   //---
   filename=tradelog+"-"+Symbol()+"-"+Month()+".csv";
   //--

   //--
//--
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
void log(string mydata1,string mydata2)
  {
   int myhandle;
   string time=TimeToStr(CurTime(),TIME_DATE|TIME_SECONDS);
   //display in terminal
   Print(" Time " + time + ": " + mydata1+";"+mydata2);
   
   // don't log anything if testing or if user doesn't want it
   //if(IsTesting()) return(0);
   //if(KillLogging) return(0);

   myhandle=FileOpen(filename, FILE_CSV|FILE_WRITE,';');
   if(myhandle>0){
      FileSeek(myhandle,0,SEEK_END);
      FileWrite(myhandle,mydata1,mydata2);
      FileClose(myhandle);
     }
  }
 
the output file is like this :
 
please kindly help. thanks!
 

Separater is a semi-colon. Excel sees a CSV type file as having its fields as seperated by a comma. If you changed the name of the to end with .TXT and then opened it with Excel you could then tell excel that the fields are seperated by a semi-colon.

 

work! just changed code to :

log(date+","+broker+","+symbol);

thanks!

Reason: