Why do writematrix et. al. have unexpected behavoir, e.g. they alter Excel formatting?

9 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Chris
Chris il 30 Ott 2021
Modificato: Chris il 30 Ott 2021
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 Commenti
Simon Skillen
Simon Skillen il 27 Mag 2022
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 il 27 Mag 2022
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.

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by