Avatar of Shanmugam Rajagopal
Shanmugam Rajagopal
 asked on

Crystal Reports - Export to excel (formatted output)

I am using ReportDocument object with following options to export rpt data to excel

crystalExportOptions = (ExportOptions)reportDocument.ExportOptions;

                    if (oFileType.IsExcel)
                    {
                        DiskFileDestinationOptions diskOptions = new DiskFileDestinationOptions();
                        diskOptions.DiskFileName = destinationFolder + sExportFileName;

                        ExcelFormatOptions formatOptions = new ExcelFormatOptions();
                        formatOptions.ExcelTabHasColumnHeadings = true;
                        formatOptions.ShowGridLines = true;
                        formatOptions.ExcelUseConstantColumnWidth = true;
                        formatOptions.ExcelConstantColumnWidth = 1000;
                        crystalExportOptions.ExportFormatOptions = formatOptions;
                        crystalExportOptions.ExportFormatType = ExportFormatType.ExcelRecord;
                        crystalExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                        crystalExportOptions.ExportDestinationOptions = diskOptions;
                    }

using (Stream stream = reportDocument.ExportToStream(ExportFormatType.Excel))
{
      using (MemoryStream memoryStream = new MemoryStream())
                        {

                            stream.CopyTo(memoryStream);
                           //Save to DB
                        }
                    }
}

when I retrieve from db and download the excel it looks unformatted. How to make the cells Autowidth for the column in the excel file?

Thanks for your help
C#Crystal Reports

Avatar of undefined
Last Comment
Shanmugam Rajagopal

8/22/2022 - Mon
AndyAinscow

Not tried this.  The following line
 formatOptions.ExcelUseConstantColumnWidth = true;
looks like you instruct not to use an autowidth, try setting the value to false.
SOLUTION
Mike McCracken

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Ido Millet

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Shanmugam Rajagopal

ASKER
I tried formatOptions.ExcelUseConstantColumnWidth = false; but result remains same.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy