Search code examples
excelmatlabdelete-row

matlab: delete the last row in excel


I have an excel file with contents and background color,

something like the first row: enter image description here

I want to delete all the contents in the first row, there is a command that do that?

UPDATE:

I succeeded to delete the cells of A3:I3:

esh.Range('A1:I1').value = []; 

I tried to color the J1 cell by white, but it let me the cell of J2 and I need to get the cell of J3.

so I need to color J1 by 'NoFill'.

how can I do that?

I have to say that I always want to delete the last row in the file (the example doesn't show that but always the last line)

you can assume I have the range/number_of_the_row that I want to delete

e = actxserver ('Excel.Application'); %# open Activex server
ewb = e.Workbooks.Open(filename); %# open the file
esh = ewb.ActiveSheet;
clr = [255 255 255] * [1 256 256^2]';
esh.Range('A1:I1').value = [];
esh.Range('J1:J1').Interior.Color = clr;
set(e, 'DisplayAlerts', 0); % Stop dialog!
xlWorkbookNormal = excelWorkbook; %# it's the Excel constant, not sure how to pass it other way
ewb.SaveAs(filename, xlWorkbookNormal)
ewb.Close(false)
e.Quit
e.delete

Solution

  • esh.Range(J1).interior.ColorIndex = 0;