Script solution - running Excel macro in SLES


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script solution - running Excel macro in SLES
# 1  
Old 11-15-2016
Script solution - running Excel macro in SLES

Hello all,
I'm here again with new trouble. I need to find any possible way to apply excel macro on excel file in SLES server, or to convert that macro somehow.

Could you please share your ideas, and help me with this? Thank you in advance

ps (attached macro is with changed extension, because xlsm not allowed)
# 2  
Old 11-17-2016
Or maybe it is possible to do this without macro. If column C (ringnoanswer) is equal with column C (exitwithtimeout), then write in new sheet Columns F,G,I from RingNoAnswer

Last edited by bigbrobg; 11-17-2016 at 03:54 PM..
# 3  
Old 11-17-2016
It seems converting some EXCEL macro to a shell script is not too attractive in these fora. May I propose a different approach: If you post the two sheets as .csv files (in fact, text files) and care- and detailfully describe the check/compare actions needed, chances are someone comes up with a shell/sed/awk script that does what you need...
This User Gave Thanks to RudiC For This Post:
# 4  
Old 11-17-2016
Or, in short, show the data you have, and then, show the data you want, and explain how they're related.
These 3 Users Gave Thanks to Corona688 For This Post:
# 5  
Old 11-17-2016
I have two sheets:

sheet one - ringnoanswer event:

Code:
Day   Start Date   Start Time   End Date   End Time   Queue   Operator   Issue   WaitTime       
Mon    07 Nov 2016    09:12:48 EST    07 Nov 2016    09:13:10 EST   2041   Djamila Millien   RINGNOANSWER   20000       
Mon    07 Nov 2016    09:32:19 EST    07 Nov 2016    09:32:41 EST   2041   Djamila Millien   RINGNOANSWER   20000       
Mon    07 Nov 2016    09:35:48 EST    07 Nov 2016    09:36:11 EST   2021   Kimberly Paz   RINGNOANSWER   20000       
Mon    07 Nov 2016    09:39:15 EST    07 Nov 2016    09:39:40 EST   2041   Djamila Millien   RINGNOANSWER   20000       
Mon    07 Nov 2016    10:17:11 EST    07 Nov 2016    10:17:41 EST   2081   Deidra Wright   RINGNOANSWER   20000

sheet two - exitwithtimeout event:

Code:
Day   Start Date   Start Time   End Date   End Time   Queue   Issue                             
  Mon    07 Nov 2016    09:12:48 EST   07 Nov 2016    09:13:41 EST   2041   EXITWITHTIMEOUT   30       
  Mon    07 Nov 2016    09:16:42 EST   07 Nov 2016    09:17:41 EST   2081   EXITWITHTIMEOUT   30       
  Mon    07 Nov 2016    09:39:15 EST   07 Nov 2016    09:40:11 EST   2041   EXITWITHTIMEOUT   30       
  Mon    07 Nov 2016    10:17:11 EST   07 Nov 2016    10:17:41 EST   2081   EXITWITHTIMEOUT   30

I need to check column (start time) in both sheets. If there is match, I need to have output like this:
Code:
RNA Queue   RNA Operator   RNA WaitTime       
2041   Djamila Millien   20000      
2041   Djamila Millien   20000       
2081   Deidra Wright   20000


Currently I have this script that I'm using to generate excel file in SLES

Code:
#!/usr/bin/perl
use strict;
use warnings;
use Spreadsheet::WriteExcel;
use Spreadsheet::WriteExcel::Formula;
use Excel::Template;
use Text::CSV_XS;

my $name = 'call_report.xls';
my $file_ring = "/var/log/asterisk_agents_log/ringnoanswer_strip.log";
my $file_exitempty = "/var/log/asterisk_agents_log/exitempty_strip.log";
my $file_exitempty_of = "/var/log/asterisk_agents_log/exitempty-of_strip.log";
my $file_exittimeout = "/var/log/asterisk_agents_log/exitwithtimeout_strip.log";
my $file_exittimeout_of = "/var/log/asterisk_agents_log/exitwithtimeout-of_strip.log";

my $workbook = Spreadsheet::WriteExcel->new("/var/log/asterisk_agents_log/$name");

my $ringnoanswer = $workbook->addworksheet("RingNoAnswer");
my $exitempty = $workbook->addworksheet("ExitEmpty"); 
my $exitempty_of = $workbook->addworksheet("ExitEmpty-OF");
my $exitwithtimeout = $workbook->addworksheet("ExitWithTimeout");
my $exitwithtimeout_of = $workbook->addworksheet("ExitWithTimeout-OF");
my $calc = $workbook->addworksheet("Calc");

my @array_ring   =   ( 'Day','Start Date','Start Time', 'End Date','End Time', 'Queue', 'Operator', 'Issue', 'WaitTime' );
my @array_exittimeout   =   ( 'Day','Start Date','Start Time', 'End Date','End Time', 'Queue', 'Issue', '' );
my @array_exittimeout_of   =   ( 'Day','Start Date','Start Time', 'End Date','End Time', 'Queue', 'Issue', '' );
my @array_exitempty   =   ( 'Day','Start Date','Start Time', 'End Date','End Time', 'Queue', 'Issue' );
my @array_exitempty_of   =   ( 'Day','Start Date', 'Start Time', 'End Date', 'End Time', 'Queue', 'Issue' );
my @calc = ('RNA Queue','RNA Operator','RNA WaitTime', '', 'RNA Operator', 'Count');

my %cf = (
  font => 'Arial',
  border => 1,
  border_color => 'black'
  );

my %bold = (
  bold => 1
  );

my %ch = (
  align => 'center',
  valign => 'center',
  font => 'Arial',
  size => 11,
  border => 1, 
  border_color => 'black',
  bg_color => 'yellow'
 );

my $ch = $workbook->addformat(%ch, %bold); # header
my $cn = $workbook->addformat(%cf, size => 10); # normal text
my $cs = $workbook->addformat(%cf, size => 8); # small text

$ringnoanswer->autofilter('A1:I1');
$exitempty->autofilter('A1:G1');
$exitempty_of->autofilter('A1:G1');
$exitwithtimeout->autofilter('A1:H1');
$exitwithtimeout_of->autofilter('A1:H1');
$calc->autofilter('A1:F1');

set_columns($ringnoanswer, "A",
  [5, 16, 13, 16, 13, 45, 15, 15, 12],
  [$cn, $cn, $cn, $cn, $cn, $cn, $cn, $cn, $cn]);

set_columns($exitempty, "A",
  [5, 16, 13, 16, 13, 45, 13],
  [$cn, $cn, $cn, $cn, $cn, $cn, $cn]);

set_columns($exitempty_of, "A",
  [5, 16, 13, 16, 13, 25, 13],
  [$cn, $cn, $cn, $cn, $cn, $cn, $cn]);

set_columns($exitwithtimeout, "A",
  [5, 16, 13, 16, 13, 45, 20, 3],
  [$cn, $cn, $cn, $cn, $cn, $cn, $cn, $cn]);

set_columns($exitwithtimeout_of, "A",
  [5, 16, 13, 16, 13, 45, 20, 3],
  [$cn, $cn, $cn, $cn, $cn, $cn, $cn, $cn]);

set_columns($calc, "A",
  [15, 25, 20, 40, 25, 5],
  [$cn, $cn, $cn, $cn, $cn, $cn]);

$ringnoanswer->write('A1', [ @array_ring ], $ch);
$exitempty->write('A1', [ @array_exitempty ], $ch);
$exitempty_of->write('A1', [ @array_exitempty_of ], $ch);
$exitwithtimeout->write('A1', [ @array_exittimeout ], $ch);
$exitwithtimeout_of->write('A1', [ @array_exittimeout ], $ch);

$calc->write('A1', [ @calc ], $ch);
$calc->write('A3', 1.2345);
$calc->write('A4', '=SIN(PI()/4)');
$calc->write('C2',  'internal:ringnoanswer!B1');
$calc->write('D5', '=SUM(1, 2, 3)'); # Okay

$calc->write('D6', 1, '=SUM(1, 2, 3)');

write_from_log($ringnoanswer, $file_ring);
write_from_log($exitempty, $file_exitempty);
write_from_log($exitempty_of, $file_exitempty_of);
write_from_log($exitwithtimeout, $file_exittimeout);
write_from_log($exitwithtimeout_of, $file_exittimeout_of);

$ringnoanswer->activate(); # I'd like the second worksheet to be active

$workbook->close();  # play nice
exit(0);

print_setup($ringnoanswer);
print_setup($exitempty);
print_setup($exitempty_of);
print_setup($exitwithtimeout);
print_setup($exitwithtimeout_of);
print_setup($calc);

sub print_setup {
  my $exitempty = shift;
  $exitempty->set_landscape();
  $exitempty->center_horizontally();
  $exitempty->set_margins_LR(0.25);
  $exitempty->set_margin_top(0.5);
  $exitempty->set_margin_bottom(0.36);
  $exitempty->set_footer('&L&D&R&P of &N', 0.17);
  $exitempty->hide_gridlines();
}


sub set_columns {
  my ($ws, $col, $width, $format, $hidden) = @_;
  for (my $i=0; $i < @$width; $i++) {
    my $column = "$col:$col";
    $ws->set_column($column, $$width[$i], $$format[$i], $$hidden[$i]);
    $col++;
  }
}

sub write_from_log {
  my ($worksheet, $file) = @_;
  my $csv = Text::CSV_XS->new({
     'quote_char'  => '', # what?  no quote character?  you got it!
     'escape_char' => '\\', # a backslash
     'sep_char'    => '|',
     'binary'      => 0
   });

  my $row = 1;
  open (CSVFILE, "<", $file) || die "Unable to open $file for reading: $!, stopped";
  while (<CSVFILE>) {
    if ($csv->parse($_)) {
        my @Fld = $csv->fields;
        my $col = 0;
        my $keep = 1;
         if ($keep) {
           foreach my $token (@Fld) {
            if ($token =~ /^<img/) {
              $token =~ /<img src="(.*)" loc="(.*)">/i;
              my ($img, $loc) = ($1, $2);
              $worksheet->insert_bitmap($loc, $img);
            } else {
              $worksheet->write($row, $col, $token);
            }
            $col++;
          }
        }
        $row++ if ($keep);
    } else {
      my $err = $csv->error_input;
      print "Text::CSV_XS parse() failed on argument: ", $err, "\n";
    }
  }
}


Last edited by bigbrobg; 11-17-2016 at 04:10 PM..
# 6  
Old 11-17-2016
Those are not .csv - files. Howsoever, try

Code:
awk '
NR == FNR               {T[$2,$3,$4,$5]
                         next
                        }
FNR == 1                {print "RNA Queue   RNA Operator   RNA WaitTime"
                         next
                        }

($2,$3,$4,$5) in T      {print $12, $13, $14, $16
                        }
' file2 file1
RNA Queue   RNA Operator   RNA WaitTime
2041 Djamila Millien 20000
2041 Djamila Millien 20000
2081 Deidra Wright 20000

This User Gave Thanks to RudiC For This Post:
# 7  
Old 11-19-2016
This works very well.
How I can make it write output if there is RingNoAnswer between Start-End time of ExitWithTimeout?

Like this:
EXITWITHTIMEOUT

Code:
17 Nov 2016,10:06:07 EST,17 Nov 2016,10:06:59 EST,2031,EXITWITHTIMEOUT,30

RINGNOANSWER

Code:
17 Nov 2016,10:05:53 EST,17 Nov 2016,10:06:29 EST,2021,Traci Dingman,RINGNOANSWER,20000

Output:
Code:
2021    Traci Dingman    20000


Last edited by bigbrobg; 11-19-2016 at 03:01 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Converting macro to bash script

Gents, Please can you help me with this. When column 49 == 2 Before X 4714 14710 69445.00 19257.001 1218 12271 69596.00 19460.00 19478.001 X 4714 14710 69445.00 19257.001 1228 12292 69596.00 19480.00 19480.001 After X 4714 14710 69445.00 19257.001 1218... (1 Reply)
Discussion started by: jiam912
1 Replies

2. Shell Programming and Scripting

Script to generate Excel file or to SQL output data to Excel format/tabular format

Hi , i am generating some data by firing sql query with connecting to the database by my solaris box. The below one should be the header line of my excel ,here its coming in separate row. TO_CHAR(C. CURR_EMP_NO ---------- --------------- LST_NM... (6 Replies)
Discussion started by: dani1234
6 Replies

3. Shell Programming and Scripting

Perl script to Merge contents of 2 different excel files in a single excel file

All, I have an excel sheet Excel1.xls that has some entries. I have one more excel sheet Excel2.xls that has entries only in those cells which are blank in Excel1.xls These may be in different workbooks. They are totally independent made by 2 different users. I have placed them in a... (1 Reply)
Discussion started by: Anamika08
1 Replies

4. Shell Programming and Scripting

Invoke a script in UNIX using Excel Macro

Hi, I am using Send Keys to connect to UNIX server and invoke a script . Is there an alternate way to connect to UNIX server using Excel macro and invoke a UNIX Shell script? Anu (2 Replies)
Discussion started by: anandita.jha
2 Replies

5. SuSE

SLES 9 vs SLES 11 hard drive cache read timings are diffrent

Can anyone give me a little clue on why the hard drive cache read timings on sles 9 is better then sles 11? The same hardware was used in both test. I even deleted the ata_generic module from initrd. The speed difference is 10MB vs 5 MB Thanks (1 Reply)
Discussion started by: 3junior
1 Replies

6. Programming

Make-question - redefine a macro, using another macro..?

I think there is no problem to use any macro in a new macro definishion, but I have a problem with that. I can not understand why? I have a *.mak file that inludes file with many definitions and rules. ############################################## include dstndflt.mak ... One of the... (2 Replies)
Discussion started by: alex_5161
2 Replies

7. Shell Programming and Scripting

How to launch a Csh shell script using Excel Macro ?

Hi all. I need to use excel macro at my desktop to launch a csh script which is in a solaris environment. What is the code that i can use in macro to help me with that ? Basically, the code need to telnet or ftp to the solaris environment and just run the script and the macro will output in an... (1 Reply)
Discussion started by: Raynon
1 Replies

8. UNIX for Dummies Questions & Answers

macro on shell script ?

in shifts we used to run a script where in we need to choose from different options. for example the first part would go like this: ======== menu ======== 1)blah 2)blah blah 3)blah blah blah you have chosen: then after that a series of multiple choice so on and so forth...what i would... (4 Replies)
Discussion started by: inquirer
4 Replies
Login or Register to Ask a Question