Effacer les filtres
Effacer les filtres

writetable resizing column widths

25 vues (au cours des 30 derniers jours)
Calvin Ebert
Calvin Ebert le 8 Mai 2019
Commenté : Danny Smith le 15 Nov 2022
I am using the following:
writetable(Variable ,'Location', 'Sheet', 'Sheet Name', 'Range', Range, 'WriteVariableNames', false)
It works correctly in writing although it resizes the columns in excel. It is writing to the end of an existing table. Is there any way to avoid this?
  1 commentaire
Danny Smith
Danny Smith le 15 Nov 2022
I was able to avoid auto-resizing of Excel columns when using writetable via a 2-step process:
  • In the Excel file/sheet you are writing to, go to Review>>Protect Sheet. Make sure that 'Format Columns' and 'Format Rows' are unchecked, then press OK
  • When using writetable with the protected sheet, use the Name/Value pair ('UseExcel', true)

Connectez-vous pour commenter.

Réponse acceptée

Calvin Ebert
Calvin Ebert le 31 Juil 2019
Hey anyone reading this, there is a work around but it is kinda annoying. See how you want your columns sized and fill in a row with 'a's at the very very end where it doesnt touch anything (Or at the very top) and have it read (Or save as variable and keep) and write it last.
  1 commentaire
Alex Calder
Alex Calder le 29 Oct 2020
Can you please provide an example, or link to where one is given? Your comment doesn't make it clear exactly what info you are wrting where and in what order. Thanks.

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 8 Mai 2019
No, there is no way to avoid it with writetable(). writetable() does not attempt to preserve formatting or templates or graphics or formulas written into the range.
To have any of those preserved, you need to use actxserver() or a .NET interface to talk to Excel to tell it what needs to be done.

Tags

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by