write different data types to excel sheet

Hello,
I have a small matrix of data that contains a column of real numbers, a column of integers and a column of cell data. It appears to be stored as cell data, but I would like to keep the format of real, integer and string (different lengths) when I write to an excel spreadsheet. Using writematrix works to write the cell data, but I can't change the data type after that.
line0 is my cell table, and I use:
- writematrix(line0,filename,"Sheet",3,Range="A2:C13")
I could use help with the ability to format the data when writing to the excel file

답변 (1개)

Stephen23
Stephen23 2026년 4월 3일 19:59
"It appears to be stored as cell data"
It is clearly stored as a string array:
S = load('Variable.mat')
S = struct with fields:
CCHdr: {'Amount ($)' 'Cost Center' 'CostCenter Name'} line0: [12×3 string]
S.line0
ans = 12×3 string array
"482918.41" "10110" "AdCom" "0" "10115" "EXCOM" "0" "10120" "FINCOM" "9889.78" "10125" "Technical Committee" "0" "10130" "Education" "332699.87" "10135" "Membership" "7030.74" "10140" "Awards" "0" "10150" "Standards" "81263.02" "10155" "Chapters" "49454.02" "10160" "Other Committee" "22040.27" "20130" "Publication Support" "38579.42" "21020" "Meetings/Conferences"
T = array2table(S.line0, 'VariableNames',S.CCHdr);
T = convertvars(T,[1,2],@double)
T = 12×3 table
Amount ($) Cost Center CostCenter Name __________ ___________ ______________________ 4.8292e+05 10110 "AdCom" 0 10115 "EXCOM" 0 10120 "FINCOM" 9889.8 10125 "Technical Committee" 0 10130 "Education" 3.327e+05 10135 "Membership" 7030.7 10140 "Awards" 0 10150 "Standards" 81263 10155 "Chapters" 49454 10160 "Other Committee" 22040 20130 "Publication Support" 38579 21020 "Meetings/Conferences"
writetable(T,'myexcel.xlsx')

댓글 수: 1

Mike
Mike 2026년 4월 4일 18:52
Thanks, I will also try your suggestion. I didn't realize one could format the table before moving to excal
- Mike

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

제품

릴리스

R2024a

질문:

2026년 4월 3일 19:41

댓글:

2026년 4월 4일 18:52

Community Treasure Hunt

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

Start Hunting!

Translated by