YAPS (Yet another postscript) on Custom Excel for RS

by Lisa Nicholls Fri, April 18 2008 15:11

I really can't believe I'm revisiting this subject... I thought I was done with it ... but this is worth saying because it's helpful to anybody generating SSML (Excel 2003 XML dialect) whether they are interested in RS or not.  I also can't believe I never figured this out before -- because I generate a lot of SSML, for all kinds of custom reports.

So last time I said this 

[...] It also happens to be a situation, alluded to in my walkthrough, where you have to be careful that your dynamically-driven tab names are actually legal tab names in Excel.  In this case, I used the following code to validate and change the tab names if necessary:

<xsl:template name="StripSheetName">
      <xsl:param name="item"/>
      <xsl:variable name="i1">
         <xsl:value-of select="translate($item,'&quot;“”','')"/>
      </xsl:variable>
      <xsl:value-of select="translate($i1,&quot;/\'&quot;,&quot;&quot;)"/>
</xsl:template>

... looks a bit wierd and it may not turn out to be sufficient, but basically all I'm doing is taking out characters I know to be illegal.  If I find more, I'll add more.

Guess what?  It didn't turn out to be sufficient. 

The items I'm using for tab names in this report are particularly long and (who knew?) Excel has a tab name limit of 31 characters. Before you ask, it's not in the Excel specifications and limits page as far as I can see. 

Also before you ask I figured out the exact number by typing 1234512345123451234512345123451 into a tab.  That last "1" is the last character Excel will let you type.  If anybody has a better source of information, I'm all ears.

So, I smartened up the template you see above a little bit.  In this particular workbook, we're adding some verbiage onto the end of entries for each tab, which you'll see referenced; other than that, you may be able to use this puppy. 

I'm stripping blank spaces out to conserve some tablength room in this version; this isn't required, because spaces are allowed in tab names, but I was trying to save some room for more meaningful content.   You'll also notice a use of two dots ("..") wherever I'm truncating a tab name, and your strategy might be slightly different... 

In any case, all-in-all, something like this should work for you.

 <xsl:template name="StripSheetName">

      <xsl:param name="item"/>
     <xsl:param name ="secondTable"/>

     <!-- get rid of smart quote and quote marks, not allowed
           and remove spaces too, to save room -->

      <xsl:variable name="i1">
         <xsl:value-of select="translate($item,' &quot;“”','')"/>
      </xsl:variable>

     <!-- get rid of other disallowed characters, including
            single-quote (apostrophe) -->

     <xsl:variable name="i2" select="translate($i1,&quot;/\'&quot;,&quot;&quot;)"/>

     <xsl:variable name="i3" >
       <xsl:choose>
         <xsl:when test="string-length($i2) &gt; 20">
         <!-- truncate, leaving enough spare room for suffix,
                and add dots -->

           <xsl:value-of select ="concat(substring($i2,1,18),'..')"/>
         </xsl:when>
         <xsl:otherwise>
           <xsl:value-of select ="$i2"/>
         </xsl:otherwise>
       </xsl:choose>
     </xsl:variable>

    <!-- add appropriate suffix for this tab -->
     <xsl:choose>
       <xsl:when test ="$secondTable">
         <xsl:value-of select ="concat($i3,'ByActivity')"/>
       </xsl:when>
       <xsl:otherwise>
         <xsl:value-of select ="concat($i3,'ByCategory')"/>
       </xsl:otherwise>
     </xsl:choose>

   </xsl:template>

 

Also before you ask: what you see up there with escaped characters is correct (for example where you see &gt; (for greater than, in XSLT) that's not an error of HTML formatting. 

The parts that look especially weird come from explicitly specifying delimiters, such as quotation marks, as string literals, but this really does work, and you may really need to do it now and again.

Enjoy... and god bless Excel and all its peculiarities <sob>.

Tags:

ASP.NET | Reporting | XML/XSLT

Comments (55) -

11/5/2008 12:48:32 AM #

Tom Xie

Hi Lisa,
Thank you for this passage, and I think there are some missing invalid chars in the utility. <g>
I've added them as the following:
<xsl:variable name="i2" select="translate($i1,&quot;/\':*?[]&quot;,&quot;&quot;)"/>

Hope it helps, thank you

Tom Xie People's Republic of China

11/5/2008 12:50:17 AM #

&gt;L&lt;

Thank you Tom!  Like the length of the tab name, this isn't documented anywhere that I could find.  So I only find out about illegal characters by trial and error <g>.  Thank you for saving me some trial and error!

>L< United States

6/24/2009 10:36:25 AM #

Quick Payday Loan

No matter what did you say. you did the great jobs..
Congratulation!

Quick Payday Loan

7/8/2009 7:05:05 PM #

Contractor for Roofs

Nice blog, just bookmarked it for later reference

Contractor for Roofs United States

7/9/2009 5:48:59 AM #

Dustin

This is new info for me Thanks.

Dustin United States

8/16/2009 5:37:53 AM #

Calling Cards USA

Thanks, you cleared up some things for me.

Calling Cards USA United States

8/22/2009 8:09:19 AM #

Book Publisher UK

As helpful as ever, thanks!

Book Publisher UK United Kingdom

8/23/2009 8:16:52 PM #

atlix

A++ post will read again

atlix United States

11/22/2009 6:37:45 AM #

excel expert

Excel 2003 XML dialect in which application is it suitable?

excel expert United States

11/23/2009 12:28:46 PM #

book publishers uk

the more YAPS the better in my mind. They all bring slightly different things to the table

book publishers uk United Kingdom

12/16/2009 1:33:26 AM #

denver dui lawyer

I never hear about YAPS. YAPS (Yet another postscript) on Custom Excel for RS  - I want to try out your code... Smile

denver dui lawyer United States

1/25/2010 9:19:41 PM #

non surgican hair transplantations

Thanks a lot for this extremely cool article.

non surgican hair transplantations

2/2/2010 4:09:55 PM #

Extenze

You post saved me from a great trouble. I am very mush thankful to you for this.

Extenze United States

2/16/2010 2:20:41 PM #

ps3magic

great post, helped me a lot, i was searching for this for weeks now. great share. bookmarked!

ps3magic United States

2/24/2010 4:31:10 AM #

Car Rental &amp; Car Hire Gold Coast

Well, I never know those SSML codes and also how and where to use it.  Better if you provided some more description for the innocent people.

Car Rental & Car Hire Gold Coast India

2/25/2010 3:59:10 AM #

sleep dentist

I have the same issue, the only difference is that I divided my report into multiple pages (using the insert page brak after rectangles) and I need to name the sheets in Excel.Any help will be appreciated.

sleep dentist India

2/25/2010 11:22:15 AM #

&gt;L&lt;

GamesRadar.smith, if you're real, the original post in this series does exactly that.

>L< United States

2/28/2010 10:14:49 AM #

Karen Norman

I am fairly new to these excel scripts and find it fascinating, I now need to go and give it a go, thanks for some useful insight.

Karen Norman United States

3/19/2010 8:26:29 PM #

electric adjustable beds

I started to try looking for documentation on the topic, also for a tool to help me debug the problems there. Thanks so much for your sharing.

electric adjustable beds Canada

3/29/2010 3:45:28 AM #

custom usb

You have got some great posts in your blog. I will be visiting again.

custom usb United States

4/28/2010 1:15:28 PM #

Amazon Price Changes

SSML generation has always confused me a bit, this cleared some things up for me. Thank you for this.

Amazon Price Changes United States

5/22/2010 5:44:32 AM #

Voluntary Insurance

I really aprreciate your work.You had done a lot of hard work on the blog.good work

Voluntary Insurance United States

5/25/2010 9:13:21 AM #

Life Settlement

You had given me a lot of new ideas .i am really thankfull to you and to your team for the support.

Life Settlement United States

5/28/2010 6:27:16 AM #

apartamentos amoblados panama

I started to try looking for documentation on the topic, also for a tool to help me debug the problems there. Thanks so much for your sharing.

apartamentos amoblados panama United States

6/4/2010 5:02:17 AM #

Sterling Silver Necklaces

Thanks for taking this opportunity to discuss  this, I feel  fervently about this and I like learning about this subject.  If possible, as you gain information, please update  this blog with more information.  I have found it really useful.

Sterling Silver Necklaces United States

6/4/2010 5:57:50 AM #

Silver Key Necklace

Took me a lot of time to read all the comments, but I really liked the article. It was very helpful to me. It's always cool when you can not only be informed, but also entertained! I'm sure you had good time writing this post.

Silver Key Necklace United States

6/7/2010 11:56:55 PM #

massage

Very Good work, Keep the work going, I enjoyed reading the entire article and it made me happy....

massage United States

6/20/2010 4:26:20 AM #

best internet tv software

Do you have any additional info on this? Or maybe point me into the correct direction?

best internet tv software United States

7/14/2010 5:53:16 AM #

piano tutorial

it worked for me Lisa with the little change Tom suggested, thanks.

piano tutorial United Kingdom

7/20/2010 4:47:06 AM #

network media players

I'm glad you went through the trouble of writing this up and posting it. It really helped me.

network media players United States

7/24/2010 7:35:48 PM #

Wolf Jewelry

Absolutely fantastic article...custom excel is the best ;)

Wolf Jewelry United States

8/2/2010 2:58:14 AM #

Abu Dhabi Homes

I like your post & I will always be coming frequently to read more of your post. Thank you very much for your post once more.

Abu Dhabi Homes U.A.E.

8/7/2010 7:53:10 AM #

joint pain remedies

Fantastic article. Write reading it !

joint pain remedies United States

9/5/2010 12:05:21 AM #

bedding

12345123451234512345=101010101010101010101 is there simile between this?

bedding United States

9/6/2010 10:02:37 AM #

&gt;L&lt;

Probably not significant.  I could have used any characters at all!  The point is the number of characters, not the exact characters I chose.  I find it easiest to count them if I type "12345", that's all...

>L< United States

9/7/2010 12:30:03 AM #

Dubai Apartments

Valuable information! Looking forward to seeing your notes posted.

Dubai Apartments U.A.E.

9/13/2010 3:05:42 AM #

Guvy bracelet

It is a useful and great informations and i want to try using it for my programming work also to thank you for nice blog and great effort .

Guvy bracelet Egypt

9/13/2010 10:23:11 AM #

www.xn--onlinecasio-n5e.com/

Like the length of the tab name, this isn't documented anywhere that I could find.  So I only find out about illegal characters by trial.great posts in your blog. I will be visiting again.

www.xn--onlinecasio-n5e.com/ United States

9/13/2010 12:01:33 PM #

san diego injury attorney

It is easy to customize the Excel toolbar and menus. You can make your own menu commands that are most commonly....

    
  

san diego injury attorney United States

9/14/2010 4:09:14 AM #

crm software for

I like reading your articles. I absolutely enjoyed every little bit of it. I have you bookmark your blog to check out the new stuff in future.

crm software for United States

9/30/2010 12:22:04 AM #

Dover delaware

wow kind of interesting and informative post thanks a lot for sharing it..

Dover delaware United States

10/1/2010 5:47:47 AM #

Kook TV

that nice go ahead....

Kook TV United States

10/3/2010 6:17:13 AM #

water bottles

post saved me from a great trouble. I am very mush thankful to you for this.

water bottles United States

10/4/2010 11:02:24 AM #

Hospitals in Singapore

Custom Excel function to extract data from SQL Server Database. The usefulness of modem data capture, as the process to their needs.

Hospitals in Singapore United States

10/7/2010 10:09:55 PM #

Banner stands

pretty interesting post,nice....

Banner stands United States

10/15/2010 2:19:40 AM #

craigslist baltimore

nice post

craigslist baltimore United States

10/15/2010 7:37:35 AM #

Car Accessories, Car Seat Covers, Car Bulbs

Is this script compatible with the new Excel version?

Car Accessories, Car Seat Covers, Car Bulbs United States

10/23/2010 12:17:28 PM #

Fashion jewelry necklaces

Like the length of the tab name, this isn't documented anywhere that I could find.  So I only find out about illegal characters by trial.great posts in your blog. I will be visiting again.

Fashion jewelry necklaces Spain

10/25/2010 11:03:58 PM #

How to Care for Your Flowers

I wonder how you got so good.  This is really a fascinating blog, lots of stuff that I can get into.  One thing I just want to say is that your Blog is so perfect!

How to Care for Your Flowers United States

11/1/2010 8:53:01 AM #

Beertender B95

I am a programmer and i see your informations useful for me , than you .

Beertender B95 Egypt

5/17/2011 12:17:24 PM #

domowe piwa

Good stuff.

domowe piwa United States

5/31/2011 7:08:25 PM #

onlineloanresources.com

This is a very informative post! Job well done!

onlineloanresources.com United States

6/24/2011 2:18:41 PM #

beer

yes, now i know more about it

beer Italy

7/6/2011 8:26:06 AM #

Dave @ Toilets For Sale

great info. I am appalling with scripts, but your explanation has been really useful

Dave @ Toilets For Sale United States

7/7/2011 5:44:04 PM #

Christopher

I have struggled with that in the past and I know how that can be.  Glad to see that I am not the only one.

Thank you for the revisiting of the topic.  Maybe you can do so every 18 months or so.

Christopher

Christopher United States

Pingbacks and trackbacks (3)+

Add comment




  Country flag
biuquote
  • Comment
  • Preview
Loading