cancel
Showing results for 
Search instead for 
Did you mean: 

trying to alter excel format of crystal report exported to excel.

Former Member
0 Kudos

Hi, I am trying to clean up the excel export of a crystal report and am using visual studio 2005 and the CR.net that comes with it, I think version 10.

I have the following code that it runs if the export type is excel and I was just trying to make sure it is working. It does not seem to be making any difference in the exported excel file.

I am using office 2007.

private ReportDocument document;

ExcelFormatOptions excelformat = new ExcelFormatOptions();

excelformat.ExcelUseConstantColumnWidth = true ;

excelformat.ExcelConstantColumnWidth = 20;

excelformat.ExcelTabHasColumnHeadings = false;

excelformat.LastPageNumber = 2;

excelformat.FirstPageNumber = 3;

excelformat.UsePageRange = true;

document.ExportOptions.ExportFormatOptions = excelformat;

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi, Paul;

Try changing your code a bit.

Change the line:

document.ExportOptions.ExportFormatOptions = excelformat

to:

ExportOptions.ExportFormatOptions = excelformat

document.Export (ExportOptions)

Then try different options for the formatting to see if they are really changes.

Regards,

Jonathan

Former Member
0 Kudos

Thanks for the information, just wondering is that ment to be one line. I commented out the line

document.ExportOptions.ExportFormatOptions-excelformat;

and replaced it with two lines

ExportOptions.ExportFormatOptions = excelformat;

document.Export(ExportOptions);

on the first new line I get the following error

Error 1 An object reference is required for the nonstatic field, method, or property 'CrystalDecisions.Shared.ExportOptions.ExportFormatOptions.get'

on the second new line I get the error

Error 2 'CrystalDecisions.Shared.ExportOptions' is a 'type' but is used like a 'variable'

Former Member
0 Kudos

Hi, Paul;

Here is the complete block of sample code:

Dim rep As New CrystalReport1

Dim expOptions As New ExportOptions

Dim expdest As New DiskFileDestinationOptions

Dim expformat As New ExcelDataOnlyFormatOptions

'----


expdest.DiskFileName = "c:\ExportedExcel.xls"

'----


expformat.ExcelUseConstantColumnWidth = True

expformat.ExcelAreaType = AreaSectionKind.WholeReport

expformat.ExcelConstantColumnWidth = 60

expformat.ExcelUseConstantColumnWidth = True

expformat.ExportPageHeaderAndPageFooter = True

'----


expOptions.ExportDestinationType =

ExportDestinationType.DiskFile

expOptions.ExportDestinationOptions = expdest

expOptions.ExportFormatOptions = expformat

expOptions.ExportFormatType = ExportFormatType.ExcelRecord

'----


rep.Export(expOptions)

Regards,

Jonathan

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi I tried the settings in the example but still did not see any changes. I noticed that in my code the export type is Excel where in the example it is ExcelRecord, although do not think this would make a difference. Will take another look at my code.

Former Member
0 Kudos

thanks for the quick response, I am using C#, I think your example is in VB. I think my code is the equivalent in C# but I will take a closer look at the code you provided. Assuming the code is correct wondering if there is anything else that could cause it from not working?

Former Member
0 Kudos

Hi, Paul;

No, there is no reason that this should not work.

Regards,

Jonathan