Why do writematrix et. al. have unexpected behavoir, e.g. they alter Excel formatting?
조회 수: 11 (최근 30일)
이전 댓글 표시
When writing to an existing Excel file, writematrix and its siblings alter extant formatting in the following ways:
1) Column widths are changed
2) Merged cells are unmerged
This behavior is unexpected and frustrating. See attached example code and Excel files.
Furthermore, it would be nice if after writing the data out writematrix would allow the Excel file to recompute all cells before saving the file. In the attached example, a random matrix is written to Columns A:D. Column E sums Columns A:D. When Column E is read into Matlab its contents have not been updated. The user must open Excel, prompting the cells to recompute, then save the file.
These issues occur in 2020a and 2020b.
Solutions that do not require the user to employ ActiveX would be much appreciated. I the user expect the built-in write functions to take care of that. I am not trying to do anything fancy, I merely want to write out data.
The deprecated xlswrite did not have these issues. Its primary problem was that it created a new instance of EXCEL.EXE if one did not exist but then failed to close it. Please avoid that problem when addressing these.
댓글 수: 0
채택된 답변
Chris
2021년 10월 30일
편집: Chris
2021년 10월 30일
Please see this related link:
If I set 'AutoFitWidth', to false, the column width does not change. I don't have Windows or Excel to check, but I would expect that adding
'UseExcel', true, 'PreserveFormat', true
would address the merged cell issue.
So, to recap, the entire function call would look something like:
writematrix(A, fout, 'Range', range_out1, ...
'AutoFitWidth', false, 'UseExcel', true, 'PreserveFormat', true);
댓글 수: 6
Simon Skillen
2022년 5월 27일
I am using 'AutoFitWidth', false, 'UseExcel', true, 'PreserveFormat', true with Matlab R2021a and merged cells become unmerged. Any ideas where to alter my code?
Walter Roberson
2022년 5월 27일
writecell() is the only one documented to preserve formatting and formulas.
The write*() routines leave the excel connection active for performance reasons. The performance hit of creating and destroying the connection each time is quite noticeable.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!