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!