How to name an excel worksheet when using writetable

Is there a simple way to name an the excel worksheet when using the writetable fnx? I am aware of the answer by Thomas Koelen on 8 May 2015 ( https://www.mathworks.com/matlabcentral/answers/215703-changing-the-name-of-the-sheet-in-excel ) but I am hoping there is a more direct and simple method, not involving ActiveX. Instead of an excel workbook with "Sheet1", "Sheet2", etc I want to give specific names to the worksheets.

 Accepted Answer

writetable(TableObj,'test.xlsx','FileType','spreadsheet','Sheet','MyTable')

8 Comments

Thanks, Fangjun Jiang! Worked great with one caveat: I modified your script slightly to (note the quotation marks):
writetable(TableObj,'test.xlsx','FileType','Sheet',"MyTable")
This indeed names the worksheet, but it ADDS this sheet to an excel workbook such that I now have sheet1, sheet2, and then "MyTable".
Is there a way to get prevent the appearance of sheets 1 and 2...it just is messy. Of course I can delete them in Excel, but I'm looking for a streamlined way of creating the excel workbook.
I can't think of anything if you don't want to involve ActiveX. One last resort yet not ideal is that you create a template Excel file ahead of time. This template Excel file only contains one sheet which you can put some useful notes and comments. Write to this template Excel file by creating a new sheet every time. Or, you can even over-write this one pre-existing sheet.
Got it. Thanks. I'm set now. I appreciate your help!
Hi Stephen, did you solve your problem with 3 additional empty Excel sheets? Could you explain me how you did it exactly? I would really appreciate it!
The code allows writing data on the specified, named tab. However, it pushed the tab to the last tab and leaving Sheet 1, Sheet 2, and Sheet 3 in front of the data tab created. This is a problem for later use of collecting data. I could not find any way to delete Sheet 1, Sheet 2, Sheet 3 either. Did anyone solve this issue?
Hastyar Barvar comments to @Seum Bin Rahman
irreverent and sensing for a downlink
Hastyar Barvar:
The topic of the link is how to get rid of the default three sheets that are created, 'sheet1', 'sheet2', 'sheet3' . Deleting those sheets after creation is a valid approach to the question of how to end up with an Excel worksheet that does not have sheets with those names, which is what @Stephen was asking about.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!