writematrix resizing column widths
40 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Ron Fredericks
el 26 de Abr. de 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.
Respuestas (2)
Fangjun Jiang
el 3 de Dic. de 2020
Look for the 'PreserveFormat' and the 'UseExcel' properties.
Also, look for the writecell() function.
0 comentarios
Robert
el 7 de Sept. de 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 comentarios
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!