Data written to wrong cell in excel using actxserver
Afficher commentaires plus anciens
Hello - I am writing data from matlab to an excel file using the actxserver tool. I have a few layers of headers I am entering before entering the data. When entering the following code the last header line "Business Name" gets written to the A4 location, NOT the A3 location (where the code should be sending it). If however I change "A3" to "A2" for the location of the "Business Name" it gets written to (the desired but not coded) cell A3.
if true
% code
e = actxserver('Excel.Application');
eWorkbook = e.Workbooks.Add;
e.Visible = 1;
eSheets = e.ActiveWorkbook.Sheets;
eSheet1 = eSheets.get('Item',1);
eSheet1.Activate
eSheet1.Name = 'Smith';
% Format Cells - Top Row
eSheet1 = eSheet1.get('Range', 'A1');
eSheet1.Value = 'Smith County';
eSheet1.Font.Bold = 1;
% Format Cells - 2nd row
eSheet1 = eSheet1.get('Range', 'A2');
eSheet1.Value = 'Contract type 1';
eSheet1.Font.Bold = 1;
% Format cells - 3rd row
eSheet1 = eSheet1.get('Range', 'A3');
eSheet1.Value = 'Business Name';
end
This shifting of the cell entry point propagates down and is repeated as more information is added. Has anyone encountered this before? Is this a bug or a feature?
3 commentaires
Greg
le 27 Nov 2017
You keep reusing eSheet1. This would be ok except it starts as a WorkSheet object, then becomes a Range object. Can't imagine indexing into 'A3' of a single cell makes any sense...
It works for me when I use a different variable for the Range objects.
Emily Carlson
le 27 Nov 2017
Greg
le 27 Nov 2017
=)
Réponses (0)
Catégories
En savoir plus sur Use COM Objects in MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!