Exporting data from Crystal Report to Excel

Hi,
I'm exporting data from Crystal Report to Excel. When I export I'm not able to see the borders, hence I'm using Excel namespace for showing border lines, the following is the code I'm using in the Web Application:

using Excel;

string workbookPath = "c:/SomeWorkBook.xls";

ExportOptions export = new ExportOptions();

DiskFileDestinationOptions ex = new DiskFileDestinationOptions();
ex.DiskFileName=workbookpath;
export.DestinationOptions = ex;
ReportDocument.Export();

Excel.Application excelApp =new Excel.ApplicationClass();// Creates a new Excel Application

excelApp.Visible =true;// Makes Excel visible to the user.

// The following code opens an existing workbook

Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(workbookPath, 0,

false, 5, "", "",false, Excel.XlPlatform.xlWindows, "",true,

false, 0,true,false,false);

// The following gets the Worksheets collection

Excel.Sheets excelSheets = excelWorkbook.Worksheets;

// The following gets Sheet1 for editing

string currentSheet = "Sheet1";

Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelSheets.get_Item(currentSheet);

Excel.Range cell = excelWorksheet.UsedRange;

cell.Borders.get_Item(Excel.XlBordersIndex.xlEdgeTop ).LineStyle =Excel.XlLineStyle.xlContinuous;

cell.Borders.get_Item(Excel.XlBordersIndex.xlEdgeBottom ).LineStyle =Excel.XlLineStyle.xlContinuous;

cell.Borders.get_Item(Excel.XlBordersIndex.xlEdgeRight ).LineStyle =Excel.XlLineStyle.xlContinuous;

cell.Borders.get_Item(Excel.XlBordersIndex.xlEdgeLeft ).LineStyle =Excel.XlLineStyle.xlContinuous;

excelWorkbook.Save();

excelWorkbook.Close(Type.Missing,workbookpath,Type.Missing);
export.DestinationOptions = ex;

excelWorkbook = null;
excelSheets = null;
excelApp = null;

When I use the above code, the Excel application is running in the background (I'm able to see the process running for that in the Task Manager) under IUSR_<servername> and as well as under current user who as logged in. So whenever I export data, that many times the Excel Application are running in the process.

How to solve this problem?

Thanks & Regards.
Remo.

[3308 byte] By [Aniyan_Remo] at [2008-2-16]
# 1
Hi Remo

The best place to get an answer to your question is to post it on the Excel Programming newsgroup. You can access it at the address below.

Thanks!
Mike Hernandez
Community Program Manager
VSTO Team

http://msdn.microsoft.com/newsgroups/default.aspx?g=microsoft.public.excel.programming

MikeHernandez-MSFT at 2007-9-8 > top of Msdn Tech,Visual Studio Tools for Office,Visual Studio Tools for Office...
# 2

Thanks Mike Smile

Aniyan_Remo at 2007-9-8 > top of Msdn Tech,Visual Studio Tools for Office,Visual Studio Tools for Office...
# 3

Hi Remo,

Based on your description of the problem it appears that you are implementing server side automation of Microsoft Excel which is not recommended for Office applications.

I have included a link below to a Knowledge Base article that discusses the reasons why this isn't supported as well possible issues that my be encountered when automating Microsoft Excel on the server.

257757 INFO: Considerations for Server-Side Automation of Office
http://support.microsoft.com/?id=257757

However, in reviewing your code it doesn't appear that you are shutting down the instance of Excel in your code. You may want to try adding the following line of code before setting the variables to null

excelApp.Quit();

Addiitonally you may also want to review the following article concerning the releasing of COM objects when automating from a .NET application.

317109 Office application does not quit after automation from Visual Studio
http://support.microsoft.com/?id=317109

Regards,

Ken Laws
MSFT

This posting is provided "AS IS" with no warranties, and confers no rights.

KenLaws at 2007-9-8 > top of Msdn Tech,Visual Studio Tools for Office,Visual Studio Tools for Office...
# 4
Thanks Ken Smile
Aniyan_Remo at 2007-9-8 > top of Msdn Tech,Visual Studio Tools for Office,Visual Studio Tools for Office...
# 5

Hi Mike,

I saw your posting and was wondering if you could give me a hand.

I'm not a programmer but I'm doing some with VS 2003 .Net and Crystal reports.

1. I'd like to create a report that shows the total time elapsed between two dates and times with SQL 2000 Server as data source

first variable - startdate mask mm/dd/yyyy format date
second variable - starttime mask hhmm format text
third variable - enddate mask mm/dd/yyyy format date
fourth variable - endtime mask hhmm format text

I'd like to be able to use only business hours (8 hours during week days) and

2. I'd like to export (using the same report) to an excel file

Any information you have would be greatly appreciated.

Thanks.

Alino at 2007-9-8 > top of Msdn Tech,Visual Studio Tools for Office,Visual Studio Tools for Office...