Forum Discussion
3 Replies
Sort By
- tristaanogreEsteemed ContributorThe 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. - superuserOccasional ContributorThanks 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. - tristaanogreEsteemed ContributorEssentially, 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?