Forum Discussion

Nimeshika's avatar
Nimeshika
Contributor
11 years ago

Write each query output to new csv sheets

Hello,

          I am able to fetch the query results and save to new CSV file using jscript. But I need to save the query results to a new sheet each time in the same CSV  File



This is the current Jscript I have used to write to a CSV file:






 function CreatingTextFile(file_name,path)


  {


    if (aqFile.Create(path+file_name+".csv") == 0)


    {


     Log.Message("The file "+file_name+".csv is created successfully.");


    }


    else 


    {


     Log.Error("The file was not created.");


    }


  }


 


  function WritingToTextFile(file_name,path,data)


  { 


   aqFile.WriteToTextFile(path+file_name+".csv", data+",", aqFile.ctUTF8);    


  }





I want to modify the above code such that I can write data to The CSV file and in  any sheet as required.



Kindly guide me for it.



Thank You in advance,

Regards,

Nimeshika

  • OK, let me put it differently. CSV files have only 1 sheet. They can't have multiple sheets.

    If you create a multi-sheet workbook in Excel and then try to save it as a CSV file, you'll see a warning like this:



    ---------------------------------------------------------------------------

    The selected file type does not support workbooks that contain multiple sheets.



    * To save only the active sheet, click OK.

    * To save all sheets, save them individually using a different file name for each, or choose a file type that supports multiple sheets.

    ---------------------------------------------------------------------------



    If you need a multi-sheet data file, use the Excel file format - XLS or XLSX. Here's an example of how to write to Excel files:

    Write data to MS Excel
  • Hi Nimeshika,



    CSV files are plain text files and don't have sheets. You need to create separate CSV files for different data tables.



    Or did you mean to use Excel files (.xls or .xlsx)?
  • Hi Helen,

             When we create a .csv file, on opening it is similar to an excel file. The only difference is in the file extension that is instead .xlsx it will be .csv . This is what I know about it. 

             So I wanted new data to be written on different sheets of .csv file.





    Regards,

       Nimeshika