MATLAB Answers


How to delete default excel sheets when using writetable function (mac)?

Asked by Kaden Shearer on 13 May 2019
Latest activity Commented on by Sean de Wolski
on 16 Sep 2019
When using the writetable function to add several different sheets, excel generates default (blank) excel sheets at the beginning of the document. I currently am working off a mac computer and thus cannot use the actxserver solutions described in other posts.

  1 Comment

I found a way around it. Create a template Excel sheet with the sheets you want and the name you want, but empty sheets. In your code, before using writetable, use copyfile to copy your template with the name of the file you want to create. Then, when you use writetable, it opens the sheets with sheets with the name you give from this template and fills it in.

Sign in to comment.

2 Answers

Answer by Walter Roberson
on 14 May 2019
 Accepted Answer

Mathworks does not offer any way to do this.
This question was recently explored in the context of someone who was providing sheet names, and was ending up with 3 extra sheets with default names. Someone (dbp I think it was) indicated that when Excel is asked to create a workbook, that it automatically adds the first sheet, and so for compatibility with Excel the first useless sheet is generated. We did not, however, see any good reason for the code to automatically generate sheet2 and sheet3.


Too bad, thank you anyways for the information.
In R2019b, this is now possible.

Sign in to comment.

Answer by Sean de Wolski
on 16 Sep 2019

Starting in R2019b, specifying the sheet will cause "Sheet"+(1:3) to not be created. This is a new feature of 19b.
writetable(t, 'foo.xlsx', 'Sheet', 'T')
Will only have a sheet, "T".


Sign in to comment.