Perl Reading Excel sheet isssue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl Reading Excel sheet isssue
# 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:
# 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 Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Summing up the data from different excel sheet into one excel sheet

Hi Folks, Can you please advise for any script in unix such that for example , i have 3 different excel sheet at the location /ppt/gfr/exc so the name s of the excel sheet are 1excel.xslx 2excel.xslx 3excel.xslx now in these 3 different excel sheet there is lot of data for example each... (3 Replies)
Discussion started by: punpun66
3 Replies

2. Shell Programming and Scripting

Perl : to get all the hyperlinks from the xlsx sheet(hyperlinks not visible in excel sheet directly)

Hi folks, I have a requirement in perl to print all the hyperlink from the spreadsheet(xlsx). Spreadsheet contains few lines of hyperlink data (pic attached). P.S. Hyperlink is behind the data and not visible in excel sheet directly. Now using perl script I need to copy the hyperlinks in... (3 Replies)
Discussion started by: scriptscript
3 Replies

3. Shell Programming and Scripting

Perl : Deleting the records in the excel sheet

I have a excel sheet with contains the records as below.. also uploaded the input excelsheet and the output excel sheet(expected output). 322mpls32.net.xyz.comBW: 44.0 M Hrly Avg (IN /... (1 Reply)
Discussion started by: giridhar276
1 Replies

4. Shell Programming and Scripting

Perl : not capturing all the data from excel sheet

Hi folks, I am working on assignment that captures all the records(2 columns one column contains names and other contain date of birth) from excel sheet stored in a directory and checks for current date and month. If it matches current date and month then the matched records are printed as... (1 Reply)
Discussion started by: giridhar276
1 Replies

5. Programming

Excel sheet modification using perl module

Hi , can any one tell me,"How to extract the same format from existing excel file to new excel file " using Spreadsheet::WriteExcel or Spreadsheet::ParseExcel module ??? Example_pgm: Below program is used to read existing excel file..In this program "my $cell = $_;" line is used to... (0 Replies)
Discussion started by: kavi.mogu
0 Replies

6. Shell Programming and Scripting

Excel sheet modification using perl module

Hi , Is there any possibility to read excel sheet in column by column order ?...Thanks in advance,........ :confused: (1 Reply)
Discussion started by: kavi.mogu
1 Replies

7. Shell Programming and Scripting

Excel sheet modification using perl module

I need to insert new column to already existing file ..can any one help me..?? (6 Replies)
Discussion started by: kavi.mogu
6 Replies

8. Shell Programming and Scripting

Excel sheet modification using perl module

Is there any possibility to move the content from one cell to another cell (Excel sheet) using perl module? (3 Replies)
Discussion started by: kavi.mogu
3 Replies

9. Shell Programming and Scripting

How to change cell background in excel sheet using perl

I need to change a cell in an excel sheet to different background color using perl.I tried SaveParse, but was unable to get it Please help regarding this. Thanks and Regards, Neelam G https://www.unix.com/images/misc/progress.gif (0 Replies)
Discussion started by: gujrathinr
0 Replies

10. UNIX for Dummies Questions & Answers

Change the cell background in excel sheet using Perl

I need to change a cell in an excel sheet to different background color using perl. Please help regarding this. Thanks and Regards, Neelam G (1 Reply)
Discussion started by: gujrathinr
1 Replies
Login or Register to Ask a Question