in reply to How to control (in a generic way) population of Excel file from another Excel file
I would put the mapping rules in another spreadsheet something like this
poj#!perl use strict; use Win32::OLE::Const 'Microsoft Excel'; Win32::OLE->Option(Warn => 3); my $ex = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit'); my $wb1 = $ex->Workbooks->Open("c:\\temp\\Book1.xlsx") ; my $wb2 = $ex->Workbooks->Add ; my $wb3 = $ex->Workbooks->Open("c:\\temp\\Mapping.xlsx"); my $sht1 = $wb1->Worksheets("Sheet1"); my $sht2 = $wb2->Worksheets("Sheet1"); my $sht3 = $wb3->Worksheets("Sheet1"); my $lastRow = $sht3->UsedRange->Find({What=>"*", SearchDirection=>xlPrevious, SearchOrder=>xlByRows})->{Row}; # Copy columns for my $n (1..$lastRow){ my $in = $sht3->Range("A$n")->Value; my $out = $sht3->Range("B$n")->Value; print "Mapping rule $n : $in => $out\n"; $sht1->Range("$in:$in")->Copy( $sht2->Range("$out:$out") ); } $wb2->SaveAs("c:\\temp\\Book2.xlsx"); undef $ex;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to control (in a generic way) population of Excel file from another Excel file
by woland99 (Beadle) on Nov 10, 2015 at 20:11 UTC |