Search This Blog

Wednesday, February 24, 2010

How to extract SWF Flash animation from Office Excel?

Besides watching Flash videos (FLV files), you should have seen or played some Flash animation game as well (SWF files, a.k.a. Shockwave flash).

And most of the time, you received SWF Flash animation in Microsoft Office document. Very likely, the SWF animation file is embedded in Office Excel.
The reason of embedding SWF animation file in Office document is probably that majority of users is running on Windows / MS Office, and MS Office can serve as a container to run or play the SWF file.

(If you received an un-embedded SWF file, you might able to open and play the SWF animation in web browser that installed with Shockwave Flash add-on)

While the SWF flash appears as an embedded file in Office Excel or Word, you might want to extract or retrieve the embedded SWF flash for your blog.

However, there is no intrinsic or built-in function to extract / retrieve embedded SWF Flash animation from Microsoft Office document files. This is definitely true, that you won’t able to find this wanted feature in Office 2007 as well!

So, how could you do that in case you’re really wanted to do so? OK, here we go:

How to extract SWF Flash animation from Office Excel?

A simple VBA program (a.k.a Visual Basic for Applications) can extract the embedded SWF Flash animation file in less than a minute or so.

The VBA / guide has been tested in Office 2003 Professional, and it should be working perfectly in any Office versions / editions too (e.g. the latest Office 2007), provided the Office system has installed the VBA components.
  1. Open a new Microsoft Excel document,
     
  2. Click the Tools menu, Marco, Visual Basic Editor. You can also press the ALT+ F11 hotkey to bring up the VBA editor,
     
  3. While in MS Visual Basic editor, click the View Code icon on the upper-left panel,
    VBA program to extract or retrieve embedded SWF Flash animation in Excel.
     
  4. Copy the VBA program source code at below here and paste it onto the VBA source code editor,
     
  5. Press F5 to execute the VBA source code,
     
  6. An Open File dialog box prompts you to select the Office Excel document that embed the SWF Flash animation file,
     
  7. A message box appears shortly after the Excel file is selected, with a message that says where the extracted SWF Flash animation file is saved in local hard disk!

The extracted SWF Flash animation file ended with SWF file extension, and it can be open/play in a web browser with Shockwave Flash addon (e.g. Flash9e.ocx in IE7).

The VBA source code used to extract or retrieve SWF Flash animation files that embedded in Microsoft Office Excel or Word:


Sub ExtractFlash()

Dim tmpFileName As String
Dim FileNumber As Integer
Dim myFileId As Long
Dim MyFileLen As Long
Dim myIndex As Long
Dim swfFileLen As Long
Dim i As Long
Dim swfArr() As Byte
Dim myArr() As Byte

tmpFileName = Application.GetOpenFilename("MS Office File (*.doc;*.xls), *.doc;*.xls", , "Open MS Office file")

If tmpFileName = "False" Then Exit Sub

myFileId = FreeFile

Open tmpFileName For Binary As #myFileId

MyFileLen = LOF(myFileId)

ReDim myArr(MyFileLen - 1)

Get myFileId, , myArr()

Close myFileId

Application.ScreenUpdating = False

i = 0

Do While i < MyFileLen

   If myArr(i) = &H46 Then

      If myArr(i + 1) = &H57 And myArr(i + 2) = &H53 Then

         swfFileLen = CLng(&H1000000) * myArr(i + 7) + CLng(&H10000) * myArr(i + 6) + CLng(&H100) * myArr(i + 5) + myArr(i + 4)

         ReDim swfArr(swfFileLen - 1)

         For myIndex = 0 To swfFileLen - 1
            swfArr(myIndex) = myArr(i + myIndex)
            Next myIndex
         Exit Do

      Else
            i = i + 3
      End If

   Else
        i = i + 1
   End If

Loop

myFileId = FreeFile

tmpFileName = Left(tmpFileName, Len(tmpFileName) - 4) & ".swf"

Open tmpFileName For Binary As #myFileId

Put #myFileId, , swfArr

Close myFileId

MsgBox "Save the extracted SWF Flash as [ " & tmpFileName & " ]"

End Sub

Wednesday, February 3, 2010

Invoking Groovy Scripts in JAVA

import java.io.File;
import groovy.lang.Binding;
import groovy.util.GroovyScriptEngine;
public class ScriptEngineEmbedGroovy
{
public static void main(String args[]) throws Throwable
{
String[] paths = {"C:\\groovy"};
GroovyScriptEngine gse = new GroovyScriptEngine(paths);
Binding binding = new Binding();
Object[] path = {"C:\\music\\mp3"};
binding.setVariable("args",path);
gse.run("Songs.groovy", binding);
}
}

Tuesday, February 2, 2010

SEO using Google AJAX

First thing to do is to sign-up and get your Google AJAX API.
There is a very useful “Developer’s Guide” and samples of the codes to play around in the playground.

In this blog, I am using the tabbed version of Google Search and here is how I accomplish. (At the time of writing this post, content of the blog was carried from another domain that’s why Google hasn’t indexed the pages yet. So that search results will be empty for this blog for a while.)
There are 3 pieces of code, 1 for the header section of your HTML, 1 for the search box and 1 for the results area.
Code for the header section;

This piece of code has to be in the head section of your HTML before the “” tag.

<blockquote>
<script src="http://www.google.com/jsapi?key=YourAPI" type="text/javascript">
</script>
<style type="text/css">
#searchResults .gsc-control { width : 500px; }
.search-control { margin: 20px; }
</style>
<script language="Javascript" type="text/javascript">
//<![CDATA[
// Load Search and Feed APIs
google.load("search", "1");
function OnLoad() {
var controlRoot = document.getElementById("searchResults");
// Create a search control
var searchControl = new GSearchControl();
searchControl.setLinkTarget(GSearch.LINK_TARGET_SELF);
searchControl.setResultSetSize(GSearch.LARGE_RESULTSET);

var searchFormElement = document.getElementById("searchControl");
var drawOptions = new GdrawOptions();
drawOptions.setSearchFormRoot(searchFormElement);
drawOptions.setDrawMode(GSearchControl.DRAW_MODE_TABBED);

// this is where you create your tabbed search results
// for every URL tab, you have to use the search address and the tab label
// This Blog
var searcher = new GwebSearch();
searcher.setSiteRestriction("http://www.lycie.com");
searcher.setUserDefinedLabel("Lycie");
searchControl.addSearcher(searcher);

// google also allow you to search the entire web
searcher = new GwebSearch();
searcher.setUserDefinedLabel("Web");
searchControl.addSearcher(searcher);

// search all other blogs
searcher = new GblogSearch();
searcher.setUserDefinedLabel("All blogs");
searchControl.addSearcher(searcher);

// draw it
searchControl.draw(controlRoot, drawOptions);

}
google.setOnLoadCallback(OnLoad, true);
//]]>
</script></blockquote>

There are 3 important things to do in this code.

1. Sign up and get your Google AJAX Search API. Put your API key where it says YourAPI in the code.

<script src="http://www.google.com/jsapi?key=YourAPI" type="text/javascript">
</script>

<style type="text/css">
2. CSS styling and tab creation are handled by Google. But if you want to use more styling use the CSS section in the code.

<style type="text/css">
#searchResults .gsc-control { width : 500px; }
.search-control { margin: 20px; }

</style>

3. Creating the tabs for the search results. Whenever somebody search my blog, search results will be displayed in 3 tabs, Lycie – results from my site, Web – results from the web and All Blogs – Results from all the blogs on the web.

Here is how I do. For every URL tab you want to create use the code below.

var searcher = new GwebSearch();
searcher.setSiteRestriction("http://www.lycie.com");
searcher.setUserDefinedLabel("Lycie");
searchControl.addSearcher(searcher);

There are 2 things to change in this piece of code in order to create new tabs.

searcher.setSiteRestriction("http://www.lycie.com");
searcher.setUserDefinedLabel("Lycie");

This is where you limit your search results. In other word, you tell Google to display results only from this URL. Here I say, limit this tab’s results for this URL “http://www.lycie.com” and use the label “Lycie”

Limiting your results from an URL means, only results from that URL will be displayed in that tab. This is very useful if you have different sections on your site. Common usage for this is Forums and Galleries. If you have a forum on your site, most likely its URL is www.example.com/forums. By using the code below, you can create another tab just for results from your forums.

searcher.setSiteRestriction("http://www.example.com/forums/");
searcher.setUserDefinedLabel("Forums");

Google does not only allow URL restrictions. Google also allows you to search the entire web for videos, blogs, news, images, books and patents. Check the AJAX API’s Playground for more coding tips.
Code for the search box

Put this into your HTML wherever you want to show your search box.


<div id="searchControl">
Loading...</div>
Code for the search results

Put this into your HTML wherever you want to show your search results.


<div id="searchResults">
Loading...</div>

That’s it. Enjoy your new search engine.

Java VarArgs

class VarGreeter {

public static void printGreeting(String... names) {
for (String n : names) {
System.out.println("Hello " + n + ". ");
}
}

public static void main(String[] args) {
printGreeting("vijay", "pittu");
}
}

Output
vijay
pittu

Java with out Main ()

public class withoutMain {
static {
System.out.println("Hello World!");
System.exit(0); // if you not put here, then error says no main
}
}

Monday, February 1, 2010

Avoid Ambiguity in Java Multiple Inheritance Interface

public interface interA
{
public int a = 5;

}

public interface interB
{
public int a = 10;

}

program 1
public class getInters implements interA, interB
{

public static void main (String args[])
{

}
}


//no error, the java support the way you see multiple interface..



program 2

public class getInters implements interA, interB
{

public static void main (String args[])
{
System.out.println ( interA.a );
System.out.println ( interB.a );
}
}

//no error,
/*
two interfaces can’t have methods and data members with the same signatures and names after all!

Answer for using Interface : Well technically they could provided you’re sure both interfaces will never be used on the same objects at the same time.
*/

Hit Counter


View My Stats