Let’s say you want to add the cell “New Value” at the end of the Excel file named emptyRows.xlsx:

To add a row after the last line of this file, you’ll first need to know the number of empty rows using getRowNumberXlsx (see previous article). This is done by identifying the row number of the first row with content, namely firstRowWithContent. The number of the row to which you would like to add content would be:

new row number = row number of the first row with content+number of rows with content

because

row number of the first row with content = number of empty rows+1

Then, you just have to write it on the Excel file using the MATLAB function xlswrite:

fileName = 'emptyRows.xlsx';
sheetNumber = 1;
fullPath = pwd;
columnNumber = 1;
value = 'firstRowWithContent';
rowNumberOfFirstRowWithContent = getRowNumberXlsx(fileName, ...
sheetNumber, fullPath, columnNumber, value);
winopen(fileName)