Data written to wrong cell in excel using actxserver
Mostrar comentarios más antiguos
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 comentarios
Greg
el 27 de Nov. de 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
el 27 de Nov. de 2017
Greg
el 27 de Nov. de 2017
=)
Respuestas (0)
Categorías
Más información sobre Use COM Objects in MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!