[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


exporting to Excel at runtime using System.IO.MemoryStream

Posted on 2013-01-15
Medium Priority
Last Modified: 2013-01-22
I have the following code below that I pulled from export to PDF at runtime, and just changed the memorystream to excel from PDF.
I do not see anywhere to put any options like autofit columns.

This works when a user clicks on the open report in excel button, but no format options.
Is there a better approach to this or is there format options I can do with the below code?

  Dim report As New Screen_CostsSummarySheetNewNoDates
                            Dim connectionInfo As New ConnectionInfo()

                            connectionInfo.DatabaseName = "LaborSheets"
                            connectionInfo.UserID =
                            connectionInfo.Password =
                            SetDBLogonForReport(connectionInfo, report)
                            Dim JobHolder = report.ParameterFields("JobNumberHolder")
                            Dim InvoiceNumberHold = report.ParameterFields("TAXBRACKET")

                            Dim s As System.IO.MemoryStream = report.ExportToStream(ExportFormatType.ExcelWorkbook)
                            Dim fs As System.IO.FileStream
                            Dim w As System.IO.BinaryWriter

                            fs = New System.IO.FileStream("C:\Temp\Cost Summary Sheet ALL Dates for " & JLabel.Text & ".xlsx", IO.FileMode.OpenOrCreate)
                            w = New System.IO.BinaryWriter(fs)
                            w.Seek(0, System.IO.SeekOrigin.Begin)
                            s = Nothing
                            fs = Nothing
                            w = Nothing
Question by:BKennedy2008
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
LVL 101

Assisted Solution

mlmcc earned 1000 total points
ID: 38779359
Is this a Crystal Reports question?

If so, why are you exporting that way rather than using the built in Crystal exporting methods?

LVL 83

Accepted Solution

CodeCruiser earned 1000 total points
ID: 38779410
To be able to format the Excel file, you will need to open it using Excel interop and set those properties.

Author Comment

ID: 38779977
using the CR Built in options, what did I mess up?

   Dim CrExportOptions As ExportOptions
                            Dim CrDiskFileDestinationOptions As New  _
                            Dim CrFormatTypeOptions As ExcelFormatOptions = ExportOptions.CreateExcelFormatOptions()
                            CrDiskFileDestinationOptions.DiskFileName = "C:\Temp\Cost Summary Sheet ALL Dates for " & JLabel.Text & ".xlsx"
                            CrFormatTypeOptions.ExcelTabHasColumnHeadings = True
                            CrFormatTypeOptions.ExcelUseConstantColumnWidth = True
                            CrFormatTypeOptions.ExcelConstantColumnWidth = "15"
                            CrExportOptions = report.ExportOptions
                            With CrExportOptions
                                .ExportDestinationType = ExportDestinationType.DiskFile
                                .ExportFormatType = ExportFormatType.ExcelWorkbook
                                .DestinationOptions = CrDiskFileDestinationOptions
                                .FormatOptions = CrFormatTypeOptions
                            End With
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

LVL 101

Expert Comment

ID: 38780742
WHat is the result?


Author Comment

ID: 38782137
none of the format is being applied
LVL 101

Expert Comment

ID: 38785558
What version of Crystal are you using?


Author Closing Comment

ID: 38805401
My bad, got caught up in the end of the year reports.
Kudos to both,
I used the built in CR to create the report, then used the interop to open the file.

Works like a champ.
Thanks again

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question