How to Write a Multi-Line Character Array to Excel?

17 ビュー (過去 30 日間)
MathWorks Support Team
MathWorks Support Team 2017 年 10 月 2 日
回答済み: MathWorks Support Team 2018 年 1 月 2 日
How to write a multi-line character array (user comments) into an Excel file using 'xlswrite'?
 

採用された回答

MathWorks Support Team
MathWorks Support Team 2017 年 10 月 2 日
Below is an example to write multi-line comments to an excel spreadsheet: 
prompt = {'Pipe Dream','Supplier','Comments'};
dlg_title = 'User Comments';
num_lines = [1 20;1 35;5 50];
user_comments = inputdlg(prompt,dlg_title,num_lines);
filename = 'testfile.xlsx';
sheet = 1;
xlswrite(filename,user_comments(1),sheet,'D40'); % save as cells
xlswrite(filename,user_comments(2),sheet,'D41');
% Add new line characters to the string ends
user_comments(3) = cellfun(@(x) {strcat(x,{newline})},user_comments(3));
% Concatenate the inner cells and remove the trailing newlines
user_comments(3) = cellfun(@(x) {deblank([x{:}])},user_comments(3));
% write the data to cells
xlswrite(filename,user_comments(3),sheet,'D42');

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by