From 5651882cd1c10163ee211f3b5aaa57996c58d8cd Mon Sep 17 00:00:00 2001 From: antinos Date: Tue, 27 Feb 2018 10:59:03 +0000 Subject: [PATCH 1/7] Update Read_and_Write_Excel.java numColumn change to mitigate suspected ImageJ bug. --- src/main/java/Read_and_Write_Excel.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/Read_and_Write_Excel.java b/src/main/java/Read_and_Write_Excel.java index d6db975..1ec7c30 100644 --- a/src/main/java/Read_and_Write_Excel.java +++ b/src/main/java/Read_and_Write_Excel.java @@ -97,7 +97,7 @@ public void run(String arg) { // Get results, the number of columns and rows, the data, and the headings. ResultsTable resultsTable = debugTable == null ? Analyzer.getResultsTable() : debugTable; - int numColumns = resultsTable.getLastColumn() + 1; + int numColumns = resultsTable.getHeadings().length; //I encountered this issue before. Passing this number gives the total number of possible columns or some such. int numRows = resultsTable.size(); String[] headers = resultsTable.getHeadings(); String[][] results = new String[numRows][numColumns]; @@ -106,7 +106,7 @@ public void run(String arg) { // plus it could mess up if there are any empty cells...this is the most sensible in the end. for (int row = 0; row < numRows; row++) for (int col = 0; col < numColumns; col++) - results[row][col] = resultsTable.getStringValue(col, row); + results[row][col] = resultsTable.getStringValue(headers[col], row); //Column header reference issue. Passing int for some reason calls hidden values. Passing header string works. // Figure out which holder to use. ExcelHolder holderToUse = fileHolder; From 4736d4247727b28fd7668231b05961b454db48a5 Mon Sep 17 00:00:00 2001 From: antinos Date: Thu, 8 Nov 2018 10:54:16 +0000 Subject: [PATCH 2/7] v1.1.1 and v1.1.2 changes Bug fix and new features --- src/main/java/Read_and_Write_Excel.java | 99 ++++++++++++++++++++----- 1 file changed, 79 insertions(+), 20 deletions(-) diff --git a/src/main/java/Read_and_Write_Excel.java b/src/main/java/Read_and_Write_Excel.java index 1ec7c30..30d1b2b 100644 --- a/src/main/java/Read_and_Write_Excel.java +++ b/src/main/java/Read_and_Write_Excel.java @@ -12,6 +12,7 @@ import java.io.FileOutputStream; import java.io.IOException; +/**version 1.1.2*/ public class Read_and_Write_Excel implements PlugIn { private enum FileHandlingMode { OPEN_CLOSE, READ_OPEN, WRITE_CLOSE, QUEUE} @@ -31,6 +32,7 @@ private enum FileHandlingMode { OPEN_CLOSE, READ_OPEN, WRITE_CLOSE, QUEUE} private String filePath; private String sheetName; private String dataSetLabel; + private boolean stackResults = false; private boolean noCountColumn = false; private FileHandlingMode fileHandlingMode = FileHandlingMode.OPEN_CLOSE; @@ -57,6 +59,8 @@ public static void main(String[] args) { debugOptions = "no_count_column dataset_label=[Test dataset label] sheet=[Sheet Name] file=[/Users/bkromhout/Desktop/Results File.xlsx]"; new Read_and_Write_Excel().run(""); debugOptions = "no_count_column file=[/path/to/Results File.xlsx]"; + new Read_and_Write_Excel().run(""); + debugOptions = "stack_results"; } public void run(String arg) { @@ -97,17 +101,24 @@ public void run(String arg) { // Get results, the number of columns and rows, the data, and the headings. ResultsTable resultsTable = debugTable == null ? Analyzer.getResultsTable() : debugTable; - int numColumns = resultsTable.getHeadings().length; //I encountered this issue before. Passing this number gives the total number of possible columns or some such. + int numColumns = resultsTable.getHeadings().length; int numRows = resultsTable.size(); String[] headers = resultsTable.getHeadings(); String[][] results = new String[numRows][numColumns]; // Loop over the results. We could use the getRowAsString(), but we'd just have to split it and parse it again, // plus it could mess up if there are any empty cells...this is the most sensible in the end. - for (int row = 0; row < numRows; row++) - for (int col = 0; col < numColumns; col++) + for (int row = 0; row < numRows; row++){ + //Solution for handling empty label-column cells, which otherwise causes the plugin to fail. Replace null label cells with "NaN". + if (resultsTable.getLabel(row) == null){ + resultsTable.setLabel("null", row); + } + //Continue with results loop, as described above. + for (int col = 0; col < numColumns; col++){ results[row][col] = resultsTable.getStringValue(headers[col], row); //Column header reference issue. Passing int for some reason calls hidden values. Passing header string works. - + } + } + // Figure out which holder to use. ExcelHolder holderToUse = fileHolder; if (fileHandlingMode == FileHandlingMode.OPEN_CLOSE) { @@ -149,6 +160,52 @@ public void run(String arg) { f.setBold(true); boldStyle.setFont(f); + // Write the column header cells. If stackResults is chosen, then only write the header cells if they do not exist already. + row = sheet.getRow(COLUMN_HEADER_ROW); + if (row == null) row = sheet.createRow(COLUMN_HEADER_ROW); + if (stackResults != true) { + for (int headerIdx = 0; headerIdx < (headers.length + idxAdj); headerIdx++) { + int cellCol = firstColIdx + headerIdx; + Cell colHeader = row.getCell(cellCol); + if (colHeader == null) colHeader = row.createCell(cellCol); + // Make sure we write the "Count" column header to the first column, if we want it. + if (cellCol == firstColIdx && !noCountColumn) colHeader.setCellValue("Count"); + else colHeader.setCellValue(headers[headerIdx - idxAdj]); + colHeader.setCellStyle(boldStyle); + } + } else { + if (sheet.getRow(COLUMN_HEADER_ROW).getCell(0) == null){ + for (int headerIdx = 0; headerIdx < (headers.length + idxAdj); headerIdx++) { + int cellCol = firstColIdx + headerIdx; + Cell colHeader = row.getCell(cellCol); + if (colHeader == null) colHeader = row.createCell(cellCol); + // Make sure we write the "Count" column header to the first column, if we want it. + if (cellCol == firstColIdx && !noCountColumn) colHeader.setCellValue("Count"); + else colHeader.setCellValue(headers[headerIdx - idxAdj]); + colHeader.setCellStyle(boldStyle); + } + } + } + + // Change the first column index to write data to, depending on stack_results status. + row = sheet.getRow(FIRST_DATA_ROW); + int firstDataRow = FIRST_DATA_ROW; + if (sheet.getLastRowNum()!=2 && stackResults == true) { + int lastColIdx = row.getLastCellNum()-1; + int lastRowOfLastColIdx = FIRST_DATA_ROW; + Row rowL = sheet.getRow(lastRowOfLastColIdx); + Cell testCell = row.getCell(lastColIdx); + while (testCell != null){ + lastRowOfLastColIdx++; + rowL = sheet.getRow(lastRowOfLastColIdx); + if (rowL != null){ testCell = rowL.getCell(lastColIdx);} + else testCell = null; + } + firstDataRow = lastRowOfLastColIdx; + firstColIdx = lastColIdx - headers.length; + if (noCountColumn == true) firstColIdx = firstColIdx + 1; + } + // Write dataset label to the first row in the sheet. row = sheet.getRow(DATASET_LABEL_ROW); if (row == null) row = sheet.createRow(DATASET_LABEL_ROW); @@ -157,27 +214,14 @@ public void run(String arg) { datasetLabelCell.setCellValue(dataSetLabel); datasetLabelCell.setCellStyle(boldStyle); - // Write the column header cells. - row = sheet.getRow(COLUMN_HEADER_ROW); - if (row == null) row = sheet.createRow(COLUMN_HEADER_ROW); - for (int headerIdx = 0; headerIdx < (headers.length + idxAdj); headerIdx++) { - int cellCol = firstColIdx + headerIdx; - Cell colHeader = row.getCell(cellCol); - if (colHeader == null) colHeader = row.createCell(cellCol); - // Make sure we write the "Count" column header to the first column, if we want it. - if (cellCol == firstColIdx && !noCountColumn) colHeader.setCellValue("Count"); - else colHeader.setCellValue(headers[headerIdx - idxAdj]); - colHeader.setCellStyle(boldStyle); - } - // Write the data (and count number, if necessary) to the sheet. All row/col numbers are 0-based indices. // We loop over the actual 2D results array here, and figure out the cell row/col based on that. + row = sheet.getRow(FIRST_DATA_ROW); for (int resultRow = 0; resultRow < results.length; resultRow++) { // Figure out the cell row index, then get (or create) a row. - int cellRow = FIRST_DATA_ROW + resultRow; + int cellRow = firstDataRow + resultRow; row = sheet.getRow(cellRow); if (row == null) row = sheet.createRow(cellRow); - for (int resultCol = 0; resultCol < (results[resultRow].length + idxAdj); resultCol++) { // Figure out the cell column index, then get (or create) a cell. int cellCol = firstColIdx + resultCol; @@ -186,8 +230,18 @@ public void run(String arg) { // If this is the first cell column, and we want to write the row count, write that (1-based). if (cellCol == firstColIdx && !noCountColumn) cell.setCellValue(resultRow + 1); - else cell.setCellValue(results[resultRow][resultCol - idxAdj]); + else { + //Check result datatype and format the cell appropriately before writing + //Not a perfect checking method, but will work most of the time without too much overhead + if (results[resultRow][resultCol - idxAdj].matches(".*[A-Za-z].*") == true){ + cell.setCellValue(results[resultRow][resultCol - idxAdj]); + } else { + cell.setCellType(CellType.NUMERIC); + cell.setCellValue(Double.parseDouble(results[resultRow][resultCol - idxAdj])); + } + } } + IJ.showProgress(resultRow, results.length + ((int)Math.rint(results.length/100)) ); } // Write the output to a file. @@ -195,6 +249,7 @@ public void run(String arg) { } catch (IOException e) { IJ.handleException(e); } + IJ.showProgress(1); } /** @@ -256,6 +311,10 @@ private void parseOptions() { ImagePlus currImage = WindowManager.getCurrentImage(); if (currImage != null) dataSetLabel = currImage.getTitle(); } + + // Figure out if we want to place new results data into existing columns + // Stacking data instead of placing it adjacent to existing data in the designated spreadsheet + stackResults = optionsStr.contains("stack_results"); } private static class ExcelHolder { From 14e442820375e08dc27f2efb71744400b0fbfde3 Mon Sep 17 00:00:00 2001 From: antinos Date: Sun, 1 Dec 2019 12:24:04 +0000 Subject: [PATCH 3/7] v1.1.5 Several bug fixes, mostly related to way the plugin handles empty cells. --- src/main/java/Read_and_Write_Excel.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/Read_and_Write_Excel.java b/src/main/java/Read_and_Write_Excel.java index 30d1b2b..7bb4fdf 100644 --- a/src/main/java/Read_and_Write_Excel.java +++ b/src/main/java/Read_and_Write_Excel.java @@ -12,7 +12,7 @@ import java.io.FileOutputStream; import java.io.IOException; -/**version 1.1.2*/ +/**version 1.1.5*/ public class Read_and_Write_Excel implements PlugIn { private enum FileHandlingMode { OPEN_CLOSE, READ_OPEN, WRITE_CLOSE, QUEUE} @@ -109,13 +109,16 @@ public void run(String arg) { // Loop over the results. We could use the getRowAsString(), but we'd just have to split it and parse it again, // plus it could mess up if there are any empty cells...this is the most sensible in the end. for (int row = 0; row < numRows; row++){ - //Solution for handling empty label-column cells, which otherwise causes the plugin to fail. Replace null label cells with "NaN". - if (resultsTable.getLabel(row) == null){ - resultsTable.setLabel("null", row); - } //Continue with results loop, as described above. for (int col = 0; col < numColumns; col++){ - results[row][col] = resultsTable.getStringValue(headers[col], row); //Column header reference issue. Passing int for some reason calls hidden values. Passing header string works. + //Solution for handling empty column cells, which otherwise causes the plugin to fail. + if (resultsTable.columnExists(headers[col]) == true && headers[col] != "Label" && !resultsTable.getStringValue(headers[col], row).isEmpty() ){ + results[row][col] = resultsTable.getStringValue(headers[col], row); //Column header reference issue. Passing int for some reason calls hidden values. Passing header string works. + } else if(headers[col] == "Label" && resultsTable.getLabel(row) != null && !resultsTable.getLabel(row).isEmpty()) { + results[row][col] = resultsTable.getLabel(row); + } else { + results[row][col] = " "; + } } } @@ -233,7 +236,7 @@ public void run(String arg) { else { //Check result datatype and format the cell appropriately before writing //Not a perfect checking method, but will work most of the time without too much overhead - if (results[resultRow][resultCol - idxAdj].matches(".*[A-Za-z].*") == true){ + if (results[resultRow][resultCol - idxAdj].matches(".*[A-Za-z].*") == true || results[resultRow][resultCol - idxAdj] == " "){ cell.setCellValue(results[resultRow][resultCol - idxAdj]); } else { cell.setCellType(CellType.NUMERIC); From 857aac30c23e94207d36fe813f29caaeedcd7aed Mon Sep 17 00:00:00 2001 From: antinos Date: Wed, 20 May 2020 02:26:29 +0100 Subject: [PATCH 4/7] v1.1.6 Fixed a rare 'stack_results' bug that incorrectly exported data from a results table with only 1 row when the excel file also contained a single row of data. --- src/main/java/Read_and_Write_Excel.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/Read_and_Write_Excel.java b/src/main/java/Read_and_Write_Excel.java index 7bb4fdf..b415365 100644 --- a/src/main/java/Read_and_Write_Excel.java +++ b/src/main/java/Read_and_Write_Excel.java @@ -12,7 +12,7 @@ import java.io.FileOutputStream; import java.io.IOException; -/**version 1.1.5*/ +/**version 1.1.6*/ public class Read_and_Write_Excel implements PlugIn { private enum FileHandlingMode { OPEN_CLOSE, READ_OPEN, WRITE_CLOSE, QUEUE} @@ -61,6 +61,7 @@ public static void main(String[] args) { debugOptions = "no_count_column file=[/path/to/Results File.xlsx]"; new Read_and_Write_Excel().run(""); debugOptions = "stack_results"; + new Read_and_Write_Excel().run(""); } public void run(String arg) { @@ -193,8 +194,15 @@ public void run(String arg) { // Change the first column index to write data to, depending on stack_results status. row = sheet.getRow(FIRST_DATA_ROW); int firstDataRow = FIRST_DATA_ROW; - if (sheet.getLastRowNum()!=2 && stackResults == true) { + if (sheet.getLastRowNum()!=1 && stackResults == true) { int lastColIdx = row.getLastCellNum()-1; + // getLastCellNum() will output -1 if the row does not contain any cells, so we handle that scenario here (check for -2 as we already took away 1 above) + if (lastColIdx == -2) { + //when the results table is empty the headings length is output as 0, so this must also be handled + if (headers.length == 0) { + lastColIdx = 0; + } else lastColIdx = headers.length-1+idxAdj; + } int lastRowOfLastColIdx = FIRST_DATA_ROW; Row rowL = sheet.getRow(lastRowOfLastColIdx); Cell testCell = row.getCell(lastColIdx); From efcc6af572fe03ce78d27a8f2e2053bd6640b10b Mon Sep 17 00:00:00 2001 From: antinos Date: Wed, 20 May 2020 11:27:30 +0100 Subject: [PATCH 5/7] Install instr. changed for most up-to-date version Minor edit to direct users to most up-to-date version of the plugin. Strikethroughs included for transparency (can be properly changed later) --- README.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5febe07..118e550 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ The defaults can be overridden when calling the plugin from an ImageJ macro usin ## Macro Parameters This version of the Read_and_Write_Excel plugin supports additional features which make it more flexible for usage in ImageJ macros. These are the supported parameters: * `no_count_column`: Prevents the plugin from adding a "Count" column automatically. +* `stack_results` : Instructs the plugin to export data underneath pre-existing data in the Excel file, instead of adjacent to it. * `file=`: The path to the excel file to use (uses the default desktop file otherwise) * `sheet=`: Which sheet in the excel file to put the results in * `dataset_label=`: The label to write in the cell above the data in the excel file @@ -22,9 +23,12 @@ This version of the Read_and_Write_Excel plugin supports additional features whi The easiest way to install the plugin is to use Fiji's built-in updater: 1) Go to Help > Update... 2) Click "Manage update sites" -3) Click "Add update site" -4) Give the new update site a name, and use the URL `http://sites.imagej.net/Bkromhout/` -5) You should now see the plugin available in the updater. +~~3) Click "Add update site"~~ +3) Find 'ResultsToExcel' in the list of plugins and mark the check-box. +~~4) Give the new update site a name, and use the URL `http://sites.imagej.net/Bkromhout/`~~ (*does not host the most recent version currently*) +4) Close the "Manage update sites" window and click "Apply changes" in the Imagej Updater main window. +~~5) You should now see the plugin available in the updater.~~ +5) Restart ImageJ. If you can't do that for some reason, you should also be able to download the latest release, unzip it, and copy the plugin's JAR to the ImageJ plugins folder, and the JARs in the "jars" folder to ImageJ's "jars" folder. @@ -46,4 +50,4 @@ print("Wrote 2"); run("Read and Write Excel", "file_mode=write_and_close"); print("Closed file"); -``` \ No newline at end of file +``` From a8c9050590e86a704e1769cd5f8a4375e5fa32d8 Mon Sep 17 00:00:00 2001 From: antinos Date: Wed, 20 May 2020 11:32:35 +0100 Subject: [PATCH 6/7] Install instr. changed for most up-to-date version Installation instructions changed to direct users to the most p-to-date version of the plugin. Strikethroughs included for transparency (can be properly changed later perhaps). *another minor edit for list display adjustments --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 118e550..51b57c0 100644 --- a/README.md +++ b/README.md @@ -22,12 +22,12 @@ This version of the Read_and_Write_Excel plugin supports additional features whi ## Installation The easiest way to install the plugin is to use Fiji's built-in updater: 1) Go to Help > Update... -2) Click "Manage update sites" -~~3) Click "Add update site"~~ -3) Find 'ResultsToExcel' in the list of plugins and mark the check-box. -~~4) Give the new update site a name, and use the URL `http://sites.imagej.net/Bkromhout/`~~ (*does not host the most recent version currently*) -4) Close the "Manage update sites" window and click "Apply changes" in the Imagej Updater main window. -~~5) You should now see the plugin available in the updater.~~ +2) Click "Manage update sites"
+~~3) Click "Add update site"~~
+3) Find 'ResultsToExcel' in the list of plugins and mark the check-box.
+~~4) Give the new update site a name, and use the URL `http://sites.imagej.net/Bkromhout/`~~ (*does not host the most recent version currently*)
+4) Close the "Manage update sites" window and click "Apply changes" in the Imagej Updater main window.
+~~5) You should now see the plugin available in the updater.~~
5) Restart ImageJ. If you can't do that for some reason, you should also be able to download the latest release, unzip it, and copy the plugin's JAR to the ImageJ plugins folder, and the JARs in the "jars" folder to ImageJ's "jars" folder. From e64e56fb642a75e571613d19295e4002c8bc93b6 Mon Sep 17 00:00:00 2001 From: antinos Date: Sat, 26 Sep 2020 15:36:10 +0100 Subject: [PATCH 7/7] v1.1.7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Feature added. 'cell_ref' argument now allows data to be imported to a specified cell. User request from Stein Rørvik (steinr on forum.image.sc). NOTE: the plugin does not check to see if data is already present at the specified location, so overwriting is possible. Column headers are also not exported with the data. --- src/main/java/Read_and_Write_Excel.java | 68 ++++++++++++++++--------- 1 file changed, 43 insertions(+), 25 deletions(-) diff --git a/src/main/java/Read_and_Write_Excel.java b/src/main/java/Read_and_Write_Excel.java index b415365..5bd6d91 100644 --- a/src/main/java/Read_and_Write_Excel.java +++ b/src/main/java/Read_and_Write_Excel.java @@ -4,6 +4,7 @@ import ij.plugin.filter.Analyzer; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.util.CellReference; import org.apache.poi.ss.util.WorkbookUtil; import org.apache.poi.xssf.usermodel.XSSFWorkbook; @@ -12,7 +13,7 @@ import java.io.FileOutputStream; import java.io.IOException; -/**version 1.1.6*/ +/**version 1.1.7*/ public class Read_and_Write_Excel implements PlugIn { private enum FileHandlingMode { OPEN_CLOSE, READ_OPEN, WRITE_CLOSE, QUEUE} @@ -32,6 +33,7 @@ private enum FileHandlingMode { OPEN_CLOSE, READ_OPEN, WRITE_CLOSE, QUEUE} private String filePath; private String sheetName; private String dataSetLabel; + private String importCell; private boolean stackResults = false; private boolean noCountColumn = false; private FileHandlingMode fileHandlingMode = FileHandlingMode.OPEN_CLOSE; @@ -62,6 +64,8 @@ public static void main(String[] args) { new Read_and_Write_Excel().run(""); debugOptions = "stack_results"; new Read_and_Write_Excel().run(""); + debugOptions = "cell_ref=[A1]"; + new Read_and_Write_Excel().run(""); } public void run(String arg) { @@ -164,31 +168,33 @@ public void run(String arg) { f.setBold(true); boldStyle.setFont(f); - // Write the column header cells. If stackResults is chosen, then only write the header cells if they do not exist already. - row = sheet.getRow(COLUMN_HEADER_ROW); - if (row == null) row = sheet.createRow(COLUMN_HEADER_ROW); - if (stackResults != true) { - for (int headerIdx = 0; headerIdx < (headers.length + idxAdj); headerIdx++) { - int cellCol = firstColIdx + headerIdx; - Cell colHeader = row.getCell(cellCol); - if (colHeader == null) colHeader = row.createCell(cellCol); - // Make sure we write the "Count" column header to the first column, if we want it. - if (cellCol == firstColIdx && !noCountColumn) colHeader.setCellValue("Count"); - else colHeader.setCellValue(headers[headerIdx - idxAdj]); - colHeader.setCellStyle(boldStyle); + // Write the column header cells. If stackResults is chosen, then only write the header cells if they do not exist already. If an import cell reference is specified, then do not write the headers at all. + if(importCell == null) { + row = sheet.getRow(COLUMN_HEADER_ROW); + if (row == null) row = sheet.createRow(COLUMN_HEADER_ROW); + if (stackResults != true) { + for (int headerIdx = 0; headerIdx < (headers.length + idxAdj); headerIdx++) { + int cellCol = firstColIdx + headerIdx; + Cell colHeader = row.getCell(cellCol); + if (colHeader == null) colHeader = row.createCell(cellCol); + // Make sure we write the "Count" column header to the first column, if we want it. + if (cellCol == firstColIdx && !noCountColumn) colHeader.setCellValue("Count"); + else colHeader.setCellValue(headers[headerIdx - idxAdj]); + colHeader.setCellStyle(boldStyle); + } + } else { + if (sheet.getRow(COLUMN_HEADER_ROW).getCell(0) == null){ + for (int headerIdx = 0; headerIdx < (headers.length + idxAdj); headerIdx++) { + int cellCol = firstColIdx + headerIdx; + Cell colHeader = row.getCell(cellCol); + if (colHeader == null) colHeader = row.createCell(cellCol); + // Make sure we write the "Count" column header to the first column, if we want it. + if (cellCol == firstColIdx && !noCountColumn) colHeader.setCellValue("Count"); + else colHeader.setCellValue(headers[headerIdx - idxAdj]); + colHeader.setCellStyle(boldStyle); + } + } } - } else { - if (sheet.getRow(COLUMN_HEADER_ROW).getCell(0) == null){ - for (int headerIdx = 0; headerIdx < (headers.length + idxAdj); headerIdx++) { - int cellCol = firstColIdx + headerIdx; - Cell colHeader = row.getCell(cellCol); - if (colHeader == null) colHeader = row.createCell(cellCol); - // Make sure we write the "Count" column header to the first column, if we want it. - if (cellCol == firstColIdx && !noCountColumn) colHeader.setCellValue("Count"); - else colHeader.setCellValue(headers[headerIdx - idxAdj]); - colHeader.setCellStyle(boldStyle); - } - } } // Change the first column index to write data to, depending on stack_results status. @@ -217,6 +223,15 @@ public void run(String arg) { if (noCountColumn == true) firstColIdx = firstColIdx + 1; } + // Change the first column and first data row index to write data to, depending on whether an import cell is specified. + if (importCell != null) { + String[] inputCellParts = new String[3]; + CellReference cellRef = new CellReference(importCell); + inputCellParts = cellRef.getCellRefParts(); + firstDataRow = ((int) Integer.valueOf(inputCellParts[1]))-1; + firstColIdx = CellReference.convertColStringToIndex(inputCellParts[2]); + } + // Write dataset label to the first row in the sheet. row = sheet.getRow(DATASET_LABEL_ROW); if (row == null) row = sheet.createRow(DATASET_LABEL_ROW); @@ -326,6 +341,9 @@ private void parseOptions() { // Figure out if we want to place new results data into existing columns // Stacking data instead of placing it adjacent to existing data in the designated spreadsheet stackResults = optionsStr.contains("stack_results"); + + //Figure out if we want to import results data to a specific cell in the spreadsheet + importCell = Macro.getValue(optionsStr, "cell_ref", null); } private static class ExcelHolder {