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

Answers (1)

"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 Comment

Thanks, I will also try your suggestion. I didn't realize one could format the table before moving to excal
- Mike

Sign in to comment.

Categories

Products

Release

R2024a

Asked:

on 3 Apr 2026 at 19:41

Commented:

on 4 Apr 2026 at 18:52

Community Treasure Hunt

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

Start Hunting!