Export Data to Excel Error:

6 ビュー (過去 30 日間)
Harjas
Harjas 2022 年 6 月 30 日
コメント済み: Image Analyst 2022 年 7 月 4 日
I have three different output arrays as low voltage, med voltage and high voltage. Three arrays have different number of rows. I want to export three arrays as three different columns of same excel sheet.I tried to use the writetable, but after one writetable command, it is giving error
"Unable to write to file 'FlowDistinction_Yearly.xlsx'. You may not have write permissions or the file may be open by another
application."
Code:
filename = 'FlowDistinction_Yearly.xlsx'
writetable(array2table(High),filename,'sheet',1,'Range','A1:')
writetable(array2table(Med),filename,'sheet',1,'Range','A2:')
I checked few other options but most of them require same number of rows but in my case, number of rows will be different for each column.
  1 件のコメント
Harjas
Harjas 2022 年 6 月 30 日
Thanks. It worked

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

採用された回答

Clayton Coonrod
Clayton Coonrod 2022 年 6 月 30 日
A = [1,2,3,4];
B = [5,6,7];
C = [8,9,10,11,12];
ncol=max([length(A),length(B),length(C)]);
ndatasets=3;
T=cell(ndatasets,ncol);
T(1,1:length(A))=table2cell(array2table(A));
T(2,1:length(B))=table2cell(array2table(B));
T(3,1:length(C))=table2cell(array2table(C));
filename='FlowData2.xls';
T=cell2table(T');
writetable(T,filename)
  1 件のコメント
Image Analyst
Image Analyst 2022 年 7 月 1 日
@Harjas's comment moved here:
Thanks! It worked!

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

その他の回答 (2 件)

Cris LaPierre
Cris LaPierre 2022 年 6 月 30 日
編集済み: Cris LaPierre 2022 年 6 月 30 日
I am able to reproduce the error in R2018b. This appears to be an issue that has been fixed in newer versions of MATLAB. Any chance you can update your MATLAB version?
Note that, to write your data , I think you want the following Range syntax
writetable(array2table(High),filename,'sheet',1,'Range','A:A')
writetable(array2table(Med),filename,'sheet',1,'Range','B:B')
  4 件のコメント
Harjas
Harjas 2022 年 7 月 4 日
Okay, I tried to use but it is now giving me invalid parameter name: UseExcel. I have attached the error image for your reference.
Image Analyst
Image Analyst 2022 年 7 月 4 日
@Harjas then just use @Clayton Coonrod's solution which you said already worked.
Otherwise take out the 'UseExcel' parameter. If you still want an .xlsx format workbook created but for some reason do not want Excel to be used, then call tech support and ask them why UseExcel is not working. The UseExcel = false should work for these formats: .xls, .xlsx, .xlsm, .xltx, .xltm

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


Image Analyst
Image Analyst 2022 年 6 月 30 日
Maybe the workbook is still locked because the first call to writetable() has not finished 100%. If you put
pause(2); % Wait 2 seconds for writetable to finish.
in between the calls to writetable, does it work then?
  3 件のコメント
Harjas
Harjas 2022 年 6 月 30 日
編集済み: Harjas 2022 年 6 月 30 日
No,it still gives same error. But, answer given by Clayton worked for me. Thanks for looking into my question.
Image Analyst
Image Analyst 2022 年 7 月 1 日
No problem. Please click "Accept this answer" on his answer below to award him reputation points.

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

カテゴリ

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

タグ

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by