Showing results for 
Search instead for 
Did you mean: 

Alignment problem in excel when export from cr viewer

Former Member
0 Kudos


We are developing a windows application in VS 2005 with CR XI.

When we export the report to excel,

1. If the report has any null value, there are alignment problems.

2. The worksheet name is coming as "Sheet 1" by default. I need to change it to the name of the report.

Is there any solution to fix the above issues. Please let me know.

Code Used for export:

Private Sub cmdExport_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdExport.Click

Dim StrExportPath As String

Dim diskOpts As DiskFileDestinationOptions = ExportOptions.CreateDiskFileDestinationOptions()

Dim exportOpts As ExportOptions

Dim myExportFormatOptions As ExcelFormatOptions = ExportOptions.CreateExcelFormatOptions()


Cursor.Current = Cursors.WaitCursor

cmdExport.Enabled = False

StrExportPath = txtExportPath.Text

If (StrExportPath.Length > 0) Then

If Not Strings.Right(StrExportPath.Trim().ToLower, 4) = ".xls" Then

StrExportPath = txtExportPath.Text & Strings.Left(objExportSave.Filter, 4)

End If

diskOpts.DiskFileName = StrExportPath

myExportFormatOptions.ExcelConstantColumnWidth = 300

myExportFormatOptions.ExcelUseConstantColumnWidth = True

exportOpts = New ExportOptions

exportOpts.ExportFormatOptions = myExportFormatOptions

exportOpts.ExportDestinationOptions = diskOpts

exportOpts.ExportFormatType = ExportFormatType.Excel

exportOpts.ExportDestinationType = ExportDestinationType.DiskFile


'customerReport.ExportToDisk(ExportFormatType.Excel, StrExportPath)

Cursor.Current = Cursors.Arrow

'Added at Dot Net Migration To Display the message.

MsgBox("Report Exported successfully", MsgBoxStyle.Information, ModMessage.strTitle)


MsgBox("Please enter a File Name to Export", MsgBoxStyle.Information, ModMessage.strTitle)

End If

Catch ex As Exception

funMsgDesc(4001, ex.Message.ToString)


Cursor.Current = Cursors.Arrow

cmdExport.Enabled = True

End Try

Thanks in advance.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Sandhiya,

It seems that you are using non compatible environment.

VS 2003 is only compatible with CR 9.1 (Bundle version which comes with VS), CR XI R1 and CR10.

VS 2005 is only compatible with CR 10.2 (Bundle version which comes with VS), CR XI R2 and CR 2008.

VS 2008 is only compatible with CR 10.5 (Bundle version which comes with VS) and CR 2008 SP0 and SP1.

While exporting give the report name so that you will get the report name as per your requirement.

When exporting from an application, the field headers are not aligned (in the exported Excel file) because the default column width is based on objects in the details section.

Use the following lines of code:

Dim excelOpts As New ExcelFormatOptions()

' Insert Applicable Options Here

crReportDocument.ExportOptions.FormatOptions = execlOpts

'Set the report to use a non-constant column width

excelOpts.ExcelUseConstantColumnWidth = False

'Set the default Width Setting for exporting to Excel as 'Whole Report'

excelOpts.ExcelAreaType = 255



Former Member
0 Kudos

Hi Shewta,

We are using VS 2005 with CR 10.2 (Bundle version which comes with VS). So it is compatible right.

We are giving the filename when export click, and we are able to get that name for the excel file. But for the worksheet name it is coming as "Sheet1". Got it?

I have used the code given by you. But still that columns are overlapping and not properly aligned. Due to this when I give filter, it looks crap. But in CR 8 with vb, the export is working good. The problem is with this .net version.


Active Contributor
0 Kudos

Note in your original post you wrote:

"We are developing a windows application in VS 2005 with CR XI.'

Now you say you are using "...VS 2005 with CR 10.2 (Bundle version which comes with VS)."

Let us know the version of the Crystal Reports assemblies referenced in your project and we'll proceed from there. OK?


Answers (0)