Crystal report with subreport export to excel fails - asp.net

I'm working on a ASP.Net web application in Visual Studio 2010. I'm working on a report designed in SAP Crystal Reports for VS2010.
I'm able to export the report to PDF and Word formats, but when I try to export it in Excel format, the Visual Studio debug just stops, and the response is never returned.
I'm using Crystal Reports for Visual Studio 2010, and the report in question has a simple subreport (nothing but a single label) in Section 1 (Report Header).
using (TestReport report = new TestReport()) // TestReport inherits ReportClass
{
TestDataSet data = this.GetData();
report.SetDataSource(data);
return report.ExportToStream(ExportFormatType.Excel);
}
The report.ExportToStream(ExportFormatType.Excel); fails and the debug just stops. If I remove the subreport it works OK, but otherwise it fails.

I managed to fix it by replacing the output format enum value from to Excel to ExcelWorkbook...
Code:
using (TestReport report = new TestReport()) // TestReport inherits ReportClass
{
TestDataSet data = this.GetData();
report.SetDataSource(data);
return report.ExportToStream(ExportFormatType.ExcelWorkbook);
}

Related

Crystal Report Asking parameter again

Dear all I am working on an asp .net application in which I am using crystal report for showing reports.
In my application everything works fine including the reports. The real problem comes when I start clicking on the crystal report toolbar. If I click on any buttons on the crystal report tool bar like (Export, next page ...etc.) it is asking parameters again. Is there any way so that that the crystal report viewer does not ask the parameter that I have already given ?
I have also given true for the property reuseparametervaluesonrefresh. i am passing parameters to the report document.
ReportDocument rd = new ReportDocument();
rd.SetParameterValue("#Date", Request["Date"]); CrystalReportViewer1.ReportSource = rd;
try to change Crystal Report Parameter type from Date to String.

ASP.Net (VB) Report View Data set Dynamically

I am having a hard time with this one and I assume it is something I am missing as always.
I am using Visual Studio Web Express 2012. I have installed Report Builder and Report Viewer 11. I have created a generic report file in the report builder as I can not seem to view any designer view in Visual Studio. Not the issue. I am pulling data from my SQL database as usual and populate a dataset. All is fine from here. I can not seem to get the data to show in the report view but can not figure out what I am missing. I have looked everywhere on the web as well as Stack specifically. I have used some of the sample codes and have gotten the report to now show up but still no data. Any help would be great.
I create a generic report file in report builder. No fields, no title etc., just the generic report. This may be my issue but I can not seem to figure out what I am missing.
On my page load I populate the dataset as always with no problem as I can display the data in a label etc.
I add the report viewer to my page and add the following code to the page load after the dataset fill. I also noted that you must use if page.postback = false as Ajax seems to not like it otherwise and just seems to loop and continue loading forever.
I have tried many different code ideas but found I finally got the report to load (again no data) with the following.
rv1.Reset()
rv1.LocalReport.DataSources.Clear()
Dim rds As New ReportDataSource("DataSet1", tempDS.Tables(0))
rv1.LocalReport.ReportPath = Server.MapPath("\tests\test.rdl")
rv1.LocalReport.DataSources.Add(rds)
rv1.LocalReport.Refresh()
Again this is VB.Net webpage. What am I missing? Thanks in advance.
Did you bind the datasource? Sorry if i'm wrong, but in C# asp.net you need to bind the datasource after using an atribution.

Trigger excel solver from vb.net web app

Using vb.net, visual studio 2013 and excel 2010.
I have a web page and when a button is clicked values are passed from the page to excel ( a presaved formatted copy). I then want to run the solver add in (which I have also preconfigured). I have been searching for a while now and cannot find a way of doing this.
The below is the code I use to open the excel application
Dim xlApp As Excel.Application
Dim xlWorkbook As Excel.Workbook
Dim xlWorksheet As Excel.Worksheet
xlApp = New Excel.Application
xlApp.Visible = True
xlApp.DisplayAlerts = False
xlWorkbook = xlApp.Workbooks.Open("c:\temp\RTO.xlsx")
xlWorksheet = xlWorkbook.Sheets("Optimiser")
Another curious problem that may be related is when I open excel from the web page the solver addin is enabled in excels options but does not appear in the data ribbon tab. If I disable and enable it in the options it comes back.
UPDATE
I tried the following code
xlApp.Run("C:\Program Files\Microsoft Office\Office15\Library\SOLVER\solver.xlam!Auto_Open")
But it errors with the following
Additional information: Cannot run the macro 'C:\Program
Files\Microsoft Office\Office15\Library\SOLVER\solver.xlam!Auto_Open'.
The macro may not be available in this workbook or all macros may be
disabled.
Ok, so
1) a website that populates excel with data and then streams the excel to the client.
2) the client then fill out or manipulates stuff in the excel.
3) Then clicks a button to solve and perhaps submit the excel...(where you are stuck)
Step 3 could be accomplished with a small 'one click application ' aka 'clickonce', whereas the application is online and served from your site. You could take one cell of your excel and have it open IE and point to the installer, and even pass a parameters (be sure to allow params to pass in the app) as to where the excel was located. Then the app could interop with the excel and do its stuff, perhaps even deliver data back to the server.
After further research and thinking about my problem, I came up with the following.
I cannot find any help about triggering solver from within my vb.net code but you can trigger a macro.
First I added the following code which loaded solver.xlam into excel once it had launched.
xlWorkbook.VBProject.References.AddFromFile("C:\Program Files\Microsoft Office\Office15\Library\SOLVER\solver.xlam")
I then created a macro in excel to launch solver. Once done I added the following line of code into my web page. Runsolver is the name of the macro.
xlApp.Run("RunSolver")
Hope this helps someone else down the line

Naming of Sheets using Asp.net SSRS 2008 (RDLC) for export to Excel

I'm working on a VS 2008 asp.net webforms application in which it contains an existing RDLC (Client file, and NOT the RDL Server side file).
The problem is upon exporting to excel, all of the worksheets are not named properly, i.e. Sheet1, Sheet2, etc. I have found many examples on exporting data, on SQL Server 2008 R2 feature of RDL, however I am in need of a RDLC solution?
Does anyone know about how to either "fix" this or do some sort of post processing to rename the tabs so the customer doesn't end up seeing Sheet1, Sheet2, Sheet3,etc.?
Application is choosing the path of the RDLC file
Adds DataSource
Chooses xls
Does all the Responses
I see this Stackoverflow link How to get named excel sheets while exporting from SSRS, however:
Can't do the Macro
Can't do the export as SSML
I am NOT using RDL / SQL Server 2008 R2 SSRS, thus the other answers are misleading for people using the RDLC
Sheet renaming isn't supported with the version of RDLC report. I'm guessing you can't upgrade. So here's a work around: Save the report to a file as normal. Then open it again using Microsoft.Office.Interop.Excel or any other Excel library to rename the sheets. Once you do this save and you're done.
using Excel = Microsoft.Office.Interop.Excel;
Excel.ApplicationClass xl=new Excel.ApplicationClass();
Excel.Workbook xlBook;
Excel.Worksheet xlSheet;
string filePath = Server.MapPath(#"\report.xls");
xlBook = (Workbook)xl.Workbooks.Open(filePath,Type.Missing,
Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing
,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing);
xlSheet = (Worksheet)xlBook.Worksheets.get_Item(1);
xlSheet.Name = "New Sheet Name";
xlBook.Save();
xl.Application.Workbooks.Close();
List of different libraries that you can use if this one doesn't work for you: Free Libraries
1. Close XML Library - http://closedxml.codeplex.com/documentation
2. Open XML SDK - http://msdn.microsoft.com/en-us/library/bb448854.aspx
3. NOPI - http://npoi.codeplex.com/
4. CarlosAG - http://www.carlosag.net/Tools/ExcelXmlWriter/
Paid Libraries
5. Spreadsheet Gear
6. Smart XLS
7. Office Writer
8. Spire
I would upgrade to the RDL 2010 schema - it supports Excel Named Sheets (amongst other useful enhancements):
http://msdn.microsoft.com/en-us/library/ee960138.aspx
Your not going to be able to do it.
http://social.msdn.microsoft.com/forums/en-US/sqlreportingservices/thread/54caf25b-b17b-474c-aa47-fc884f90af03
http://go4answers.webhost4life.com/Example/reportviewer-eport-excel-naming-sheets-157612.aspx
http://forums.asp.net/post/4140154.aspx
This may help for post processing using excels xml dialect:
http://spacefold.com/lisa/post/Changing-the-Sheet-names-in-SQL-Server-RS-Excel-QnD-XSLT.aspx

Crystal Reports - Data missing when exporting to (PDF or excel or word)

I'm trying to either print or export some Crystal Reports in asp.net
web application. The reports were made with CR 10.5, get their data
from an SQL Server 2008 database.
When I print or export to PDF, a bunch (but not all) of the fields are
skipped. I've
confirmed that the reports work fine in the viewer and designer, but
not when trying to view or export
1) Some fields are always skipped.
2) The same fields seem to be skipped.
Any suggestion or help is appreciated.
try this...
bind your crystal report viewer in page_init() method or check your page postback event...

Resources