RSS
 

converting xls to csv

04 Jan

About xls2csv:

xls2csv – Is a script that converts xls files to csv. The author of this script is Ken Prows. This script is free so you can modify it, redistribute it under the same terms as Perl itself. This script can be downloaded from here: http://search.cpan.org/~ken/xls2csv-1.06/

xls2csv Options:

  • -x : filename of the source spreadsheet
  • -b : the character set the source spreadsheet is in (before)
  • -c : the filename to save the generated csv file as
  • -a : the character set the csv file should be converted to (after)
  • -q : quiet mode
  • -s : print a list of supported character sets
  • -h : print help message
  • -v : get version information
  • -W : list worksheets in the spreadsheet specified by -x
  • -w : specify the worksheet name to convert (defaults to the first worksheet)

E.g.
1. To list all worksheets:- xls2csv -W -x xlsfilename.xls
2. To convert a xls file to csv :- xls2csv -x EXCEL_FILE -b CHARSET -c CSV_FILE -a CHARSET (If xls is having multiple worksheets then by default it will process the first worksheet)
3. To convert a particular worksheet:- xls2csv –x xlsfilename.xls -c csvfilename.csv -w “worksheetname”

Converting all XLS worksheets to CSV:-
It can be done in following steps:-
1. Get the list of all the worksheets first (xls2csv -W -x xlsfilename.xls)
4. Then process the conversion for each worksheet (xls2csv –x xlsfilename.xls -c csvfilename.csv -w “worksheetname”)

Prerequisites

First Perl should be installed with following modules:-
1. Locale::Recode
2. Unicode::Map
3. Spreadsheet::ParseExcel
4. Spreadsheet::ParseExcel::FmtUnicode
5. Text::CSV_XS

For installation you can use CPAN :-

For Interactive Mode:-
perl -MCPAN -e shell;
For Batch Mode:-
use CPAN;
autobundle, clean, install, make, recompile, test

To install any module:

1. In interactive mode type: install , e.g. install Spreadsheet::ParseExcel

 
 

how https works

30 Sep

How HTTPS works?

HTTPS (Hyper text transfer protocol secure) works on HTTP protocol using SSL/TLS  (Secure Sockets Layer/ Transport Layer Security)   encryption layer. HTTPS runs on port 443 whereas HTTP runs on port 80. A HTTPS website contains a HTTPS certificate which enables the encryption. Each certificate contains Public and Private Keys , public keys are used for encryption and private keys are used for decryption.

The communication between the browser and HTTPS webpage happens in following steps:-

  1. Browser make a request for the HTTPS webpage
  2. HTTPS webpage sends a copy of it’s SSL certificate
  3. Browser continues if it finds the certificate as valid.
  4. The webpage sends a digitally signed acknowledgment to start communication over a secure encrypted channel.
  5. Now all the communication between the browser and the webpage take place in encrypted form.
 
 

apache questions

29 Sep

Q1: How to authenticate a user or access control in apache

Ans: It can be done in following way:-

1: Create a password file

2: configure it

1: Create a password file in apache: for this we have this command htpasswd -c /usr/local/apache/passwd/passwords username
where the passwords is the file containing the usernames and passwords in /usr/local/apache/passwd/ directory

  • -c should be used first time only or it will overwrite the file
  • for updating the file and adding new users we just need to omit -c from command like:- htpasswd /usr/local/apache/passwd/passwords use2

2: Configure it: For this add following lines in .htaccess file:-
AuthType Basic
AuthName “test only”
AuthUserFile /usr/local/apache/passwd/passwords
Require valid-user

 
 

php oops concepts

25 Sep

php oops concepts

Polymorphism

Polymorphism means many forms, in PHP it means that deciding which function should be called in runtime. In PHP polymorphism means inheritance and overriding functions.

e.g.

<?php
class ParentC
{
public function func1()
{
echo ‘<br>Parent class’;
}
}

class ChildC extends ParentC
{
public function func1()
{
echo ‘<br>Child class’;
}
}

class Poly
{
public function callFunc(ParentC $obj)
{
$obj->func1();
}
}

$childObj=new ChildC();
$polyObj=new Poly();
$polyObj->callFunc($childObj);
?>

PHP does not support compile time polymorphism, so it does not support operator overloading and function overloading.  Function overloading is not supported in PHP because in PHP we can not have two functions with the same name.

If we have any requirement like a function can have some optional parameters then we use func_get_arg() to get the parameters passed to the function.

so if we have a function say func1($arg1,$arg2){……} , then:-

func1(‘a’,'b’); //is valid

func1(‘a’,'b’,'c’,'d’); //is also valid

func1(‘a’);  //is invalid as the function requires at least two parameters

Encapsulation

Encapsulation is a technique for data hiding. Sometimes we have some private variables in the class so that they should not be modified/accessed from out side of the class and we do provide some public or protected functions in out class to use those variables in the way they are intended to be used, then this technique is called Encapsulation.

e.g.

<?php
class EncapExp
{
private $num1;
private $num2;

public function setNumbers($n1,$n2)
{
if(is_int($n1))
{
$this->num1=$n1;
}
else
{
echo ‘<br>’.$n1.’ is not a number’;  exit;
}

if(is_int($n2))
{
$this->num2=$n2;
}
else
{
echo ‘<br>’.$n2.’ is not a number’;  exit;
}
}

public function addNumbers()
{
return $this->num1+$this->num2;
}
}

$obj=new EncapExp();
$obj->setNumbers(2,3);
echo $obj->addNumbers();   //output: 5
$obj->setNumbers(2,’a');    // outpt: a is not a number

?>

so in the above example we can see that we are restricting the invalid (non-integer) values to assign to the variables.  If they would be public then one could assign non-integer values to them.

Inheritance

Objects of one class can acquire the properties of objects of other class using inheritance.

PHP doesn’t support multiple inheritance. So unlike JAVA we cant implement more than one interface.

Abstract Class

  1. Its not compulsory that an abstract class will have at least one abstract method or at least one non-abstract method
    1. e.g.  abstract class abs1{ public function fun1(){ echo “hi”; } }  is ok
    2. abstract class abs2{  abstract function fun2();  }  is ok
    3. abstract class abs3{   public function f1(){…..}  abstract protected function f2(); }   is also ok
  2. Abstract function can not be private

Interfaces

  1. Interfaces can not have protected or private declarations
  2. Interfaces can not have member variables

interface intFace1()

{

var $var1;

public function intFunct1();

}

will show an error like “Interfaces may not include member variables”

interface intFace1

{

protected function func1();

private function func2();

}

This will show error like  : Access type for interface method intFace1::func1() must be omitted


An interface can extends other interface

<?php
interface intFace1
{
public function func1();
}

interface intFace2 extends intFace1
{
public function func2();
}

class testA implements intFace2
{
public function func1()
{
echo ‘<br>func1′;
}

public function func2()
{
echo ‘<br>func2′;
}

}

$obj=new testA();
$obj->func1();
$obj->func2();

?>

An abstract class can also implement other interface

<?php

interface intFace1
{
public function func1();
}

abstract class absClass implements intFace1
{
public function func1()
{
echo ‘<br>func1 of abstract class ‘;
}
}
class testB extends absClass
{
}

$obj=new testB();
$obj->func1();

?>

An Abstract class can also extends other Abstract class

<?php
abstract class abs1
{
abstract function fun1();
}

abstract class abs2 extends abs1
{
abstract function fun2();
}

class testA extends abs1
{
function fun2()
{
echo ‘<br>fun2 of testA class’;
}

function fun1()
{
echo ‘<br>fun1 of testA class’;
}
}

$obj=new testA();
$obj->fun2();
$obj->fun1();
?>

 
 
 
Aha! Jokes

Exchange link     Add Site