Functions of esProc/R/Python/Perl in Structured Data Process by Comparison :Chapter 18.Writing to Excel

esProc

It can be written out with one statement, and you can specify the field name, sheet name to be exported.

  =file(“d:/data.xls”).exportxls(tbl,id:id,name:name,score:score,…;”sheet1″)       

Perl

  #!perl

  use strict;

  use Win32;

  useCwd; 

  use Win32::OLE qw(in with); 

  use Win32::OLE::Const ‘Microsoft Excel’; 

  $Win32::OLE::Warn = 3;                             

 

  my $Excel = Win32::OLE->GetActiveObject(‘Excel.Application’) 

      || Win32::OLE->new(‘Excel.Application’, ‘Quit’); 

  use Encode; 

 

  my $outexcel1=”d:/out.xls”;

  my $Book = $Excel->Workbooks->Open(“$outexcel1”) or die “Could not open the   $outexcel1 !!!\n”; 

  my $Sheet = $Book->Worksheets(1); 

  my @carts=([173744,”aaa”,14],

                         [173745,”aaa”,18],

                        [173746,”bbb”,13],);

  my $row=1;

  for each(@carts) 

  { 

    $Sheet->Cells($row,1)->{‘Value’}=$_->[0];  # Only write out cell by cell

    $Sheet->Cells($row,2)->{‘Value’}=$_->[1]; 

    $Sheet->Cells($row,3)->{‘Value’}=$_->[2]; 

    $row++;

  } 

  $Book->Close;

Python

  from pyExcelerator import *

    w = Workbook()     #Create a workbook

  ws = w.add_sheet(‘sheet1’)     # Create a worksheet

    a=[[1,”a”],[3,”b”],[5,”c”],[7,”d”]]

    for i in range(0,len(a)):

         ws.write(i,0)=a[i][0]

         ws.write(i,1)=a[i][1]

    w.save(‘d:/out.xls’)     #Save it

R

After having looked for a long time, by searching from a number of official Webs and Help documents, no any approach could be available for exporting the .xls file, but only one for .txt and .csv files. esproc_r_perl_python_18

Advertisements

About datathinker

a technical consultant on Database performance optimization, Database storage expansion, Off-database computation. personal blog at: datakeywrod, website: raqsoft
This entry was posted in esProc/R/Python/Perl, Structured Data Process and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s