Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to clear or delete range of cells in an excel file

388 views
Skip to first unread message

Chess Chessi

unread,
Dec 1, 2010, 1:34:05 PM12/1/10
to
Hi friends,

I am wondering how I can clear or delete ranges of cells in excel using Matlab, for example range (a1:f100).

I am beginner and I spend so much time on this, If you know it is a great help for me.

Thank you very much in advance,

John

unread,
Dec 1, 2010, 5:19:05 PM12/1/10
to
"Chess Chessi" <ches...@yahoo.com> wrote in message <id64et$ccc$1...@fred.mathworks.com>...

Hi,

You can use "xlsread" to open an excel file. Then delete the portion of the data you wish and save the changed data as excel file using "xlswrite".

But you should consider that you will loose formats of the cells (color, font etc.) when you save data as *.xls using "xlswrite". If you want to keep the formatting too, you can check File Exchange for other functions to create *.xls.

Regards.

Chess Chessi

unread,
Dec 1, 2010, 5:41:05 PM12/1/10
to
John,

Thank you very much. I am wondering with

>> Then delete the portion of the data you wish and save the changed data as excel file using "xlswrite". <<

you mean writing something like space over the old data or actually delete my data.
I tried writing space (' ') on those cells but my graphs will be screwed. Therefore I prefer clear or delete command if exists.
I have 700000 rows and so many sheets.

Waiting for your helppppppppp
Thanks

"John " <onsekiz...@yahoo.co.uk> wrote in message <id6hkp$g2a$1...@fred.mathworks.com>...

ImageAnalyst

unread,
Dec 1, 2010, 6:45:47 PM12/1/10
to
No - don't do it that way. I'll try to find time later to show you
how to do it by running Excel as an ActiveX server. (No time now...)

John

unread,
Dec 2, 2010, 3:48:05 AM12/2/10
to
If you have only numbers in your Excel sheet, then you don&#8217;t need to deal with ActiveX staff. Just use &#8220;xlsread&#8221; or &#8220;xlswrite&#8221;.

ImageAnalyst&#8217;s way is following:

excel = actxserver('Excel.Application');

file = excel.Workbooks.Open('yourExcelFile.xls&#8217;);

sheet1=excel.Worksheets.get('Item', 'yourSheetName');

range1=get(sheet1,'Range', 'StartCell','EndCell');
% In your case: range1=get(sheet1,'Range', 'A1','F'100);

range1.Value=[];

file.Save;
file.Close;
delete(excel);


Do the steps one by one.

Regards.

ImageAnalyst

unread,
Dec 2, 2010, 6:45:07 AM12/2/10
to
On Dec 2, 3:48 am, "John " <onsekizdegi...@yahoo.co.uk> wrote:
> If you have only numbers in your Excel sheet, then you don’t need to deal with ActiveX staff. Just use “xlsread” or “xlswrite”.
>
> ImageAnalyst’s way is following:

>
> excel = actxserver('Excel.Application');
>
> file = excel.Workbooks.Open('yourExcelFile.xls’);

>
> sheet1=excel.Worksheets.get('Item', 'yourSheetName');
>
> range1=get(sheet1,'Range', 'StartCell','EndCell');
> % In your case: range1=get(sheet1,'Range', 'A1','F'100);
>
> range1.Value=[];
>
> file.Save;
> file.Close;
> delete(excel);
>
> Do the steps one by one.
>
> Regards.

---------------------------
This way will be much faster since you'll only have to launch and
shutdown Excel once instead of twice, plus you'll preserve any
formatting of the cells. Each call to xlsread or xlswrite would cause
Excel to launch and shutdown.

Eng Seng Lim

unread,
May 6, 2011, 12:46:02 AM5/6/11
to
ImageAnalyst <imagea...@mailinator.com> wrote in message <fd029f21-d5e0-4157...@f21g2000prn.googlegroups.com>...

> On Dec 2, 3:48 am, "John " <onsekizdegi...@yahoo.co.uk> wrote:
> > If you have only numbers in your Excel sheet, then you don&#8217;t need to deal with ActiveX staff. Just use &#8220;xlsread&#8221; or &#8220;xlswrite&#8221;.
> >
> > ImageAnalyst&#8217;s way is following:

> >
> > excel = actxserver('Excel.Application');
> >
> > file = excel.Workbooks.Open('yourExcelFile.xls&#8217;);

> >
> > sheet1=excel.Worksheets.get('Item', 'yourSheetName');
> >
> > range1=get(sheet1,'Range', 'StartCell','EndCell');
> > % In your case: range1=get(sheet1,'Range', 'A1','F'100);
> >
> > range1.Value=[];
> >
> > file.Save;
> > file.Close;
> > delete(excel);
> >
> > Do the steps one by one.
> >
> > Regards.
>
> ---------------------------
> This way will be much faster since you'll only have to launch and
> shutdown Excel once instead of twice, plus you'll preserve any
> formatting of the cells. Each call to xlsread or xlswrite would cause
> Excel to launch and shutdown.


Hi, i have others situation similar to this problem.
I have few sheets of 3columns x 757rows data in .xls file, now i want to delete 11th,30th,49th,68th,........ row (in other word is every 19rows) for every sheet.
May i know how to solve this problem? Thanks for helping~

0 new messages