Login  Register

Re: Append new results to excel file

Posted by Wayne Rasband on Jun 08, 2009; 3:16pm
URL: http://imagej.273.s1.nabble.com/Append-new-results-to-excel-file-tp3692245p3692246.html

On Jun 7, 2009, at 12:30 PM, Adam Hacking wrote:

> Hi,
> I'm looking for an example macro to update an excel file (append row
> after row) to a worksheet as results are generated. I can't find any
> exmaples on the ImageJ site.
> Many thanks

You can append a row to a spreadsheet-compatible, tab-delimited text
file using the File.append() macro function. Here is an example that
adds 10 rows, each containing 5 numbers, to an existing text file:

  for (i=0; i<10; i++) {
      row = "";
      for (j=0; j<5; j++)
          row = row + d2s(random,2) + "\t";
      File.append(row, getDirectory("home")+"results.xls");
      wait(5000);
  }

The file is created if it does not already exist.

-wayne