필터 지우기
필터 지우기

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.

채택된 답변

Chris
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
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
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 CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by