Write table with UIPUT file

Hello,
I am having issues writing a table to a specific sheet in excel. The error i see is "Invalid parameter name: Sheet.". Also pasting part of my code any help is appriciated. Only pasting a part of it as it is huge code filtering a lot of data and i am only having issue when i am trying to write this table to a specific sheet.
Thanks
T2 = table(Text2,Value2,Unit2);
[fname,pname] = uiputfile('*.xls');
writetable(T1,'(pname,fname)','Sheet',1,'Range','A2:end,:');
writetable(T2,'(pname,fname)','Sheet',2,'Range','A2:end,:');

回答 (1 件)

Jakob B. Nielsen
Jakob B. Nielsen 2020 年 2 月 18 日
編集済み: Jakob B. Nielsen 2020 年 2 月 18 日

0 投票

Try typing this bit in the command window:
>> '(pname,fname)'
ans =
'(pname,fname)'
So your path is a string named (pname,fname) - not your actual path string.
In addition, your range syntax is bad. You have to specify endpoints as specific cell numbers... Although, if you write your entire table, you dont even need to specify end points - just give the start point.
If you dont want to write the entire table, specify which part of the table you want to write, instead of using the spreadsheet corners as constraints, its much more neat.
Here:
writetable(T1,[pname,fname],'Sheet',1,'Range','A2');
writetable(T2,[pname,fname],'Sheet',2,'Range','A2');

3 件のコメント

Sai Gudlur
Sai Gudlur 2020 年 2 月 18 日
I made the changes suggested and i still get the same error message."Error using writetable (line 142)
Invalid parameter name: Sheet." Also checked the fname,pname type and it shows me filename that i keyed in and path where it was to be saved. Have pasted the response from workspace.
>> fname,pname
fname =
'Trial.xlsx'
pname =
'C:\Users\agudlur\Desktop\'
Jakob B. Nielsen
Jakob B. Nielsen 2020 年 2 月 18 日
Odd. I made a dummytable and tried writing it using the exact piece I posted, and it works just fine... Post the relevant script lines again? It seems odd that you get the error.
Sai Gudlur
Sai Gudlur 2020 年 2 月 18 日
It seems strange to me too but made another change seemed redundant to me but worked. Pasting the code below. that worked
[fname,pname] = uiputfile('*.xlsx');
fullfilename2 = fullfile(pname,fname);(added fullfile built in function)
writetable(T1,(fullfilename2),'Sheet',1,'Range','A2');
writetable(T2,(fullfilename2),'Sheet',2,'Range','A2');
Thanks a lot for your it help Jakob.

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

カテゴリ

ヘルプ センター および File ExchangeText Data Preparation についてさらに検索

製品

リリース

R2018b

質問済み:

2020 年 2 月 18 日

コメント済み:

2020 年 2 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by