how to determine both of sheet number and name of sheet with (writecell)

22 views (last 30 days)
Hi . I want to create an excel with this properties.
name of sheet = nitrogen
sheet number =2
I use this function but it just determined the number of sheet and didn't change the name of sheet.
writecell(parameter,'Final_data.xls','Sheet',2,'Sheet','nitrogen')
How can I determine both of them ?

Answers (1)

Mathieu NOE
Mathieu NOE on 3 Nov 2022
hello
writecell does not allow you to specify in the same command a sheet number and a sheet name
Specify the worksheet to write to by name or index:
  • name — If the specified sheet name does not exist in the file, then the writing function adds a new sheet at the end of the worksheet collection.
  • index — If the specified sheet index is an index larger than the number of worksheets, then the writing function appends empty sheets until the number of worksheets in the workbook equals the sheet index. The writing function also generates a warning indicating that it has added a new worksheet.
You can use the 'Sheet' name-value pair only with spreadsheet files.
Example: 'Sheet',2
Example: 'Sheet', 'MySheetName'
a simple solution is to fill a first sheet either with empty cell or whatever data you want , then call a second time writecell with the required sheet name , and then it will be your second sheet :
emptycell = cell(1);
parameters = {rand(10,1)};
writecell(emptycell,'Final_data.xls','Sheet',1) % sheet 1
writecell(parameters,'Final_data.xls','Sheet','nitrogen') % sheet 2

Community Treasure Hunt

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

Start Hunting!