locked
Export Report to Excel using a Excel Template RRS feed

  • Question

  • User-1622669350 posted

     I looking for assistance with the following. I have a SQL Server Report which when exported to Excel is difficult to read. So, I created an Excel Template which I would like to use in place of the default Excel file Reporting Services exports to. How do modify my code so that my Excel template is used instead of the default when the user exports the report??? Below is my code. Any assistance is appreciated.

     

     test.aspx

    <%@ Page Language="C#" Debug="true" AutoEventWireup="true" CodeFile="Test.aspx.cs"
        Inherits="Test" %>
    
    <%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
        Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt"
                    Height="400px" Width="400px">
                </rsweb:ReportViewer>
            </div>
        </form>
    </body>
    </html>

      

    test.aspx.cs 

    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Configuration;
    using System.Collections;
    using System.Text;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using Microsoft.Reporting.WebForms;
    
    
    public partial class Test : System.Web.UI.Page
    {
    
        // Handles initial page load
        protected void Page_Load(object sender, EventArgs e)
        {
            ConfigureReports();
        }
    
        protected void ConfigureReports() 
        {
            ReportViewer1.LocalReport.ReportPath = Server.MapPath("reports/BirdsReport.rdlc");
            DataSet dataSet = DataSetConfig.Birds;
            ReportDataSource ds = new ReportDataSource("BirdsDataSet_Birds", dataSet.Tables[0]);
            ReportViewer1.LocalReport.DataSources.Clear();
            ReportViewer1.LocalReport.DataSources.Add(ds);
            ReportViewer1.LocalReport.Refresh();
        }   
    
    }

     

    DataSetConfig.cs

    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    
    /// <summary>
    /// Summary description for DataSetConfig
    /// </summary>
    public class DataSetConfig
    {
    	public DataSetConfig()
    	{
    		//
    		// TODO: Add constructor logic here
    		//
    	}
    
        // Handles creating holds dataset
        public static DataSet Holds
        {
            get
            {
                DataSet dataSet = new DataSet();
    
                string query = "select * from birds";
    
                dataSet.ReadXmlSchema(@"D:\Sites\Birds\App_Code\BirdsDataSet.xsd"); // remote path
                
                SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["BirdsConnectionString"].ConnectionString);
                SqlDataAdapter cmd = new SqlDataAdapter(query, conn);
    
                cmd.Fill(dataSet, "Birds");
    
                return dataSet;
            }
        }
    }
     
     
    Monday, November 19, 2007 12:07 PM

Answers

All replies

  • User-1622669350 posted

     I'm still looking for assistance with this issue. Does anyone in the community know of alternative online resources for SSRS that offer reliable assistance?

    Tuesday, November 20, 2007 5:59 PM
  • User-1136466523 posted

    Hi,

    Based on my knowledge, you can’t create your own excel exporting format by your codes level. If you insist on doing that, some third-party software may involve in achieving your custom render.

    As for the online resources:

    http://technet.microsoft.com/en-us/sqlserver/bb331748.aspx   (For SQLServer 2000)
    http://technet.microsoft.com/en-us/sqlserver/bb331776.aspx   (For SQLServer 2005)

    Thanks.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 20, 2007 10:43 PM
  • User190544272 posted

    Is there any possibility in SSRS 2008 R2? 

    Tuesday, December 28, 2010 1:45 AM