Merge and Center in Excel
Show older comments
I am using the code below. It works for 'Title1', however for 'Title2' it always merges cells E1:F1 instead of D1:E1 that i specified no matter the different approches I try
e = actxserver('Excel.Application');
% Add a workbook.
eWorkbook = e.Workbooks.Open(dest);
e.Visible = 1;
% Make the first sheet active.
eSheets = e.ActiveWorkbook.Sheets;
eSheet1 = eSheets.get('Item',1);
eSheet1.Activate
% Merge Cells for Title1
eSheet1 = eSheet1.get('Range', 'B1:C1');
eSheet1.MergeCells = 1;
eSheet1.Value = 'Title1';
eSheet1.Font.ColorIndex = 3;
eSheet1.Font.Bold = 1;
eSheet1.HorizontalAlignment = -4108;
% Merge Cells for Title2
eSheet1 = eSheet1.get('Range', 'D1:E1');
eSheet1.MergeCells = 1;
eSheet1.Value = 'Title2';
eSheet1.Font.ColorIndex = 3;
eSheet1.Font.Bold = 1;
eSheet1.HorizontalAlignment = -4108;
Accepted Answer
More Answers (0)
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!