Something that has often annoyed me. Perhaps there is a purely excel way to do this, but I do use it rather a lot, and I couldn't find anything to save myself. The problem comes when copying data from cells in one workbook to another. In this particular example I only wanted every 13th cell from the source workbok, but wanted them to fall one after the other in the new workbook. Anyway, rather than playing round with excel for hours, I decided to whip up this script. I hope someone else finds it as useful as me. I could have rewritten the formulas manually but there are thousands to write so...
use Spreadsheet::WriteExcel;
#Question One
my $workbook = Spreadsheet::WriteExcel->new('Q01.xls');
my $worksheet = $workbook->addworksheet();
$worksheet->write('A1', '=Results.xls!D4' );
$preformula = "3";
$increment = "13";
for($i=1; $i<=90; $i++){
$precell=$i + "1";
$cell = "B".$precell;
$formula = "=Results.xls!E".$preformula;
$worksheet->write($cell, $formula );
$preformula = $preformula + $increment;
}
I haven't actually tested it yet, because I am not allowed perl at work, but I am sure it will do what I need and save me approximately 40 million hours. : )
Gerard
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.