in reply to Using variable files to add data into excel spreadsheet
If your data is not too large for that, you might consider reading all the files and populate a hash of hashes (or possibly a hash of arrays, or whatever data strructure is fit for your data). Once your are done with that, you know how many fruit types and other counters, and you can easily populate your spreadsheet. This might be slightly slower,but it is probably more practical.