BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Exception in exporting the report to excel sheet

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (ActiveX)
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Mon Feb 12, 2007 7:07 pm    Post subject: Exception in exporting the report to excel sheet Reply with quote



Hi,

I want to export the report as xls file. For doing so I have used the
TExcelApplication object on my form.The code is as follows:

_WorkbookPtr pWorkBook;
_WorksheetPtr pWorkSheet;

Excel_2k::RangePtr pRange,pCells;
Excel_2k::WorkbooksPtr pBooks;
Excel_2k::SheetsPtr pSheets;

AnsiString strCellContent,strCell;

try
{
//connect to Excel Application
m_pExcelApplication->Connect();

m_pExcelApplication->set_Caption( ( BSTR ) WideString( "Base
Coverage Report" ) );
m_pExcelApplication->set_Visible( TDefLCID(), true );
m_pExcelApplication->set_UserControl( Visible );
m_pExcelApplication->set_DisplayAlerts( 0,false);

pBooks.Bind( m_pExcelApplication->get_Workbooks(), true );

//Add workbook
pWorkBook.Bind( pBooks->Add(),true );

pSheets.Bind( pWorkBook->get_Worksheets(), true );

//Get the active sheet
pWorkSheet = pSheets->get_Item( ( TVariant ) 1 );
//pWorkSheet->set_Name( ( BSTR ) WideString( "Base Coverage
Report" ) );

// Cells
pCells.Bind( pWorkSheet->get_Cells() , true );

for( long lRow = 1; lRow <= StringGrid1->RowCount ; lRow++ )
{
for( long lCol = 1 ; lCol <= StringGrid1->ColCount ; lCol++ )
{
strCellContent = StringGrid1->Cells[ lCol ][ lRow ].Trim();

if( ( strCellContent == "Coverage(%) For Each Sample In Each
Exon" )
&& ( lCol > 1 ) )
continue;

//Get cell name.
strCell.sprintf("%s%ld",StringGrid1->Cells[ lCol ][ 0 ],
lRow );
pRange = pCells->get_Range_( ( TVariant )strCell,
( TVariant )strCell );

pCells->set_Item( ( TVariant )lRow, ( TVariant )lCol,
( TVariant )strCellContent );

if( ( strCellContent == "0" ) && ( lCol > 3 ) )
{
pRange->get_Interior()->set_Color( ( TVariant )clRed );

}
else if( ( strCellContent == "1" ) && ( lCol > 3 ) )
{
pRange->get_Interior()->set_Color( ( TVariant )clYellow );

}else if( ( strCellContent == "2" ) && ( lCol > 3 ) )
{
pRange->get_Interior()->set_Color( ( TVariant )clGreen );
}

}//End of for loop which iterates through cols of grid.

}//End of for loop which iteartes through rows of grid.

//Save the file.
pWorkBook->SaveAs((TVariant)strFileName,
TNoParam(),
TNoParam(),
TNoParam(),
TNoParam(),
TNoParam(),
xlNoChange,
TNoParam(),
TNoParam(),
TNoParam(),
TNoParam(),
TDefLCID());

//close work book
pWorkBook->Close(TNoParam(),
TNoParam(),
TNoParam(),
TDefLCID() );

pCells.Unbind();
pWorkSheet.Unbind();
pSheets.Unbind();
pWorkBook.Unbind();
pBooks.Unbind();

m_pExcelApplication->Quit();
//disconnect from excel application.
m_pExcelApplication->Disconnect();

}catch(...)
{
MessageDlg( "Exception occured while exporting the report."
"\nTerminating the export."
"\nRetry again." ,
mtError,
TMsgDlgButtons() << mbOK,
0 );

//close work book
pWorkBook->Close(TNoParam(),
TNoParam(),
TNoParam(),
TDefLCID() );

m_pExcelApplication->Quit();
//disconnect from excel application.
m_pExcelApplication->Disconnect();

}

delete pRange;
delete pCells;
delete pWorkSheet;
delete pSheets;
delete pWorkBook;
delete pBooks;


I am getting the following run time error message:

intf!=0 @ c:\Program files\borland\cbuilder6\include\vcl\utilcls.h/
2912
Press [y]es to terminate,[N]o to continue and [C]ancel to debug.

On pressing No it shows the following message:

IsBound()@ c:\Program files\borland\cbuilder6\include\vcl\utilcls.h/
4270
Press [y]es to terminate,[N]o to continue and [C]ancel to debug.

I have googled but didn't get the useful data.Please help me.

Thanks a lot.

Tara Khoiwal
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (ActiveX) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.