Saving a Table as a SpreadSheet Using a Dialog Box

11 ビュー (過去 30 日間)
Forrest Ward
Forrest Ward 2020 年 7 月 20 日
コメント済み: Thomas Taufan 2020 年 7 月 21 日
Hello, I made a GUI that takes files (from multiple formats) and creates a table out of them. The end result is this large (or sometimes small) table. I would like to put a button on the GUI that tells the user to "Save Table". From this button I would like a Dialog Box to open which then asks the user to name the table then the user selects where on their computer they would like to save it. I am only going to give them the option to save it as a '.xlsx' file extension. So, in short I need to convert my table into an Excel Spreadsheet, then save it as whatever the user types. I have looked at the function 'uiputfile' but its a little confusing and it doesn't seem to do exactly what I would like. Let me know if there is a quick fix or if this problem is too complicated. Any input helps, thanks!!

採用された回答

Image Analyst
Image Analyst 2020 年 7 月 20 日
編集済み: Image Analyst 2020 年 7 月 20 日
Try it this way
% Get the name of the file that the user wants to save.
startingFolder = pwd % Or "c:\mydata" or wherever you want.
defaultFileName = fullfile(startingFolder, '*.xlsx');
[baseFileName, folder] = uiputfile(defaultFileName, 'Specify a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
% Get base file name, so we can ignore whatever extension they may have typed in.
[~, baseFileNameNoExt, ext] = fileparts(baseFileName);
fullFileName = fullfile(folder, [baseFileNameNoExt, '.xlsx']) % Force an extension of .xlsx.
% Now write the table to an Excel workbook.
writetable(T, fullFileName);
  2 件のコメント
Forrest Ward
Forrest Ward 2020 年 7 月 20 日
Wow!! Thank you very much, that worked beautifully!
Thomas Taufan
Thomas Taufan 2020 年 7 月 21 日
Hello Image Analyst, I got a new question. Please kindly help me again, thank you very much

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

その他の回答 (0 件)

カテゴリ

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