フィルターのクリア

Error using xlswrite. Invalid sheet name '1'.

12 ビュー (過去 30 日間)
Andres Fonts
Andres Fonts 2017 年 1 月 31 日
コメント済み: Mathias Marley 2017 年 2 月 13 日
Hi! I am writting to see if you can help me with a strange issue that appeared me without any explanation...
I would like to use the xlswrite function this way:
data = 1:2;
filename = 'file.xlsx';
xlswrite(filename,data)
And I don't know why, I get this error:
Error using xlswrite (line 219)
Invalid sheet name '1'. Sheet names cannot exceed 31 characters and cannot contain any of these characters:
': / ? * [ ]'.
Does that make sense? I am not setting any kind of sheet name and it is complaining about it. So, looking to the help xlswrite menu I can see that the ARRAY field should be a cell, not a double. Ok, so changing this does not make the difference either...
I have also tried to use the activeX way to create a excel file and everything works fine, but it is quite tedious to make my own "xlswrite" function... I would like to know how to solve this problem with xlswrite.
Could you help me?
Thanks! Andres Fonts
[EDIT] Solved! The xlswrite function was corrupted. There was a code error in line 258.

採用された回答

Jan
Jan 2017 年 1 月 31 日
This is a strange problem and does not occur on my computer. This can mean, that one of this happens on your machine:
  • Your xlswrite function is damaged. Do you have write permissions to the toolbox folders?
  • A function called by xlsread is damaged or shadowed by a user defined function. Do you append the folders with your functions on the bottom of the path and not on the top?
  • filename is an existing file with a forbidden sheet name already. Then it would be the question, how this file was created, but this might not concern Matlab. If so, try to rename the sheet in Excel.
  • Anything weird happens. :-) Use the debugger to examine this: set a breakpoint in the failing line and check the name of the sheet. Using double(SheetName) reveals non-printable characters.
  3 件のコメント
Jan
Jan 2017 年 1 月 31 日
:-) Obviously my new crystal ball works as advertised.
I never run Matlab with admin privileges to avoid modifying Matlab's toolbox functions by accident. When I work in a multi-monitor setup, I sometimes loose the contact to the window, which has the keyboard focus. When I then start typing, characters are inserted without intention. But without admin privileges I cannot save these files later on.
Mathias Marley
Mathias Marley 2017 年 2 月 13 日
I got this exact same error. In line 258 I found:
sstartupA09 [theMessage, TargetSheet, visibility] = activate_sheet(Excel,sheet);
sst... is similar to a command I often write in the command window. Somehow I must have opened xlswrite, started typing the command, and saved!

サインインしてコメントする。

その他の回答 (2 件)

Gabriel Delcros
Gabriel Delcros 2017 年 1 月 31 日
You may have to try :
xlswrite ('file.xlsx', data)
If file is already created, he would find it. Or put the path ;)
  1 件のコメント
Andres Fonts
Andres Fonts 2017 年 1 月 31 日
Hi Gabriel, Thanks for answering, but what you are suggesting does not make any difference, I still have the same error. And including or excluding the path does not make the difference either...
I have also tried to create first the file and then execute xlswrite ('file.xlsx', data) and still having the error.
Thanks anyway

サインインしてコメントする。


Gabriel Delcros
Gabriel Delcros 2017 年 1 月 31 日
Oh I know, there is a problem with your data. It does not make sens to him.
Try data = [1:2];
  3 件のコメント
Jan
Jan 2017 年 1 月 31 日
Andres Fonts
Andres Fonts 2017 年 1 月 31 日
Thanks again Gabriel, but data=1:2 is correct.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by