Tuesday, September 18, 2007

XML or EXCEL

Hey Guys!

do you know, MS-Office 2003 supports XML strongly. It is very easy to create Excel by making a small XML file. Let me show you...



<?xml version="1.0"?>
<ss:Workbook xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
<ss:Worksheet ss:Name="Sheet1">
<ss:Table>
</ss:Table>
</ss:Worksheet>
</ss:Workbook>



This small code is enough to open the Excel Sheet.

Open a text file in notepad.
Write those lines in it and save as .XLS
Your excel sheet is ready.



------------- ADVANCED --------------


<?xml version="1.0"?>
<ss:Workbook xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
<ss:Worksheet ss:Name="Sheet1">
<ss:Table>
<ss:Row>
<ss:Cell>
<ss:Data ss:Type="String">Data Column</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">Data Column</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">Data Column</ss:Data>
</ss:Cell>
</ss:Row>
</ss:Table>
</ss:Worksheet>
</ss:Workbook>



The above example will create multiple rows


Following lines will help you re-size your columns as per your choice
<ss:column width="100">
<ss:column width="100">
<ss:column width="100">


Place them after <ss:Table> and before <ss:Row>


Soon, I will also tell how to add styles to your XML based spreadsheet

Monday, September 17, 2007

WYSIWYG in 1 step

Hey Guys...

Do you know about WYSIWYG editors???

What You See Is What You Get editors are HTML editors that can help you create HTML on the fly. There is a hidden trick for DIV tags which you can implement such editors in just 1 small step.

But this technique has a limitation...
It works on IE 6+ only. No firefox/netscape support available. :(

Well, just use contentEditable=true attribute in div tag.

Example...


<div contenteditable="true">
    The content goes here
</div>




Do it yourself now...


This Content is Editable. Try Me



Now this text is editable. Even CTRL+B and other such shortcuts work on this. You can also open any page, press CTRL+A to select it and press CTRL+V to paste on your new WYSIWYG editor. It will give you nice HTML.


So try it and have fun...

Monday, September 03, 2007

AJAX with HTML

Implementation of AJAX is very simple. You can have a single HTML page and run a huge ERP from there using AJAX.

All you need to know is
HTML, JAVASCRIPT, CSS

Entire process can be categorized as following....



Step 1. Send AJAX request to some server side page
Step 2. Sniff for response
Step 3. Show the response text

If you get into the implementation that these 3 steps are very easy to understand. Here's the explanation....

Step 1:

Create XMLHttpRequest Object. Now the catch here is that different browsers handle this thing differently. So use the following code that will help everywhere...


function ajaxFunction()
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
// Internet Explorer 6.0 +
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
// Internet Explorer 5.0 +
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
}





Now we have created an object for AJAX handling. Next we will call the page that contains data to be displayed. But before that, you must understand the onreadystatechange and readyState properties of XMLHttpRequest Object.

onreadystatechange is an event that is fired whenever state of xmlHTTP object is changed. In this event, the readyState property is set to some pre-defined values like

0: The request is not initialized
1: The request has been set up
2: The request has been sent
3: The request is in process
4: The request is complete

You need to call your function when onreadtstatechange event is fired. For this, you can write

onreadystatechange = function {

if(xmlHttp.readyState==4) {

document.myForm.LBL.value=xmlHttp.responseText; }


}

All you need is a textbox called LBL, which will hold the value recieved by this object. To recieve some value, you need some server side page and call it like this...

xmlHttp.open("GET","mypage.asp",true);
xmlHttp.send(null);

Well, you are done.

Surprise!!! All three steps are complete.

Yes! You are done with the basics of AJAX. Now just to summarize, I will write same code in combined form...



function ajaxFunction()
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
// Internet Explorer 6.0 +
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
// Internet Explorer 5.0 +
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
}

xmlHttp.open("GET","mypage.asp",true);
xmlHttp.send(null);

xmlHttp.onreadystatechange = function {

if(xmlHttp.readyState==4)
{
document.myForm.LBL.value=xmlHttp.responseText;
}
}