writecell command is not working.

31 visualizzazioni (ultimi 30 giorni)
Pappu Murthy
Pappu Murthy il 15 Dic 2021
Commentato: Pappu Murthy il 15 Dic 2021
When trying to write cell with only entity it does not work. if I have more than one entity it works fine.
For e.g.
Hdr1 = {'Test_1','Test_2'};
Hdr2 = {'Test_1','Test_2','Test_3'};
Fn = "Testing.xlsx";
writecell(Hdr1,Fn,'WriteMode','Append')
writecell(Hdr2,Fn,'WriteMode','Append')
the above code works just fine and the output excel sheet has two rows.
However the same code with one change:
Hdr1 = {'Test_1'};
Hdr2 = {'Test_1','Test_2','Test_3'};
Fn = "Testing.xlsx";
writecell(Hdr1,Fn,'WriteMode','Append')
writecell(Hdr2,Fn,'WriteMode','Append')
the above does not work and gives error. The only difference I see is that Hdr1 has only one element instead of two elements.
Error:
Error using writecell (line 195)
Unable to determine range. Range must be of the form 'A1' (cell), 'A:B' (column-select), '1:5' (row-select),
'A1:B5' (rectangle-select), or a valid named range in the sheet.
  3 Commenti
Geoff Hayes
Geoff Hayes il 15 Dic 2021
@Pappu Murthy - which line of code is generating the error?
Pappu Murthy
Pappu Murthy il 15 Dic 2021
The last line is giving error.

Accedi per commentare.

Risposta accettata

Image Analyst
Image Analyst il 15 Dic 2021
Looks like it expects the data to be inserted to have the same number of columns as the existing stuff above it. You can use xlswrite() instead. I'm pretty sure xlswrite() just blasts over existing stuff without caring about that. However you will have to call xlsread() first to find out how many rows are there already and make sure you write into the row one below the last row.
  5 Commenti
dpb
dpb il 15 Dic 2021
What about kludges like
Hdr1 = {'Test_1',''};
...
or
Hdr1 = {'Test_1',' '};
? First is empty second string, second just a blank, but both have two elements.
Perhaps one can fool MATLAB if not Mother Nature...
Pappu Murthy
Pappu Murthy il 15 Dic 2021
The second suggestion worked just fine. Thanks. We can close this.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by