Perl Reading Excel sheet isssue


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Old 10-30-2012
Perl Reading Excel sheet isssue

There is a perl scriptwhich will read Excel sheet and create one file(.v) .

Code:
Excel sheet::: 
     A              B   C   D
1  cpu_dailog   2   3   4



Perl will create the file(.v) like thsi :::

Code:
assert (cpu_dailog_iso ==2) ; 
assert (cpu_dailog_reset ==3);
assert (cpu_dailog_idle ==4);

My Requirement:::
If Row1+ColumnC (Value is 3 there) is having coloured background "Blue" , then i want to add comment . like this in generated file


Code:
assert (cpu_dailog_iso ==2) ; 
//assert (cpu_dailog_reset ==3);
assert (cpu_dailog_idle ==4);

Plz guys can any body help?
There are lot of signals. Its very pain to do it manually .

Quote:
//------------------------------------------Some part of the script---------------------------//
foreach $out_port (keys (%{$design{$ip_name}{output}})) {
if ($design{$ip_name}{output}{$out_port}{"reset_sig"} eq $reset_var) {
if (defined ($design{$ip_name}{output}{$out_port}{"single"})) {
print OUTPUT_FILE (" $ip_name\_level1_PRM_$out_port\_reset : assert \($out_port === 1\'h$design{$ip_name}{output}{$out_port}{\"reset_val\"}\)",
" else if\(assert_check_reset\) \$error\(\"$ip_name\_level1_PRM_$out_port\_reset_Assertion: incorrect reset value for $out_port +++ Xcel Value = 1\'h$design{$ip_name}{output}{$out_port}{\"reset_val\"} +++ RTL Value = %h\" ,$out_port \)\;\n");
} else {
$out_port_width = (($design{$ip_name}{output}{$out_port}{"bus_high"} - $design{$ip_name}{output}{$out_port}{"bus_low"}) + 1);
print OUTPUT_FILE (" $ip_name\_level1_PRM_$out_port\_reset : assert \($out_port === $out_port_width\'h$design{$ip_name}{output}{$out_port}{\"reset_val\"}\)",
" else if\(assert_check_reset\) \$error\(\"$ip_name\_level1_PRM_$out_port\_reset_Assertion: incorrect reset value for $out_port +++ Xcel Value = $out_port_width\'h$design{$ip_name}{output}{$out_port}{\"reset_val\"} +++ RTL Value = %h\" ,$out_port \)\;\n");
};
}
};

Last edited by naaj_ila; 10-30-2012 at 11:26 AM..
# 2  
Old 10-30-2012
Well, it might be easier to use Excel or LibreOffice to globally replace the blue background with a nice selective key prefix in the cell, and save it as tab separated text. Is this one of several xls format or xlsx ?
# 3  
Old 10-30-2012
My sample Excel spreadsheet, called "test_file.xlsx" looks like this -

Code:
  | A             | B   |   C   |   D   |
--+---------------+-----+-------+-------+
1 | cpu_dialog    | 2   |   3   |   4   |
--+---------------+-----+-------+-------+
2 | something_else| 20  |   30  |   40  |
--+---------------+-----+-------+-------+

and the background color of Cell C1 is blue.

Here's some Perl code:

Code:
c:\>
c:\>
c:\>REM Display the Perl program to process MS Excel workbook "test_file.xlsx"

c:\>
c:\>type read_excel.pl
#!perl -w
use strict;
use Win32::OLE;

$Win32::OLE::Warn = 3;              # die on errors
my $excelfile = 'test_file.xlsx';   # file to be read

my $Excel = Win32::OLE->GetActiveObject('Excel.Application')
            || Win32::OLE->new('Excel.Application', 'Quit');

my $Book = $Excel->Workbooks->Open($excelfile);
my $Sheet = $Book->Worksheets("Sheet1");

my $comment = "";
my @row_values;
my %suffix = qw (1 _iso 2 _reset 3 _idle);
foreach my $row (1..2) {
  foreach my $col ("a".."d") {
    my $range = $col.$row;
    push @row_values, $Sheet->Range($range)->{Value};
    if ($range eq "c1" and $Sheet->Range($range)->Interior->{ColorIndex} == 23) { # ColorIndex = 23 for Blue
      $comment = "//";
    }
  }
  foreach my $i (1..3) {
    printf ("%sassert (%s%s == %s);\n", $row==1 && $i==2 ? $comment : "", $row_values[0], $suffix{$i}, $row_values[$i]);
  }
  @row_values = ();
}

c:\>
c:\>
c:\>
c:\>REM Now run the Perl program

c:\>
c:\>perl read_excel.pl
assert (cpu_dialog_iso == 2);
//assert (cpu_dialog_reset == 3);
assert (cpu_dialog_idle == 4);
assert (something_else_iso == 20);
assert (something_else_reset == 30);
assert (something_else_idle == 40);

c:\>
c:\>
c:\>

tyler_durden
This User Gave Thanks to durden_tyler For This Post:
naaj_ila (11-02-2012)
# 4  
Old 10-31-2012
OK, xlsx,very interesting, a zip file full of xml files. I suppose the right late model perl classes can make it simple, but maybe not that simple. It looks like color can be by index or rgb.

Have it print state change and value discovery messages as it goes. Did it find the cell, find the color, and what colors did it find?
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Writing xml from excel sheet .xls using perl script omkar.jadhav Shell Programming and Scripting 12 03-17-2015 10:33 AM
Summing up the data from different excel sheet into one excel sheet punpun66 Shell Programming and Scripting 3 04-19-2014 01:33 PM
Perl CGI : unable to download the excel sheet from perl cgi page scriptscript Shell Programming and Scripting 2 06-10-2013 07:06 AM
Perl : to get all the hyperlinks from the xlsx sheet(hyperlinks not visible in excel sheet directly) scriptscript Shell Programming and Scripting 3 03-15-2013 11:53 AM
Uploading excel sheet to sharepoint portal using perl giridhar276 Shell Programming and Scripting 0 01-17-2013 05:26 AM
Copy Data from CSV file to Excel Sheet using Perl adisky123 Shell Programming and Scripting 6 01-02-2013 10:25 AM
Perl :Is it possible to read the excel 2007 sheet on unix machine using spredsheet::xlsx module giridhar276 Shell Programming and Scripting 2 09-21-2012 07:59 AM
Perl : Deleting the records in the excel sheet giridhar276 Shell Programming and Scripting 1 09-14-2012 01:01 PM
Perl : not capturing all the data from excel sheet giridhar276 Shell Programming and Scripting 1 08-01-2012 02:44 PM
Excel sheet modification using perl module kavi.mogu Programming 0 01-24-2012 12:12 AM
Excel sheet modification using perl module kavi.mogu Shell Programming and Scripting 1 01-07-2012 01:22 PM
Excel sheet modification using perl module kavi.mogu Shell Programming and Scripting 6 01-05-2012 12:48 AM
Excel sheet modification using perl module kavi.mogu Shell Programming and Scripting 3 12-28-2011 05:21 AM
How to change cell background in excel sheet using perl gujrathinr Shell Programming and Scripting 0 07-10-2008 03:01 AM
Change the cell background in excel sheet using Perl gujrathinr UNIX for Dummies Questions & Answers 1 07-09-2008 10:37 AM