on 2015 Jul 11 7:33 PM
My crystal report has more than 90 columns, so while on generating the crystal report some columns are only visible. so my client ask me to, generate the crystal report in excel format directly, that is while on pressing the generate button, the report should download in excel format directly, that is without exporting the file to an path. so can you please provide the C# asp.net code for that and explain how to achieve that. Thanks in advance.
C# code :
<%@ Page Language="C#" enableViewState="true" Inherits="VWReports.AVWReport" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="VWReports" %>
<script language=cs runat=server>
string strSessionVariable = "";
public void Page_Init()
{
IVWReport Report = null;
VWSegment NewSeg = null;
try
{
if (!IsPostBack)
{
strSessionVariable = "objReport_" + Guid.NewGuid().ToString();
ReportMetaData ReportData = new ReportMetaData("empinduction_report", "empinduction_report.rpt");
ReportData.ReportSessionId = strSessionVariable;
ReportData.ExcludeUserPreference = true;
NewSeg = new VWSegment("erpempl_empl_r_rep_hr_hsg", SegmentType.Single);
NewSeg.AddDataItem("hractualdojfrom1", VWDataType.Date, 11);
NewSeg.AddDataItem("hractualdojto1", VWDataType.Date, 11);
NewSeg.AddDataItem("hradjdatefrom1", VWDataType.Date, 11);
NewSeg.AddDataItem("hradjdateto1", VWDataType.Date, 11);
NewSeg.AddDataItem("hrbuid", VWDataType.Character, 20);
NewSeg.AddDataItem("hrbusinessunitdesc2", VWDataType.Character, 60);
NewSeg.AddDataItem("hrclaimdatefrom1", VWDataType.Date, 11);
NewSeg.AddDataItem("hrclaimdateto1", VWDataType.Date, 11);
NewSeg.AddDataItem("hrdeptcdx1", VWDataType.Character, 10);
NewSeg.AddDataItem("hrdobfm1", VWDataType.Date, 11);
NewSeg.AddDataItem("hrdobto1", VWDataType.Date, 11);
NewSeg.AddDataItem("hrdopftrust1", VWDataType.Date, 11);
NewSeg.AddDataItem("hrdopm1", VWDataType.Date, 11);
NewSeg.AddDataItem("hrempcdfrom1", VWDataType.Character, 20);
NewSeg.AddDataItem("hrempcodeto2", VWDataType.Character, 20);
NewSeg.AddDataItem("hremployeestatus2", VWDataType.Character, 40);
NewSeg.AddDataItem("hremployeestatuscd", VWDataType.Character, 5);
NewSeg.AddDataItem("hremptype2", VWDataType.Character, 40);
NewSeg.AddDataItem("hremptype2cd", VWDataType.Character, 40);
NewSeg.AddDataItem("hrgradesetshdescx1", VWDataType.Character, 30);
NewSeg.AddDataItem("hrjobcd142", VWDataType.Character, 10);
NewSeg.AddDataItem("hrlocalityname2", VWDataType.Character, 80);
NewSeg.AddDataItem("hrlocalitynamecd", VWDataType.Character, 80);
NewSeg.AddDataItem("hrposidx2", VWDataType.Character, 10);
NewSeg.AddDataItem("hrqualifications4001", VWDataType.Character, 400);
NewSeg.AddDataItem("hrrepdate2", VWDataType.Date, 11);
ReportData.MapSegment(NewSeg);
NewSeg = new VWSegment("erpemplempl_rgrd1_repgrmsg", SegmentType.Multiple);
NewSeg.AddDataItem("hr11mscs1", VWDataType.Character, 40);
NewSeg.AddDataItem("hr12mscs1", VWDataType.Character, 40);
NewSeg.AddDataItem("hr13mscs1", VWDataType.Character, 40);
NewSeg.AddDataItem("hr14mscs1", VWDataType.Character, 40);
NewSeg.AddDataItem("hr15mscs1", VWDataType.Character, 40);
NewSeg.AddDataItem("hractualamt11", VWDataType.Double, 15);
NewSeg.AddDataItem("hractualamt21", VWDataType.Double, 15);
NewSeg.AddDataItem("hrageyrsfrom1", VWDataType.Integer, 4);
NewSeg.AddDataItem("hrallowance11", VWDataType.Double, 15);
NewSeg.AddDataItem("hrallowance2", VWDataType.Double, 15);
NewSeg.AddDataItem("hramtdeclared11", VWDataType.Double, 15);
NewSeg.AddDataItem("hramtdeclared21", VWDataType.Double, 15);
NewSeg.AddDataItem("hramtdeclared31", VWDataType.Double, 15);
NewSeg.AddDataItem("hramtdeclared41", VWDataType.Double, 15);
NewSeg.AddDataItem("hramtdeclared51", VWDataType.Double, 15);
NewSeg.AddDataItem("hramtdeclared61", VWDataType.Double, 15);
NewSeg.AddDataItem("hramtdeclared71", VWDataType.Double, 15);
NewSeg.AddDataItem("hrassgnefffrom1", VWDataType.Date, 11);
NewSeg.AddDataItem("hrauthleaveunits1", VWDataType.Double, 15);
NewSeg.AddDataItem("hrbasicpay1", VWDataType.Double, 15);
NewSeg.AddDataItem("hrbntotalcr1", VWDataType.Double, 15);
NewSeg.AddDataItem("hrclhra1", VWDataType.Double, 15);
NewSeg.AddDataItem("hrcommentstext111", VWDataType.Character, 255);
NewSeg.AddDataItem("hrcommentstext121", VWDataType.Character, 255);
NewSeg.AddDataItem("hrcommentstext131", VWDataType.Character, 255);
NewSeg.AddDataItem("hrcommentstext141", VWDataType.Character, 255);
NewSeg.AddDataItem("hrcommentstext151", VWDataType.Character, 255);
NewSeg.AddDataItem("hrcommentstext161", VWDataType.Character, 255);
NewSeg.AddDataItem("hrcommentstext171", VWDataType.Character, 255);
NewSeg.AddDataItem("hrcommentstext181", VWDataType.Character, 255);
NewSeg.AddDataItem("hrcommentstext191", VWDataType.Character, 255);
NewSeg.AddDataItem("hrcommentstext211", VWDataType.Character, 255);
NewSeg.AddDataItem("hrcompanycd1", VWDataType.Character, 4);
NewSeg.AddDataItem("hrcompdesc", VWDataType.Character, 50);
NewSeg.AddDataItem("hrcompyear1", VWDataType.Integer, 4);
NewSeg.AddDataItem("hrconvamtpaid1", VWDataType.Double, 15);
NewSeg.AddDataItem("hrctctotal1", VWDataType.Double, 15);
NewSeg.AddDataItem("hrcurrexp2", VWDataType.Character, 255);
NewSeg.AddDataItem("hrdepartment2", VWDataType.Character, 25);
NewSeg.AddDataItem("hrdepartmentdesc2", VWDataType.Character, 80);
NewSeg.AddDataItem("hrdeptqual1date1", VWDataType.Date, 11);
NewSeg.AddDataItem("hrdeptqual2date1", VWDataType.Date, 11);
NewSeg.AddDataItem("hrdeptqual3date1", VWDataType.Date, 11);
NewSeg.AddDataItem("hrdeptqual4date1", VWDataType.Date, 11);
NewSeg.AddDataItem("hrdeptqual5date1", VWDataType.Date, 11);
NewSeg.AddDataItem("hrdob3", VWDataType.Date, 11);
NewSeg.AddDataItem("hrdoj4", VWDataType.Date, 11);
NewSeg.AddDataItem("hrdolprevorg11", VWDataType.Date, 11);
NewSeg.AddDataItem("hrdop1", VWDataType.Date, 11);
NewSeg.AddDataItem("hrdort1", VWDataType.Date, 11);
NewSeg.AddDataItem("hrefbook1", VWDataType.Character, 80);
NewSeg.AddDataItem("hremail3", VWDataType.Character, 50);
NewSeg.AddDataItem("hrempcode", VWDataType.Character, 20);
NewSeg.AddDataItem("hremplname1", VWDataType.Character, 77);
NewSeg.AddDataItem("hremptype11", VWDataType.Character, 40);
NewSeg.AddDataItem("hresi2", VWDataType.Character, 40);
NewSeg.AddDataItem("hrexgratpay1", VWDataType.Double, 15);
NewSeg.AddDataItem("hrexperience1", VWDataType.Character, 255);
NewSeg.AddDataItem("hrfathername1", VWDataType.Character, 77);
NewSeg.AddDataItem("hrfileid1", VWDataType.Character, 20);
NewSeg.AddDataItem("hrgenderqcdm", VWDataType.Character, 40);
NewSeg.AddDataItem("hrgrade3", VWDataType.Character, 25);
NewSeg.AddDataItem("hrgradedescl2", VWDataType.Character, 80);
NewSeg.AddDataItem("hrgradesetcdx1", VWDataType.Character, 10);
NewSeg.AddDataItem("hrgradesetdescl2", VWDataType.Character, 80);
NewSeg.AddDataItem("hrhodcd1", VWDataType.Character, 20);
NewSeg.AddDataItem("hrinstitutionm1", VWDataType.Character, 40);
NewSeg.AddDataItem("hrintc111", VWDataType.Integer, 5);
NewSeg.AddDataItem("hrintc121", VWDataType.Integer, 5);
NewSeg.AddDataItem("hrintc131", VWDataType.Integer, 5);
NewSeg.AddDataItem("hrintc141", VWDataType.Integer, 5);
NewSeg.AddDataItem("hrjob1", VWDataType.Character, 40);
NewSeg.AddDataItem("hrjobcd6", VWDataType.Character, 10);
NewSeg.AddDataItem("hrleaveunits1", VWDataType.Double, 8);
NewSeg.AddDataItem("hrlleavebalanceunits11", VWDataType.Double, 8);
NewSeg.AddDataItem("hrlocaldetails1", VWDataType.Character, 40);
NewSeg.AddDataItem("hrlreqleaveunits3", VWDataType.Double, 8);
NewSeg.AddDataItem("hrmaritalstatus1", VWDataType.Character, 40);
NewSeg.AddDataItem("hrmedamtpaid1", VWDataType.Double, 15);
NewSeg.AddDataItem("hrmedical1", VWDataType.Character, 50);
NewSeg.AddDataItem("hrmgrcdmltmscs1", VWDataType.Character, 20);
NewSeg.AddDataItem("hrmlamount1", VWDataType.Double, 15);
NewSeg.AddDataItem("hrmonthsyears1", VWDataType.Character, 40);
NewSeg.AddDataItem("hrotherfee11", VWDataType.Double, 15);
NewSeg.AddDataItem("hrotherfee21", VWDataType.Double, 15);
NewSeg.AddDataItem("hrpan3", VWDataType.Character, 20);
NewSeg.AddDataItem("hrperkamt1", VWDataType.Double, 15);
NewSeg.AddDataItem("hrperpay1", VWDataType.Double, 15);
NewSeg.AddDataItem("hrpfappno2", VWDataType.Character, 20);
NewSeg.AddDataItem("hrpfindivfund1", VWDataType.Double, 15);
NewSeg.AddDataItem("hrposition4", VWDataType.Character, 25);
NewSeg.AddDataItem("hrpositionlgdesc2", VWDataType.Character, 80);
NewSeg.AddDataItem("hrprevexp2", VWDataType.Character, 255);
NewSeg.AddDataItem("hrprobtype1", VWDataType.Character, 40);
NewSeg.AddDataItem("hrqualification2", VWDataType.Character, 25);
NewSeg.AddDataItem("hrr1date1", VWDataType.Date, 11);
NewSeg.AddDataItem("hrr2date1", VWDataType.Date, 11);
NewSeg.AddDataItem("hrreason11", VWDataType.Character, 255);
NewSeg.AddDataItem("hrrefundeeamt11", VWDataType.Double, 15);
NewSeg.AddDataItem("hrrefundeeamt21", VWDataType.Double, 15);
NewSeg.AddDataItem("hrrefundeeamt31", VWDataType.Double, 15);
NewSeg.AddDataItem("hrretirementage1", VWDataType.Integer, 5);
NewSeg.AddDataItem("hrrptempstatml", VWDataType.Character, 40);
NewSeg.AddDataItem("hrsafcon1", VWDataType.Character, 40);
NewSeg.AddDataItem("hrseparationreason1", VWDataType.Character, 40);
NewSeg.AddDataItem("hrsepreasons11", VWDataType.Character, 40);
NewSeg.AddDataItem("hrsickdayleave1", VWDataType.Double, 5);
NewSeg.AddDataItem("hrsrlno1", VWDataType.Integer, 10);
NewSeg.AddDataItem("hrtotalamt3", VWDataType.Double, 15);
NewSeg.AddDataItem("hruser4", VWDataType.Character, 25);
NewSeg.AddDataItem("hrw2amount12a1", VWDataType.Double, 15);
NewSeg.AddDataItem("hrw2amount12b1", VWDataType.Double, 15);
NewSeg.AddDataItem("hrw2amount12c1", VWDataType.Double, 15);
NewSeg.AddDataItem("hrw2amount12d1", VWDataType.Double, 15);
NewSeg.AddDataItem("hrw2amount14a1", VWDataType.Double, 15);
ReportData.MapSegment(NewSeg);
Report = VWReports.Utilities.CreateReport();
Report.Configure(ReportData);
Session[strSessionVariable] = Report;
}
}
catch (Exception e)
{
Response.Write (e.Message);
}
}
public void Page_Load()
{
if (!IsPostBack)
{
hdnSessionVariableName.Value = strSessionVariable;
}
IVWReport Report = (IVWReport)Session[hdnSessionVariableName.Value];
try
{
if (Report != null)
Report.RenderReport(this);
}
catch (Exception e)
{
Response.Write (e.Message);
}
}
</script>
<html>
<title>Report</title>
<body style="margin:0px;" oncontextmenu="return false;" scroll="no" >
<form id="reportform" method="post" runat="server">
<input id="hdnSessionVariableName" type="hidden" name="hdnSessionVariableName" runat="server">
</form>
</body>
</html>
Hi Ram
Export to stream. See KBA 1198587 - How to export a report to stream in C Sharp (C#) for Visual Studio .NET
BTW., the reason you cannot see all the columns in the viewer is because the report engine depends on the printer driver.E.g.; say you'd need a page width of 30 inches to see all the columns, you'd need a printer driver that can print / supports a 30 inch paper width.
Alternatively, you can see what happens with the report is you check the "No Printer" option and "Dissociate Formatting Page Size and Printer Paper Size" option.
- Ludek
Senior Support Engineer AGS Product Support, Global Support Center Canada
Follow me on Twitter
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
11 | |
10 | |
10 | |
10 | |
8 | |
7 | |
7 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.