From: Naftali Herscovici on
Hello,

I have the following code:
%-------------------------------------------- CODE STARTS -----------------------
file = [pwd '\test.xls'];

%% OPEN EXCEL APPLICATION
h = actxserver('Excel.Application');
% Show the Excel window
set(h, 'Visible', 1);

%% INSERT NEW WORKBOOK
W = h.Workbooks.Add;

%% WORKBOOKS CONTAIN WORKSHEETS
Sheets = h.ActiveWorkBook.Sheets;

Sheets.Add( [], Sheets.Item(3) );
%% ADD DATA AND CHARTS

j=2

%% Rename
Sheets.Item(j).Name = ['s' int2str(j)];

%% Make it "Active"
Sheets.Item(j).Activate;
Activesheet = h.Activesheet;

h.Column(1).NumberFormat='$#,##0.00'; %<=Problem 1
h.Column(1).columnwidth='50'; %<=Problem 1
h.columns(1).HorizontalAlignment = xlCenter; %<=Problem 2
h.columns(1).VerticalAlignment = xlCenter; %<=Problem 2
%% Insert (random) data
A = floor(256*rand(10,1));
ActivesheetRange = get(Activesheet,'Range','A1:A10');
set(ActivesheetRange, 'Value', A);

%<=Problem 1 => It does it for the WHOLE SHEET. I need only column 1 (or column 'A')
%<=Problem 2 => Juts tried to imitate VBA. it does not work

Please advise,

Thank you
From: Andy on
Replace these four lines:

h.Column(1).NumberFormat='$#,##0.00'; %<=Problem 1
h.Column(1).columnwidth='50'; %<=Problem 1
h.columns(1).HorizontalAlignment = xlCenter; %<=Problem 2
h.columns(1).VerticalAlignment = xlCenter; %<=Problem 2

with these four lines:

Activesheet.Columns.Item('A').NumberFormat='$#,##0.00';
Activesheet.Columns.Item('A').ColumnWidth='50';
Activesheet.Range('A1').EntireColumn.HorizontalAlignment = 3;
Activesheet.Range('A1').EntireColumn.VerticalAlignment = 2;
From: Naftali Herscovici on
Excellent, thank you