writematrix resizing column widths
42 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I'm using Matlab 2020a. When I use the function writematrix to write data to MS Excel, it changes the column widths. This is obnoxious. How do I tell it to not do that? ActiveX is too much work and overkill for what I need. Is the simple work around just to keep using xlswrite? Yes, I know MathWorks recommends using writematrix etc. over xlsread. Why? xlsread does exactly what I want without changing things I don't want changed.
Mathworks: don't recommend something that doesn't work as well as what it replaces.
1 Kommentar
Ron Fredericks
am 26 Apr. 2022
I am using writematrix() in my code. I had the same problem James describes above - column width uncontrollable and oft times too narrow.
I found a 'nice' workaround:
For me, titles for columns would end up truncated because cell widths (columns) were optimized for the data which took less space. The solution was to write the titles last, after all data was written. Titles are still at the top of the column for me, but now the width is adjusted for titles.
In other words:
Write your longest data cells last - even if those data elements show at the top of the excel worksheet page. The column of data cells will now be formatted to fit the data requiring the widest width.
Antworten (2)
Fangjun Jiang
am 3 Dez. 2020
Look for the 'PreserveFormat' and the 'UseExcel' properties.
Also, look for the writecell() function.
0 Kommentare
Robert
am 7 Sep. 2022
For anyone encountering this problem and using R2020b, set the AutoFitWidth name-value pair for writematrix to false. Unfortunately, this does not help people using R2020a and earlier. The PreserveFormat and UseExcel name-value pairs Fangjun suggests do not help in that case.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Spreadsheets finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!