<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://philchuang.com/cs/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results matching tag 'javascript'</title><link>http://philchuang.com/cs/search/SearchResults.aspx?o=DateDescending&amp;tag=javascript&amp;orTags=0</link><description>Search results matching tag 'javascript'</description><dc:language>en-US</dc:language><generator>CommunityServer 2008 SP1 (Build: 30619.63)</generator><item><title>Automatically resizing Sharepoint Excel Web Parts</title><link>http://philchuang.com/cs/blogs/dev/archive/2010/04/28/automatically-resizing-sharepoint-excel-web-parts.aspx</link><pubDate>Wed, 28 Apr 2010 18:51:00 GMT</pubDate><guid isPermaLink="false">5be18640-eccb-47b9-8b04-4ed791bb5d95:1034</guid><dc:creator>philchuang</dc:creator><description>&lt;p&gt;If you&amp;#39;ve ever done excel web parts in sharepoint, you know that most of the time they turn out ugly, due to the fact that they&amp;#39;re rendered in an iframe and therefore the browser doesn&amp;#39;t resize the container to fit the content.&lt;/p&gt;
&lt;p&gt;So I went googling, and found Paul Grenier&amp;#39;s article &lt;a target="_blank" href="http://www.endusersharepoint.com/2009/01/05/jquery-for-everyone-dynamically-sizing-excel-web-parts/" title="http://www.endusersharepoint.com/2009/01/05/jquery-for-everyone-dynamically-sizing-excel-web-parts/"&gt;JQuery for Everyone: Dynamically Sizing Excel Web Parts&lt;/a&gt;.&amp;nbsp;&amp;nbsp; That got me started, but it didn&amp;#39;t quite work so I had to hack it until it did.&lt;/p&gt;
&lt;p&gt;I also adapted the code to resize charts&amp;nbsp;instead of just&amp;nbsp;tables.&lt;/p&gt;
&lt;p&gt;What you&amp;#39;re going to want to do is edit the page where you want the resizing to happen, add in a content editor web part, and paste the following code into the source editor.&lt;/p&gt;
&lt;pre class="brush: js;"&gt;&amp;lt;script src=&amp;quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js&amp;quot; type=&amp;quot;text/javascript&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;
$(function () { // resizes excel webparts
	$(&amp;quot;td[id^=&amp;#39;MSOZoneCell_WebPart&amp;#39;]&amp;quot;).each (function (i, e) {
		var findIframe = $(e).find (&amp;quot;iframe:first&amp;quot;);
		if (findIframe &amp;amp;&amp;amp; findIframe.attr (&amp;quot;scriptforiframecontent&amp;quot;))
			bindEwaLoaded (&amp;quot;#&amp;quot;+e.id);
	});
});

function bindEwaLoaded(obj) { // bind event to the web part
	$(obj).bind (&amp;quot;ewaLoaded&amp;quot;, function (e) {
		var b = $(e.target).find (&amp;quot;iframe:first&amp;quot;).attr (&amp;quot;postedbackalready&amp;quot;);
		if (b == undefined) // loop until iframe is ready
			setTimeout (function() { $(e.target).trigger (&amp;quot;ewaLoaded&amp;quot;); }, 1000);
		else // try to resize now
			ewaSetSize (e.target);
	}).trigger (&amp;quot;ewaLoaded&amp;quot;); // first trigger now
}

function ewaSetSize(obj) { // resize elements
	// configure paddings
	var excelObjectWidthPadding = 50;
	var excelObjectHeightPadding = 50.
	var w, h, div1, div2;
	var e = $(obj).find (&amp;quot;iframe:first&amp;quot;).contents().find (&amp;quot;table.ewrnav-invisibletable-nopadding:last&amp;quot;);
	if (e.length != 0) { // excel table
		w = e.width ();
		h = e.height ();
		div1 = $(obj).find (&amp;quot;table:first&amp;gt; tbody:first&amp;gt; tr:eq(1)&amp;gt; td&amp;gt; div&amp;gt; div&amp;quot;);
		div2 = $(div1).find (&amp;quot;table:first&amp;gt; tbody:first&amp;gt; tr:eq(1)&amp;gt; td&amp;gt; div&amp;quot;);
	} else {
		e = $(obj).find (&amp;quot;iframe:first&amp;quot;).contents().find (&amp;quot;div.ewrchart-img-div&amp;quot;);
		if (e.length != 0) { // excel chart
			w = e.width ();
			h = e.height ();
			div1 = $(obj).find (&amp;quot;table:first&amp;gt; tbody:first&amp;gt; tr:eq(0)&amp;gt; td&amp;gt; div&amp;gt; div&amp;quot;);
			div2 = $(div1).find (&amp;quot;table:first&amp;gt; tbody:first&amp;gt; tr:eq(1)&amp;gt; td&amp;gt; div&amp;quot;);
		}
	}

	if (w == 0 || w == undefined) { // loop until content is ready
		setTimeout (function() { ewaSetSize (obj); }, 1000);
	} else { // do resize
		w += excelObjectWidthPadding;
		h += excelObjectHeightPadding;
		div1.width (w);
		div2.height (h);
	}
}
&amp;lt;/script&amp;gt;
&lt;/pre&gt;
&lt;p&gt;Once that&amp;#39;s done, change the Appearance &amp;gt; Chrome Type to &amp;quot;None&amp;quot;.&amp;nbsp;&amp;nbsp; You can also configure excelObjectXXXXPadding to your liking.&lt;/p&gt;</description></item></channel></rss>