Solved

exporting to Excel at runtime using System.IO.MemoryStream

Posted on 2013-01-15
7
528 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 101

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 101

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 101

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

688 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