Creating new result tabs for each image in a directory


I created a code where I have a folder with all my images. I did a For loop to process all the images in this folder and then save the results in an excel file. I also reset the ROI manager at the end of one image processing and before proceeding to the next. I have 2 images for eg.
Currently, the results saved is only for image 2.
How do I save each image results to a new Excel Tab (and specify the image name on the tab)?

Thank you.


I think your code is over-writing the previous results table output… so no matter how many images you process - only the last image’s results will be written in and saved. So you need to move where you have your saveAs() function in your for loop. Would you be able to share with us your code?

For stuff like this… I’d recommend what I wrote in this other thread:

Using those Script Parameters will save you - especially when saving/naming image results, etc.

thank you for the reply. yes, you are right that is what happened. I managed to fix that - initially in my line 62 i did not fill in the details of savaAs() correctly.
But still it is creating a new file for each analysis, which is fine too. But i’m wondering if i can save the data to the same excel file but on different tabs with each tab having the file name.
I have attached my code here.
Thank you.
07 May 2020_Forum_.ijm (4.4 KB)


Unfortunately - ImageJ is not so sophisticated… you won’t be able to save them as tabs in an excel sheet via ImageJ. You could save them all to the same file as one long list or as different files - but that’s about it as far as I know. You’d have to look outside of ImageJ for table writing code… perhaps you can do it afterwards via a command line script?

1 Like

Hi kisha,

The ‘Read and Write Excel’ Plugin can do exactly what you want. You can install it via the Fiji updater (look for ‘ResultsToExcel’). Then in a macro, your call will look something like this:

run("Read and Write Excel", "file=[C:/Users/kisha/Documents/My_cool_file.xlsx] sheet=[Custom name here] dataset_label=[name of processed image etc]");

In which ‘file’ denotes the save and re-write location and file-name (if not provided, the users desktop and a deafult title is used); ‘sheet’ denotes the workbook tab (if the same tab-name is given then that tab will be updated. If a new tab name is given, a new tab will be created); and ‘dataset_label’ denotes the data import label (by default the last open image title will be used).
Other instructions can be found here:

Only bringing this to your attention in case it can help. ImageJ of course has plenty of native functionality for .csv and .txt saving. With clever macro file opening and data parsing the same file/data can be amended but this plugin does make it easier.

Kind regards.


thank you ! I will check this out.