in reply to loop through xlsx and get specific column cell values

Hello emadmahou,

I’m not at all clear on what you are trying to do. It would be a great help if you could give (small!) sample files, one each for $inputFile and “test.xlsx”, together with the output (in “$inputFile.seed.txt”) you want to generate.

Here are some preliminary observations:

  1. The variable %DivisionHash is declared but never used.
  2. Since neither the name of the Excel file nor its contents change during the loop, there is no need to re-parse it on every loop iteration. Parse it once, before the loop, and access the parse information in the loop as needed.
  3. Since your values are strings, you should compare then using eq, not ==: if ($DivisionHash eq $value). (ww stole my thunder on this one!)
  4. The commented-out sections of your code seem to be leftover from an earlier design. By all means keep them for reference (in a separate file, say), but it will help you to “see” your code more clearly if you remove them from the current script.
  5. Likewise, there are places where the comments don’t match the code:
    # Get cell value from excel sheet1 row 1 column 2 for my $worksheet ( $workbook->worksheets() ) {
    and unexplained magic numbers:
    my $cell = $worksheet->get_cell(1,9);
    Cleaning up the code, and documenting what it currently does, will help you to clarify its structure and logic.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: loop through xlsx and get specific column cell values
by ww (Archbishop) on Apr 17, 2016 at 12:28 UTC
    ;-) I didn't steal it; I merely flashed on it...
    ... and in doing so, missed the critical (en)lightening of points 1,2,4 and 5.
        Well done and + +