How to use xlswrite in an Excel add-in?

1 回表示 (過去 30 日間)
Nebitno
Nebitno 2014 年 3 月 7 日
回答済み: Prateekshya 2024 年 10 月 14 日
Hello,
I am using EX Builder to make an Excel add-in. The add-in should read an m x n matrix from the sheet and write down an m x 3 matrix of outputs. Now, I am OK with the first part which consists of using the xlsread function. However, I am having an issue using the xlswrite function which cannot write into an opened workbook. Is there a way to work around this problem?
Many thanks!
P.S. I did try to include a piece of code which closes the workbook before applying xlswrite. This works when I run my m file in Matlab, however it still does not work when I build an Excel add-in.
  1 件のコメント
Jan Eikeset
Jan Eikeset 2016 年 7 月 15 日
Has anybody found an answer to this question? I find myself in a similar situation.

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

回答 (1 件)

Prateekshya
Prateekshya 2024 年 10 月 14 日
Hello Nebitno,
To write data into an excel sheet, you can use writematrix for R2019a and later versions:
  • If you are using a MATLAB version that supports writematrix, it provides a more robust way to write data to Excel files. However, it still requires the workbook to be closed.
writematrix(outputData, 'yourfile.xlsx', 'Sheet', 1, 'Range', 'A1');
For more information on the writematrix function, please go through the following documentation link: https://www.mathworks.com/help/matlab/ref/writematrix.html#mw_bf4dd90e-62a2-42b7-8c53-3ac04cea640a
  • If you must use xlswrite, ensure that the workbook is closed programmatically before writing. However, this approach might not be ideal in an add-in environment where the workbook is typically open.
I hope this helps!

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by