Forum Discussion

superuser's avatar
superuser
Occasional Contributor
13 years ago

How to fetch the Data table from server and save it in Excel sheet

Hi,

I am using SQL server. I am able to connect the database to TC how could i save the fetched data to excel sheet.

Immediate help would be much appreciated.

Thanks

Satish

3 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    The following "How-to" article gives a technique for writing to an excel sheet.



    http://smartbear.com/support/viewarticle/20878/



    While it does not give specifics of "Here's how you output SQL to Excel", if you have the SQL data, you can modify the code in this howto to output that excel to a spreadsheet.
  • superuser's avatar
    superuser
    Occasional Contributor
    Thanks Robert

    Although I know how to deal with excel in different ways. Here i have data table available in test complete and i want that data to be write in Excel sheet.

    Need further guidence.


  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Essentially, if you have an SQL table returned as an ADODB.RecordSet, you could simply do something like:







    That will effectively assign to the ExcelSheet at the indicated row and column the value of the current record at ColumnNo.  I would probably wrap that in a while loop to loop through the recordset while !RecordSet.EOF and doing a for loop within that on the columncount of the record set.  There's probably more than one way of doing it, though but that's how I'd end up doing it.



    So, in PseudoCode, it might look something like this.





    var Row=1;

    var LoopIndex

    while (!RecordSet.EOF)

    {

    for(LoopIndex = 1;LoopIndex<(RecordSet.ColumnCount); LoopIndex++)

    {

        ExcelSheet.Cells(Row, LoopIndex) = RecordSet.Fields(LoopIndex - 1).Value;

    }

    Row = Row + 1;

    RecordSet.MoveNext;

    }






    This is untested code so it will need tweaks and makes some assumptions but this is what I would do.  If this is not what you're looking for, could you be more specific in your need for guidance?