Solved

exporting to Excel at runtime using System.IO.MemoryStream

Posted on 2013-01-15
7
526 Views
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")
                            JobHolder.CurrentValues.AddValue(JobNumberHolder)
                            Dim InvoiceNumberHold = report.ParameterFields("TAXBRACKET")
                            InvoiceNumberHold.CurrentValues.AddValue(TaxBox_Daily.Text)


                            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)
                            w.Write(s.ToArray)
                            w.Close()
                            fs.Close()
                            System.Diagnostics.Process.Start(fs.Name)
                            s = Nothing
                            fs = Nothing
                            w = Nothing
0
Comment
Question by:BKennedy2008
[X]
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
7 Comments
 
LVL 100

Assisted Solution

by:mlmcc
mlmcc earned 250 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?

mlmcc
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 250 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.
0
 

Author Comment

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

   Dim CrExportOptions As ExportOptions
                            Dim CrDiskFileDestinationOptions As New  _
                          DiskFileDestinationOptions()
                            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
                            report.Export(CrExportOptions)
0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
LVL 100

Expert Comment

by:mlmcc
ID: 38780742
WHat is the result?

mlmcc
0
 

Author Comment

by:BKennedy2008
ID: 38782137
none of the format is being applied
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 38785558
What version of Crystal are you using?

mlmcc
0
 

Author Closing Comment

by:BKennedy2008
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
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display

730 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