Question : A Perl Spreadsheet Problem

Hi,

This is related to my earlier problem today. Here instead of hard-coding the query I am putting them into an excel sheet and reading it. The excel sheet is attached. But the output excel sheet is not getting generated with any rows, it is blank. Where am I going wrong?

Any help, as usual, really appreciated..
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
#!/usr/bin/perl5.10 -w

use warnings;
use Spreadsheet::WriteExcel::Big;
use Spreadsheet::ParseExcel;
use strict;
use IO::Scalar;
use Data::Dumper;
use DBI;
use DBD::MSDB2;


my $generated_file;

print "\n\nFinding your Baseline Posting file name: ";
my $dir = "/ms/user/s/sayantag/Posting_ETL";
chdir($dir);
$generated_file = `ls -t /ms/user/s/sayantag/Posting_ETL| head  -2| tail -1`;
chomp $generated_file ; 
print "$generated_file" . "\n";

print "\n\nFinding your Generated Posting file name: ";
$generated_file = substr ($generated_file, 0, 15);
print "$generated_file" . "\n";

my $xls_file = '/ms/user/s/sayantag/Posting_ETL/'. $generated_file . '.xls';
print "$xls_file\n";


my $workbook  = Spreadsheet::WriteExcel::Big->new($xls_file);
my $worksheet = $workbook->addworksheet("Posting Journal Entries");
my $worksheet1 = $workbook->addworksheet("Authentication");

my $format1 = $workbook->add_format();
my $format2 = $workbook->add_format();
my $format3 = $workbook->add_format(num_format => 'mm/dd/yy');


$format1->set_size(12);
$format1->set_bold();
$format1->set_color('blue');
$format1->set_align('center');
$format1->set_bg_color('yellow');

#$format2->set_num_format ('General');

############# Define WorkBook for SQL Queries ###############################

my $sql_parser   = Spreadsheet::ParseExcel->new();
my $sql_workbook = $sql_parser->parse("/ms/user/s/sayantag/SQL_Queries.xls");
my $sql_worksheet;

############################################################################

my $col=0;
my $row=0;

foreach my $i(

 "JRNL_ID"
,"ACCTNG_PERIOD_ID"
,"FCP_ID"
,"LDGR_TYPE_CDE"
,"BA_HRCHY_ID"
,"BA_NID"
,"LE_HRCHY_ID"
,"LE_NID"
,"REGION_HRCHY_ID"
,"REGION_NID"
,"ASSET_ID"
,"QTP_KEY_ID"
,"CHANGE_CTGRY_ID"
,"ELIMINATION_ID"
,"SRC_ID"
,"JRNL_VAL"
,"EFFECTIVE_DTE"
,"RULE_ID"
,"JRNL_SET_ID"
,"CCY"
,"TRANSLATED_CCY"
,"UOM_CCY"
,"RUN_GROUP_ID"
,"BA_CNTRPTY_ID"
,"INTERCPNY_CNTRPTY_ID"
,"REGION_CNTRPTY_ID"
,"TICKET_REF_NO"
,"MASTER_TICKET_REF_NO"
,"HEADER_ID"	   

)

{

$worksheet->write(0, $col++, $i, $format1);

}

################## Accesing Query from SQL Queries WorkBook #####################

for  $sql_worksheet ( $sql_workbook->worksheets() ) {

my ( $row_min, $row_max ) = $sql_worksheet->row_range();
my ( $col_min, $col_max ) = $sql_worksheet->col_range();

 for my $row ( $row_min .. $row_max ) {##First for##
 for my $col ( $col_min .. $col_max ) {##Second for##
   my $cell = $sql_worksheet->get_cell( $row, $col );
     if ($col==0 && $row !=0 && ($sql_worksheet->get_cell($row, 0) eq "Query1"))  { 
       $col++;
       my $query =  $sql_worksheet->get_cell($row, $col)->value;
##############################################################################
my $dbh = DBI->connect('dbi:MSDB2:NQ200001', '', '', { 'RaiseError' => 1 }) or 
          die "Can't connect to database: $DBI::errstr";

my $sql = "$query";



my $sth = $dbh->prepare($sql);

$sth->execute();



$row = 1;

while (my $a = $sth->fetchrow_hashref()) {

$worksheet->write($row,0, (defined($a->{"JRNL_ID"})? $a->{"JRNL_ID"} : '[NULL]'),  $format2);
$worksheet->write($row,1, (defined($a->{"ACCTNG_PERIOD_ID"})? $a->{"ACCTNG_PERIOD_ID"} : '[NULL]'), $format2);
$worksheet->write($row,2, (defined($a->{"FCP_ID"})? $a->{"FCP_ID"} : '[NULL]'), $format2);
$worksheet->write($row,3, (defined($a->{"LDGR_TYPE_CDE"})? $a->{"LDGR_TYPE_CDE"} : '[NULL]'), $format2);
$worksheet->write($row,4, (defined($a->{"BA_HRCHY_ID"})? $a->{"BA_HRCHY_ID"} : '[NULL]'), $format2);
$worksheet->write($row,5, (defined($a->{"BA_NID"})? $a->{"BA_NID"} : '[NULL]'), $format2);
$worksheet->write($row,6, (defined($a->{"LE_HRCHY_ID"})? $a->{"LE_HRCHY_ID"} : '[NULL]'), $format2);
$worksheet->write($row,7, (defined($a->{"LE_NID"})? $a->{"LE_NID"} : '[NULL]'), $format2);
$worksheet->write($row,8, (defined($a->{"REGION_HRCHY_ID"})? $a->{"REGION_HRCHY_ID"} : '[NULL]'), $format2);
$worksheet->write($row,9, (defined($a->{"REGION_NID"})? $a->{"REGION_NID"} : '[NULL]'), $format2);
$worksheet->write($row,10,(defined($a->{"ASSET_ID"})? $a->{"ASSET_ID"} : '[NULL]'), $format2);
$worksheet->write($row,11,(defined($a->{"QTP_KEY_ID"})? $a->{"QTP_KEY_ID"} : '[NULL]'), $format2);
$worksheet->write($row,12,(defined($a->{"CHANGE_CTGRY_ID"})? $a->{"CHANGE_CTGRY_ID"} : '[NULL]'), $format2);
$worksheet->write($row,13,(defined($a->{"ELIMINATION_ID"})? $a->{"ELIMINATION_ID"} : '[NULL]'), $format2);
$worksheet->write($row,14,(defined($a->{"SRC_ID"})? $a->{"SRC_ID"} :  '[NULL]'), $format2);
$worksheet->write($row,15,(defined($a->{"JRNL_VAL"})? $a->{"JRNL_VAL"} : '[NULL]'), $format2);
$worksheet->write($row,16,(defined($a->{"EFFECTIVE_DTE"})? $a->{"EFFECTIVE_DTE"} : '[NULL]'), $format3);
$worksheet->write($row,17,(defined($a->{"RULE_ID"})? $a->{"RULE_ID"} : '[NULL]'), $format2);
$worksheet->write($row,18,(defined($a->{"JRNL_SET_ID"})? $a->{"JRNL_SET_ID"} : '[NULL]'), $format2);
$worksheet->write($row,19,(defined($a->{"CCY"})? $a->{"CCY"} : '[NULL]'), $format2);
$worksheet->write($row,20,(defined($a->{"TRANSLATED_CCY"})? $a->{"TRANSLATED_CCY"} : '[NULL]'), $format2);
$worksheet->write($row,21,(defined($a->{"UOM_CCY"})? $a->{"UOM_CCY"} : '[NULL]'), $format2);
$worksheet->write($row,22,(defined($a->{"RUN_GROUP_ID"})? $a->{"RUN_GROUP_ID"} : '[NULL]'), $format2);
$worksheet->write($row,23,(defined($a->{"BA_CNTRPTY_ID"})? $a->{"BA_CNTRPTY_ID"} : '[NULL]'), $format2);
$worksheet->write($row,24,(defined($a->{"INTERCPNY_CNTRPTY_ID"})? $a->{"INTERCPNY_CNTRPTY_ID"} : '[NULL]'), $format2);
$worksheet->write($row,25,(defined($a->{"REGION_CNTRPTY_ID"})? $a->{"REGION_CNTRPTY_ID"} : '[NULL]'), $format2);
$worksheet->write($row,26,(defined($a->{"TICKET_REF_NO"})? $a->{"TICKET_REF_NO"} : '[NULL]'), $format2);
$worksheet->write($row,27,(defined($a->{"MASTER_TICKET_REF_NO"})? $a->{"MASTER_TICKET_REF_NO"} : '[NULL]'), $format2);
$worksheet->write($row,28,(defined($a->{"HEADER_ID"})? $a->{"HEADER_ID"} : '[NULL]'), $format2);


$row++;
}

$sth->finish();

}###End If for SQL Queries WorkBook ###     
   
 

###################### SECOND SHEET ####################################

$col=0;


foreach my $i("NUM_ROWS", "NUM_PROCESSED", "NUM_FAILED", "NUM_OUTPUT_ROWS")

{

$worksheet1->write(0, $col++, $i, $format1);

}

##################### Accesing SQL Queries WorkBook again #########################

if ($col==0 && $row !=0 && ($sql_worksheet->get_cell($row, 0) eq "Query2"))  {
       $col++;
       my $query =  $sql_worksheet->get_cell($row, $col)->value;

my $dbh = DBI->connect('dbi:MSDB2:NQ230001', '', '', { 'RaiseError' => 1 }) or
          die "Can't connect to database: $DBI::errstr";

my $sql = "$query";




my $sth = $dbh->prepare($sql);

$sth->execute();


$row = 1;

while (my $a = $sth->fetchrow_hashref()) {

$worksheet1->write($row,0, $a->{"NUM_ROWS"}, $format2);
$worksheet1->write($row,1, $a->{"NUM_PROCESSED"}, $format2);
$worksheet1->write($row,2, $a->{"NUM_FAILED"}, $format2);
$worksheet1->write($row,3, $a->{"NUM_OUTPUT_ROWS"}, $format2);

$row++;
}

$sth->finish();
   } #########End If for the second time (for Authentication Worksheet of the Original generated file) for SQL Queries WorkBook ########
  }
 }
}
$workbook->close();
#exit;


if (-s $xls_file) {

print "\n\nFile to be compared is generated with non-zero size. \n\n";

}

else {

print "\n\nFile Generated is of zero-size. Pls fix the issues and regenerate them again before comparing\n\n";

}
Attachments:
 
the SQL queries workbook
 

Answer : A Perl Spreadsheet Problem

The airport express has an ethernet port so it can be connected to an existing network and then broadcasts wifi.

I am unfamiliar with the actual setup process but according to Apple it does support WEP and WPA security so it would be as secure as any other wireless router if setup properly.
Random Solutions  
 
programming4us programming4us