Quantcast
Channel: Questions and answers to issues related to Software: Business, Database, Firewalls, Office, Graphics, Security, System, Server.
Viewing all articles
Browse latest Browse all 25

Perl Spreadsheet::Writeexcel problem

$
0
0
I want to output two files into an excel sheet and write their column names. the column names are the same for both the files, so it can be the first row of the sheet. In the attached code, I can only output the first file into the excel sheet not the second file. Also cannot write the column names on top. Where am i going wrong with the code. Pls reply with the code asap...

Thanks so much
Code Snippet:
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:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
#!/usr/bin/perl5.10 -w

use warnings;
use Spreadsheet::WriteExcel::Big;
use strict;
use IO::Scalar;
use Data::Dumper;

my $actual_file;
my $generated_file;

print "Files to Compare...\n\n";

print "Specify your actual delta file path and name: \n\n";
$actual_file = "/ms/user/s/sayantag/delta_OtcFxTaxlotsOpen1.txt";

#print "Specify your generated delta file path and name: \n\n";
#$generated_file = ;
$generated_file = "/ms/user/s/sayantag/delta_OtcFxTaxlotsOpen2.txt";

my $workbook  = Spreadsheet::WriteExcel::Big->new("/ms/user/s/sayantag/Compare_Files.xls");
my $worksheet = $workbook->addworksheet();
my @XLSarray;
my @XLSarray2;
#my $data_row;
my $row = 0;
my $col=1;

my $format1 = $workbook->add_format();
$format1->set_num_format ('General');


print "The column value is $col\n";
print "The row value is $row\n";


############ Write the headers #############
$worksheet->write(0, 1, "POSTING_EVENT_TYPE", $format1);
$worksheet->write(0, 2, "LEDGER_TYPE", $format1);
$worksheet->write(0, 3, "ACCTNG_PERIOD_ID", $format1);
$worksheet->write(0, 4, "HRCHY_EFFECTIVE_DTE", $format1);
$worksheet->write(0, 5, "BA_HRCHY_ID", $format1);
$worksheet->write(0, 6, "BA_NID", $format1);
$worksheet->write(0, 7, "LE_HRCHY_ID", $format1);
$worksheet->write(0, 8, "LE_NID", $format1);
$worksheet->write(0, 9, "REGION_HRCHY_ID", $format1);
$worksheet->write(0, 10, "REGION_NID", $format1);
$worksheet->write(0, 11, "CHANGE_CTGRY_ID", $format1);
$worksheet->write(0, 12, "ELIMINATION_ID", $format1);
$worksheet->write(0, 13, "SRC_ID", $format1);
$worksheet->write(0, 14, "VALUE", $format1);
$worksheet->write(0, 15, "RUN_GROUP_ID", $format1);
$worksheet->write(0, 16, "ASSET_ID", $format1);
$worksheet->write(0, 17, "EXTERNAL_CNTRPTY_ID", $format1);
$worksheet->write(0, 18, "REGION_CNTRPTY_ID", $format1);
$worksheet->write(0, 19, "BA_CNTRPTY_ID", $format1);
$worksheet->write(0, 20, "AQUISITION_DTE", $format1);
$worksheet->write(0, 21, "AQUISITION_DTE_LPT_ID", $format1);
$worksheet->write(0, 22, "DUE_DTE", $format1);
$worksheet->write(0, 23, "DUE_DTE_LPT_ID", $format1);
$worksheet->write(0, 24, "CLIENT_ID", $format1);
$worksheet->write(0, 25, "INTERCPNY_CNTRPTY_ID", $format1);
$worksheet->write(0, 26, "DEBT_TENURE_NME", $format1);
$worksheet->write(0, 27, "CCY", $format1);
$worksheet->write(0, 28, "TRANSLATED_CCY", $format1);
$worksheet->write(0, 29, "UOM_CCY", $format1);
$worksheet->write(0, 30, "AUDIT_ACCT_NUM", $format1);
$worksheet->write(0, 31, "QTP_KEY_ID", $format1);
$worksheet->write(0, 32, "AUDIT_CPNY_CDE", $format1);
$worksheet->write(0, 33, "AUDIT_COST_CNTR_NME", $format1);
$worksheet->write(0, 34, "AUDIT_JRNL_XML", $format1);
$worksheet->write(0, 35, "AUDIT_ACCOUNT_RULE", $format1);
$worksheet->write(0, 36, "AUDIT_PRODUCT_RULE", $format1);
$worksheet->write(0, 37, "AUDIT_SOURCE", $format1);
$worksheet->write(0, 38, "AUDIT_TD_SD_PEND", $format1);
$worksheet->write(0, 39, "AUDIT_FUNDING_RULE", $format1);
$worksheet->write(0, 40, "CLEARING_HOUSE_CDE", $format1);
$worksheet->write(0, 41, "SEC_POOL_ID", $format1);
$worksheet->write(0, 42, "TICKET_REF_NO", $format1);
$worksheet->write(0, 43, "MASTER_TICKET_REF_NO", $format1);
$worksheet->write(0, 44, "LEG_TYPE_DSC", $format1);
$worksheet->write(0, 45, "NETTING_GRP_ID", $format1);
$worksheet->write(0, 46, "COLLATERAL_GRP_ID", $format1);
$worksheet->write(0, 47, "PROD_GRP_DSC", $format1);
$worksheet->write(0, 48, "HEADER_ID", $format1);


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

############### First File #######################
$row +=2;

open ("ACT", $actual_file) || die "Cannot open $actual_file\n";

while (my $data_row = ) {


my (
 $posting_event_type
,$ledger_type
,$acctng_period_id
,$hrchy_effective_dte
,$ba_hrchy_id
,$ba_nid
,$le_hrchy_id
,$le_nid
,$region_hrchy_id
,$region_nid
,$change_ctgry_id
,$elimination_id
,$src_id
,$value
,$run_group_id
,$asset_id
,$external_cntrpty_id
,$region_cntrpty_id
,$ba_cntrpty_id
,$aquisition_dte
,$aquisition_dte_lpt_id
,$due_dte
,$due_dte_lpt_id
,$client_id
,$intercpny_cntrpty_id
,$debt_tenure_nme
,$ccy
,$translated_ccy
,$uom_ccy
,$audit_acct_num
,$qtp_key_id
,$audit_cpny_cde
,$audit_cost_cntr_nme
,$audit_jrnl_xml
,$audit_account_rule
,$audit_product_rule
,$audit_source
,$audit_td_sd_pend
,$audit_funding_rule
,$clearing_house_cde
,$sec_pool_id
,$ticket_ref_no
,$master_ticket_ref_no
,$leg_type_dsc
,$netting_grp_id
,$collateral_grp_id
,$prod_grp_dsc
,$header_id
) = split (/\|/, $data_row);




push @XLSarray,
($posting_event_type
,$ledger_type
,$acctng_period_id
,$hrchy_effective_dte
,$ba_hrchy_id
,$ba_nid
,$le_hrchy_id
,$le_nid
,$region_hrchy_id
,$region_nid
,$change_ctgry_id
,$elimination_id
,$src_id
,$value
,$run_group_id
,$asset_id
,$external_cntrpty_id
,$region_cntrpty_id
,$ba_cntrpty_id
,$aquisition_dte
,$aquisition_dte_lpt_id
,$due_dte
,$due_dte_lpt_id
,$client_id
,$intercpny_cntrpty_id
,$debt_tenure_nme
,$ccy
,$translated_ccy
,$uom_ccy
,$audit_acct_num
,$qtp_key_id
,$audit_cpny_cde
,$audit_cost_cntr_nme
,$audit_jrnl_xml
,$audit_account_rule
,$audit_product_rule
,$audit_source
,$audit_td_sd_pend
,$audit_funding_rule
,$clearing_house_cde
,$sec_pool_id
,$ticket_ref_no
,$master_ticket_ref_no
,$leg_type_dsc
,$netting_grp_id
,$collateral_grp_id
,$prod_grp_dsc
,$header_id
);

print "The column value is $col\n";
print "The row value is $row\n";

$col = 1;

foreach my $XLSelement (@XLSarray) {
$worksheet->write($row, $col, $XLSelement, $format1);
$col++;
}
@XLSarray = ();  
$row++;
}
close("ACT");
########################################################


################ SECOND FILE ##########################

$row +=2;

open ("GEN", $generated_file) || die "Cannot open $generated_file\n";

while (my $data_row = ) {


my (
 $posting_event_type
,$ledger_type
,$acctng_period_id
,$hrchy_effective_dte
,$ba_hrchy_id
,$ba_nid
,$le_hrchy_id
,$le_nid
,$region_hrchy_id
,$region_nid
,$change_ctgry_id
,$elimination_id
,$src_id
,$value
,$run_group_id
,$asset_id
,$external_cntrpty_id
,$region_cntrpty_id
,$ba_cntrpty_id
,$aquisition_dte
,$aquisition_dte_lpt_id
,$due_dte
,$due_dte_lpt_id
,$client_id
,$intercpny_cntrpty_id
,$debt_tenure_nme
,$ccy
,$translated_ccy
,$uom_ccy
,$audit_acct_num
,$qtp_key_id
,$audit_cpny_cde
,$audit_cost_cntr_nme
,$audit_jrnl_xml
,$audit_account_rule
,$audit_product_rule
,$audit_source
,$audit_td_sd_pend
,$audit_funding_rule
,$clearing_house_cde
,$sec_pool_id
,$ticket_ref_no
,$master_ticket_ref_no
,$leg_type_dsc
,$netting_grp_id
,$collateral_grp_id
,$prod_grp_dsc
,$header_id
) = split (/\|/, $data_row);




push @XLSarray2,
($posting_event_type
,$ledger_type
,$acctng_period_id
,$hrchy_effective_dte
,$ba_hrchy_id
,$ba_nid
,$le_hrchy_id
,$le_nid
,$region_hrchy_id
,$region_nid
,$change_ctgry_id
,$elimination_id
,$src_id
,$value
,$run_group_id
,$asset_id
,$external_cntrpty_id
,$region_cntrpty_id
,$ba_cntrpty_id
,$aquisition_dte
,$aquisition_dte_lpt_id
,$due_dte
,$due_dte_lpt_id
,$client_id
,$intercpny_cntrpty_id
,$debt_tenure_nme
,$ccy
,$translated_ccy
,$uom_ccy
,$audit_acct_num
,$qtp_key_id
,$audit_cpny_cde
,$audit_cost_cntr_nme
,$audit_jrnl_xml
,$audit_account_rule
,$audit_product_rule
,$audit_source
,$audit_td_sd_pend
,$audit_funding_rule
,$clearing_house_cde
,$sec_pool_id
,$ticket_ref_no
,$master_ticket_ref_no
,$leg_type_dsc
,$netting_grp_id
,$collateral_grp_id
,$prod_grp_dsc
,$header_id
);

print "The column value is $col\n";
print "The row value is $row\n";

$col = 1;

foreach my $XLSelement (@XLSarray2) {
$worksheet->write($row, $col, $XLSelement, $format1);
$col++;
}
@XLSarray2 = ();  
$row++;
}

close("GEN");
###############################################


$workbook->close();

Viewing all articles
Browse latest Browse all 25

Trending Articles