{"id":86,"date":"2010-02-07T05:02:00","date_gmt":"2010-02-07T05:02:00","guid":{"rendered":"\/lisa\/post\/2010\/02\/07\/YAPS-on-Custom-Excel-for-RS-Drive-Subscriptions-with-a-Stick-Shift.aspx"},"modified":"2010-02-07T05:02:00","modified_gmt":"2010-02-07T05:02:00","slug":"yaps-on-custom-excel-for-rs-drive-subscriptions-with-a-stick-shift","status":"publish","type":"post","link":"https:\/\/spacefold.com\/lisa\/2010\/02\/07\/yaps-on-custom-excel-for-rs-drive-subscriptions-with-a-stick-shift\/","title":{"rendered":"YAPS on Custom-Excel-for-RS: Drive Subscriptions with a Stick Shift"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p>The title gives away the punchline on this one&#8230;<\/p>\n<p><a title=\"Cliff extends the domain of a post with a question\" href=\"\/lisa\/2007\/10\/03\/Changing-the-Sheet-names-in-SQL-Server-RS-Excel-QnD-XSLT#id_6d680d9b-217c-404a-be1a-85ce1a14eb3f\">Cliff Leighton asks<\/a><\/p>\n<blockquote>\n<p style=\"padding-left: 30px;\">Also, does anyone know how to make the output filename end with .XLS in an emailed SSRS Subscription with the &#8220;XML file with report data&#8221; option? The emailed file from the Subscription comes out as *filename*.xml and my users will be very confused with an XML file versus a XLS file.<\/p>\n<\/blockquote>\n<p>and at least one other person (<a title=\"I bet Sanket wants the same thing\" href=\"\/lisa\/2007\/10\/03\/Changing-the-Sheet-names-in-SQL-Server-RS-Excel-QnD-XSLT#id_0600842f-458f-476d-a0b2-3b71e8795f31\">Sanket<\/a>) appeared to have a similar problem last November:<\/p>\n<blockquote>\n<p style=\"padding-left: 30px;\">Hi,I want to change name of report file when exporting to excel.<br \/>i have got no idea how to do it. <img loading=\"lazy\" decoding=\"async\" class=\"flag\" style=\"border: 0; margin: 0px;\" src=\"https:\/\/spacefold.com\/lisa\/editors\/tiny_mce3\/plugins\/emotions\/img\/smiley-frown.gif\" alt=\"Frown\" width=\"15\" height=\"15\" \/><br \/>&nbsp;Please help <img loading=\"lazy\" decoding=\"async\" class=\"flag\" style=\"border: 0; margin: 0px;\" src=\"https:\/\/spacefold.com\/lisa\/editors\/tiny_mce3\/plugins\/emotions\/img\/smiley-smile.gif\" alt=\"Smile\" width=\"15\" height=\"15\" \/><\/p>\n<\/blockquote>\n<p>&#8230;&nbsp;which certainly makes it a question worth answering. I asked Sanket this:<\/p>\n<blockquote>\n<p style=\"padding-left: 30px;\">Sanket: are you exporting using an application?&nbsp;&nbsp;Or is the user doing the export from ReportViewer or Report Manager? Or what?<\/p>\n<\/blockquote>\n<p>&#8230; and you&#8217;ll see why shortly.<\/p>\n<h2>Before I answer, the inevitable caveat<\/h2>\n<p>Folks, while an XML extension may be confusing, consider the following:<\/p>\n<ul>\n<li>If the user&#8217;s computer has ever had Excel 2003 installed on it, chances are that a double-click will open the file in Excel by default, and the XML file will show an appropriate\/specialized icon to show that it is an &#8220;Excel XML file&#8221;, not a standard XML icon.&nbsp; Not terribly confusing.&nbsp; How does this work?&nbsp; It&#8217;s all down to the processing instruction that we added to the SSML: <br \/><span style=\"font-family: courier new,courier;\"><strong>&lt;?mso-application progid=&#8221;Excel.Sheet&#8221;?&gt;<br \/><\/strong><\/span><br \/>This screen shot shows you what it looks like when it works as expected (remember, this will be different depending on the client computer; for example, the Standard XML file icon you see here belongs to <a title=\"Stylus Studio site\" href=\"http:\/\/www.stylusstudio.com\/\" target=\"_blank\" rel=\"noopener\">Stylus Studio<\/a>, because that&#8217;s my default owner for this type of file on this computer):\n<p><img decoding=\"async\" src=\"\/lisa\/wp-non\/migrated\/2010\/2\/ExcelIcons.PNG\" alt=\"\" \/><\/p>\n<\/li>\n<li>If the user has&nbsp;Excel 2007 installed as the default owner for files&nbsp;with an XLS extension, and the file is really SSML rather than Excel binary, the result they will when they doubleclick is a&nbsp;warning&nbsp;like the following:\n<p><img decoding=\"async\" src=\"\/lisa\/wp-non\/migrated\/2010\/2\/Excel2007Warning.png\" alt=\"\" \/><\/p>\n<p>Naturally, you can tell your users to ignore this warning and answer &#8220;Yes&#8221; to the dialog.&nbsp; But it&#8217;s not exactly what I would call un-confusing.<\/p>\n<\/li>\n<\/ul>\n<p>So, IMHO&#8230; you pays your money and you takes your choice.&nbsp; With that understood, let&#8217;s address the stated requirement.<\/p>\n<h2>The short answer is &#8220;no&#8221;, but we don&#8217;t care.<\/h2>\n<p>Try to remember that the default subscription interface you see in Report Manager is just a basic UI given to you by default.&nbsp;<\/p>\n<p>Just like the parameters panel for ReportViewer, which we all love to hate, there&#8217;s nothing intrinsically required about it.<\/p>\n<p>Just like the Excel renderer can be obviated by creating our own SSML from the XML output, the base Excel rendition isn&#8217;t the one we have to accept.<\/p>\n<p>A subscription is just a timed task or job. If you look at SQL Agent, it looks something like this:&nbsp;<\/p>\n<p style=\"text-align: center;\"><img decoding=\"async\" src=\"\/lisa\/wp-non\/migrated\/2010\/2\/RSJob.PNG\" alt=\"\" \/><\/p>\n<p>The one step in the job looks something like this:&nbsp;<\/p>\n<p class=\"code\">exec ReportServer.dbo.AddEvent <br \/>&nbsp; @EventType=&#8217;TimedSubscription&#8217;, <br \/>&nbsp; @EventData=&#8217;512f89b1-7dd8-4b2f-806b-29927da7a81e&#8217;<\/p>\n<p>&#8230; and the code underneath is probably not very complicated either, although I&#8217;ve never looked.&nbsp; (That would be like trying to fix the default Excel renderer.)<\/p>\n<p>Let&#8217;s leave it alone, and think about the right way to fix our problem here, which (from Cliff&#8217;s point of view) is that you are allowed to set the full name of the output file when it goes to a file share, but you&#8217;re not allowed to set the extension when you send the subscription to an email address.<\/p>\n<h2>We won&#8217;t need any grenades<\/h2>\n<p>This is actually an easy problem to solve, several different ways (remember the paying the money and taking the choice part?)<\/p>\n<p>Here&#8217;s a&nbsp;overview of how to do this thing.<\/p>\n<p>Start with the knowledge that this is just a timed task, and write your own! It will be very simple, and SSIS is probably the most natural approach (but if you don&#8217;t like it you don&#8217;t have to use it, as you&#8217;ll easily see).<\/p>\n<ol style=\"list-style: decimal;\">\n<li style=\"list-style: decimal;\">\n<h3>Use a fileshare subscription, or&#8230;<\/h3>\n<ol style=\"list-style: decimal;\">\n<li style=\"list-style: decimal;\">If you&#8217;re using SSIS, you can invoke the subscription yourself. Or use a file watcher task (these are available from better SSIS jockeys than me, so check it out) and stick with the standard subscription schedule.<br \/>Method notes: You don&#8217;t need to use the code you see above, you can just <a title=\"How to send  SSRS from SSIS using subscription\" href=\"http:\/\/www.sql-server-performance.com\/faq\/How_to_send_a_SSRS_report_from_SSIS_p1\/\" target=\"_blank\" rel=\"noopener\">use <strong>exec sp_start_job<\/strong><\/a>.&nbsp; (That&#8217;s one reference. You&#8217;ll find others, I&#8217;m sure. It turns out this is pretty much an FAQ.)<\/li>\n<li style=\"list-style: decimal;\">Pick up the file and rename it.<\/li>\n<li style=\"list-style: decimal;\">Email it out.&nbsp;\n<ol>\n<li style=\"list-style: decimal;\">If your subscription was data driven, you should be able to look at the same data as RS does, to figure out to whom you email.&nbsp;<\/li>\n<li style=\"list-style: decimal;\">Emailing is simple, whether you use a purpose-built SSIS task or your own code.<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<li style=\"list-style: decimal;\">\n<h3>&#8230; Skip the subscription altogether. Create a timed task or SSIS job that does what you need, without one:<\/h3>\n<ol style=\"list-style: decimal;\">\n<li style=\"list-style: decimal;\">Retrieve the report yourself, with&nbsp;minimal code.&nbsp;\n<ol>\n<li style=\"list-style: decimal;\">You can use either SOAP or REST to do this.&nbsp;<br \/>Method notes: I&#8217;ve shown several examples of how to do this on this blog already, but I&#8217;ll add another example here, which shows a Q&amp;D REST approach to doing this inside SSIS.&nbsp; It comes from my <a title=\"XMLRSDocs docs\" href=\"http:\/\/spacefold.com\/articles\/xmlrsdocs\/\">xmlRSDocs<\/a> processing code, but you should be able to see how to apply it.&nbsp; <br \/>I&#8217;m posting this bit because I think I remember having to help somebody with the correct classes to use for a low-level post approach like this, when working inside SSIS, once.<\/li>\n<li style=\"list-style: decimal;\">Here&#8217;s <a title=\"Consuming RS in SSIS\" href=\"http:\/\/mgarner.wordpress.com\/2007\/06\/06\/consuming-the-reporting-services-web-service-inside-ssis\/\" target=\"_blank\" rel=\"noopener\">an alternative<\/a> &#8212; you&#8217;ll find many &#8212; for invoking RS inside SSIS, and this one uses SOAP.&nbsp; I think this is a bit overcomplicated and I think you can apply some of my other instructions for SOAP invocations more easily, including <a title=\"blog post using SOAP API to grab a report\" href=\"\/lisa\/2010\/01\/16\/Walkthrough-Part-II-Dynamic-Interactive-Paging-and-another-fierce-look-at-parameters\/\">one SOAP version done quite recently<\/a>. But maybe this one is more &#8220;orthodox&#8221;, so I don&#8217;t want to push my methods on you..<\/li>\n<\/ol>\n<\/li>\n<li style=\"list-style: decimal;\">Obviously when you&#8217;re picking up the file yourself, name it anything you want.<\/li>\n<li style=\"list-style: decimal;\">As above, email it out.<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>That&#8217;s about it.&nbsp; Here&#8217;s the REST example I promised; this is the code from an SSIS script task.<\/p>\n<p class=\"code\">&nbsp;<br \/><span style=\"color: #0000ff;\">Public Sub<\/span> Main()&nbsp;&nbsp;<br \/><span style=\"color: #008800;\">&nbsp;&nbsp; &#8216; a script task to grab an SSRS report <br \/>&nbsp;&nbsp; &#8216; from within SSIS, based on some <br \/>&nbsp;&nbsp; &#8216; specialized package variables that make<br \/>&nbsp;&nbsp;&nbsp;&#8216; sense in my scenario.&nbsp; Your scenario is<br \/>&nbsp;&nbsp; &#8216; different, but the basic idea will work for you.<\/span><br \/>&nbsp;<br \/><span style=\"color: #0000ff;\">&nbsp;&nbsp; Dim<\/span> outputFile <span style=\"color: #0000ff;\">As String<\/span>, requestURL <span style=\"color: #0000ff;\">As String<\/span><br \/>&nbsp;<br \/><span style=\"color: #0000ff;\">&nbsp;&nbsp; If<\/span> Dts.Variables(<span style=\"color: #a31515;\">&#8220;ExportRSType&#8221;<\/span>).Value.ToString().Length = 0 <span style=\"color: #0000ff;\">Then<\/span><br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dts.Variables(<span style=\"color: #a31515;\"> &#8220;ExportRSType&#8221;<\/span>).Value = <span style=\"color: #a31515;\">&#8220;PDF&#8221;<\/span><br \/>&nbsp;&nbsp; <span style=\"color: #0000ff;\">End If<\/span> <\/p>\n<p><span style=\"color: #0000ff;\">&nbsp;&nbsp; <\/span>outputFile = Dts.Variables(<span style=\"color: #a31515;\"> &#8220;ExportRSFilename&#8221;<\/span> ).Value.ToString()&nbsp;&nbsp;<br \/>&nbsp;<br \/><span style=\"color: #0000ff;\">&nbsp;&nbsp; If<\/span> System.IO.Path.GetDirectoryName(outputFile) = <span style=\"color: #a31515;\">&#8220;&#8221;<\/span> <span style=\"color: #0000ff;\">Then<\/span><br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; outputFile = Dts.Variables(<span style=\"color: #a31515;\">&#8220;InputDir&#8221;<\/span> ).Value.ToString() &amp; _&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; outputFile&nbsp;<br \/>&nbsp;&nbsp; <span style=\"color: #0000ff;\">End If<\/span><\/p>\n<p>&nbsp;&nbsp; outputFile = System.IO.Path.GetFullPath(outputFile)<br \/>&nbsp;&nbsp; requestURL = _<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dts.Variables(<span style=\"color: #a31515;\">&#8220;ExportRSURL&#8221;<\/span> ).Value.ToString()&nbsp;<br \/>&nbsp;&nbsp; requestURL += _<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: #a31515;\">&#8220;&amp;rs:Command=Render&#8221;<\/span><br \/>&nbsp;&nbsp; requestURL += _<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: #a31515;\">&#8220;&amp;rs:Format=&#8221;<\/span> &amp; Dts.Variables( <span style=\"color: #a31515;\">&#8220;ExportRSType&#8221;<\/span> ).Value.ToString()&nbsp;&nbsp;<\/p>\n<p><span style=\"color: #008800;\">&nbsp;&nbsp; &#8216; this part is a little kludge because of&nbsp;<br \/>&nbsp;&nbsp; &#8216; how I set up my URL template variable&nbsp;<br \/>&nbsp;&nbsp; in the SSIS Package&#8230; not really germane:<br \/><\/span><br \/>&nbsp;&nbsp; &nbsp;<span style=\"color: #0000ff;\">If<\/span> Len(Dts.Variables( <span style=\"color: #a31515;\">&#8220;ExportRSParams&#8221;<\/span>).Value.ToString()) &gt; 0 <span style=\"color: #0000ff;\">Then<\/span><br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; requestURL += _<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: #a31515;\">&#8220;&amp;&#8221; <\/span>&amp; Dts.Variables( <span style=\"color: #a31515;\">&#8220;ExportRSParams&#8221;<\/span>).Value.ToString().Replace( <span style=\"color: #a31515;\">&#8220;^&#8221;<\/span>, <span style=\"color: #a31515;\">&#8220;&amp;&#8221;<\/span> )<br \/>&nbsp;&nbsp; <span style=\"color: #0000ff;\">End If<\/span><\/p>\n<p>&nbsp;&nbsp; <span style=\"color: #0000ff;\">Dim<\/span> ox <span style=\"color: #0000ff;\">As<\/span> System.Net.WebRequest = _&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.Net.WebRequest.Create(requestURL)<br \/>&nbsp;&nbsp; ox.UseDefaultCredentials =&nbsp; <span style=\"color: #0000ff;\">True<\/span> <span style=\"color: #008000;\">&#8216;TBD&#8230;<\/span><br \/>&nbsp;<br \/>&nbsp;&nbsp; <span style=\"color: #0000ff;\">Dim<\/span> oy <span style=\"color: #0000ff;\">As<\/span> System.Net.WebResponse = ox.GetResponse()&nbsp;&nbsp;<br \/>&nbsp;&nbsp; <span style=\"color: #0000ff;\">Dim<\/span> raw <span style=\"color: #0000ff;\">As<\/span> System.IO.FileStream = _&nbsp;&nbsp;<br \/>&nbsp;&nbsp; <span style=\"color: #0000ff;\">New<\/span> System.IO.FileStream(outputFile, IO.FileMode.Create)&nbsp;&nbsp;<br \/>&nbsp;&nbsp; <span style=\"color: #0000ff;\">Dim<\/span> buffer(1024) <span style=\"color: #0000ff;\">As Byte <\/span><br \/>&nbsp;<br \/>&nbsp;&nbsp;&nbsp;<span style=\"color: #0000ff;\">Dim<\/span> rs <span style=\"color: #0000ff;\">As<\/span> System.IO.Stream = oy.GetResponseStream()&nbsp;&nbsp;<br \/>&nbsp;&nbsp; <span style=\"color: #0000ff;\">Dim<\/span> read <span style=\"color: #0000ff;\">As<\/span> <span style=\"color: #0000ff;\">Integer<\/span> = rs.Read(buffer, 0, buffer.Length)&nbsp;&nbsp;<br \/>&nbsp;&nbsp;&nbsp;<br \/>&nbsp;&nbsp; <span style=\"color: #0000ff;\">While<\/span> (read &gt; 0) <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; raw.Write(buffer, 0, read)<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; read = rs.Read(buffer, 0, buffer.Length)<br \/>&nbsp;&nbsp; <span style=\"color: #0000ff;\">End While<\/span><\/p>\n<p>&nbsp;&nbsp; oy.Close()<br \/>&nbsp;&nbsp; raw.Close()<br \/>&nbsp;&nbsp; raw.Dispose()<br \/>&nbsp;&nbsp; rs.Close()<br \/>&nbsp;&nbsp; rs.Dispose()<br \/>&nbsp;&nbsp; oy =&nbsp;<span style=\"color: #0000ff;\">Nothing<\/span><br \/>&nbsp;&nbsp; ox =&nbsp;<span style=\"color: #0000ff;\">Nothing<\/span><br \/>&nbsp;&nbsp; raw =&nbsp;<span style=\"color: #0000ff;\">Nothing<\/span><br \/>&nbsp;&nbsp; rs =&nbsp;<span style=\"color: #0000ff;\">Nothing<\/span><br \/>&nbsp;&nbsp; Dts.TaskResult = ScriptResults.Success<br \/>&nbsp;<br \/><span style=\"color: #0000ff;\">End Sub<\/span><\/p>\n<p>&#8230; OK?<\/p>\n<p>None of this stuff is magic.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; The title gives away the punchline on this one&#8230; Cliff Leighton asks Also, does anyone know how to make the output filename end with .XLS in an emailed SSRS Subscription with the &#8220;XML file with report data&#8221; option? The emailed file from the Subscription comes out as *filename*.xml and my users will be very<a class=\"more-link\" href=\"https:\/\/spacefold.com\/lisa\/2010\/02\/07\/yaps-on-custom-excel-for-rs-drive-subscriptions-with-a-stick-shift\/\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,6,7,10,12],"tags":[],"class_list":["post-86","post","type-post","status-publish","format-standard","hentry","category-reporting","category-sql-server","category-ssis","category-xml-xslt","category-yaps"],"_links":{"self":[{"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/posts\/86","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/comments?post=86"}],"version-history":[{"count":0,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/posts\/86\/revisions"}],"wp:attachment":[{"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/media?parent=86"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/categories?post=86"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/tags?post=86"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}