in reply to How to control (in a generic way) population of Excel file from another Excel file

Since you say you know how to use Excel through OLE I've ommitted some details here. You can create an array like: my @swap = (['A','C'],['C','A']); Then open two sheets and iterate over the rows, like so:
for my $row (0..$lastrow) { for my $i (0..$#swap) { $Sheet2->Range($swap[$i][1].$row)->{'Value'} = $Sheet1->Range($swa +p[$i][0].$row)->{'Value'}; } }
where $lastrow is gotten from the original sheet. There may be some other way to copy and paste an entire column using OLE commands, but I'm afraid that would take getting into the weeds of the Excel API. This is pretty straightforward, and you could easily implement it as a subroutine.
  • Comment on Re: How to control (in a generic way) population of Excel file from another Excel file
  • Select or Download Code

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 19:49 UTC

    Thank you for your reply. That is roughly the approach so far. Identify the source and target column - make some sort of notation - very similar to your @swap array - and let it drive OLE operations. It is simple but somehow I feel I am not doing it right. Every time I need something more sophisticated I need another new class of "rule" and associated handler code. On a positive side that rule syntax is primitive enough that anybody can maintain the rules file.

    I have not done a lot in XML but I thought that perhaps the way to go was to convert both XLS files to XML and then use something like XLST to manipulate target XML based on source one. Is it something that offers some inherent advantage or am I opening Pandora's box trying it?

      If you're thinking about something like that, why not dump your data into a SQL database and access it that way? Perl has excellent SQL integration and SQL lets you slice and dice data any way you want. If you search on Perl SQL you will find all kinds of tutorials and guides.

        Thank you - need to investigate that approach. It would allow for versioning of the incoming data - the input Excel file is coming from a larger database to which we do not have access but periodically we are sent some extract as a feature request.