How do I use readcell and keep leading spaces within cells

9 ビュー (過去 30 日間)
John
John 2025 年 8 月 27 日
回答済み: Star Strider 2025 年 8 月 27 日
I have an Excel spreadsheet I need to import using readcell, and some of the cells within the spreadsheet have leading spaces before the text (as a sort of indent to differentiate them when reading).
Currently my code is just a basic readcell command:
raw = readcell([xls_path, '/', xls_filename],'Sheet', sheet_name);
where xls_path, xls_filename, and sheet_name are user inputs from earlier in the program. When Matlab imports the data, all of the spaces at the beginning of the cells are removed.
How can I import the data in the Excel file and preserve the leading spaces in the cells?

回答 (1 件)

Star Strider
Star Strider 2025 年 8 月 27 日
There may be other ways of doing this (and I am not certain that it will work with your Excel fiile), however if you define whitespace as a delimiter, in detectImportOptions, the LeadingDelimitersRule name-value pair could work. In the setvaropts documentation, WhiteSpaceRule could also work.

カテゴリ

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

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by