Data written to wrong cell in excel using actxserver
이전 댓글 표시
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
Greg
2017년 11월 27일
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
2017년 11월 27일
Greg
2017년 11월 27일
=)
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Use COM Objects in MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!