Saturday, 2 February 2013

Convert worksheets into csv files

I would like to share a macro with you that convert multiple sheets into multiple csv file within on click.

For this you need MS OFFICE 1997 or Higher version and window system.

Following are the instructions for convert xls ito csv.

1) Open your xls file in ms excel.
2) Press (ALT+F8), a popup will open.
3) type a name like "ExportSheetsToCSV" and click on "create" button.
4) Now new window will open, delete all data and past following data.
Sub ExportSheetsToCSV()
Dim wSheet As Worksheet
Dim csvFile As String
For Each wSheet In Worksheets
On Error Resume Next
wSheet.Copy
csvFile = CurDir & "\" & wSheet.Name & ".csv"
ActiveWorkbook.SaveAs Filename:=csvFile, FileFormat:=xlCSV, CreateBackup:=True
ActiveWorkbook.Saved = True
ActiveWorkbook.Close
Next wSheet
End Sub


5) Now click on "Run" @ the top.
6) You can get all your csv files from the "c:\users\{username}\my documents\";



Sunday, 27 January 2013

Regular Expressions PHP/Javascript

MetaCharacter: It is special chacter(s) which have special meaning in Regular Expression.

For Example:
*, ., /, \, ? and ^.

Sr
Meta character
Desctiption
1
[ ]
Match any character within [phc]
Means find “p” OR “h” OR “c”
2
-
Range
a-z means a to z(a,b,c, ... z)
0-0 means 0 to 9 (0,1,2,3,4,5,6,7,8,9)
A-Z means A to Z(A,B,C,D ..... Z)
3
^
Caret It means start with a character
For example: ^ab (start with “a”)

Inside the bracket if have opposite meaning.
For example: [^a](must not start with “a”)

4
$
End with character
For Example
Abc$ means end with “c”
5
.
The . (period) means any character(s) in this position,
For example, ph. will find php, php-tutorial and php-tutorial-php but not aphp because it has no following character
6
?
Matches the preceding character 0 or 1 times only.
For example:
colou?r will find both color (0 times) and colour (1 time).
7
*
Matches the preceding character 0 or more times.
For example:
tre* will find tree (2 times) and tread (1 time) and trough (0 times).
8
+
Matches the previous character 1 or more times.
For example:
tre+ will find tree (2 times) and tread (1 time) but NOT trough (0 times).
9
{n}
Preceding character, or character range, n times exactly.
For example:
find a local phone number we could use [0-9]{3}-[0-9]{4} which would find any number of the form 723-4567 OR 132-3234 OR 214-3433.
10
()
To group a character.
For Example:
(php), will find the “php” only.
11
|
Vertical bar used for OR
(a|c) find either “a” OR “c”
12
\d
any character in the range 0 – 9
13
\D
Any character not in between 0-9
14
\s
Whitespace or tab
15
\S
Not whitespace or tab
16
\w
Alphanumeric characters (a-z, 0-9, A-Z)
17
\W
Not alphanumeric character (a-z, 0-9, A-Z)