Clear cells content

469 views
Skip to first unread message

Lamon

unread,
Nov 25, 2011, 6:00:02 AM11/25/11
to Excel-DNA
Salut Govert,

Any idea on how to clear cells content?

I have search both the Codeplex and Google groupes without success.

I have tried to use:

xlcall.excel(xlcall.xlcClear, xlRef); xlcall.excel(xlcall.xlcClear,
3, xlRef);
XlRef being the range I want to clear.

Without success. Do I need to select the cells before clearing?

Thank you for your support,

Guy

Govert van Drimmelen

unread,
Nov 27, 2011, 5:10:45 AM11/27/11
to Excel-DNA
Hi Guy,

I look at the documentation for the CLEAR macro (equivalent of
xlcClear) in my XLMACR8.HLP file (downloaded from here:
http://www.microsoft.com/download/en/details.aspx?id=24039). It looks
like CLEAR will clear the active sheet or some parts of the active
chart, and CLEAR takes one argument, a type_num that indicates whether
everything should be cleared (1), or only formats (2), contents (3) or
comments (4).

So you cannot pass a range reference into the CLEAR command.

You probably just want to set the value of the cells to empty. For
this you'd need an array of the right size. You can try this as a
start:

[ExcelCommand(MenuName="Test Clear", MenuText="Clear A2:B5")]
public static void ClearA2B5()
{
ExcelReference xlRef = new ExcelReference(1, 4, 0, 1);
int rows = xlRef.RowLast - xlRef.RowFirst + 1;
int cols = xlRef.ColumnLast - xlRef.ColumnFirst + 1;
object[,] values = new object[rows, cols]; // nulls
xlRef.SetValue(values);
}

Regards,
Govert

Lamon

unread,
Dec 1, 2011, 9:00:14 PM12/1/11
to Excel-DNA
Salut Govert,

In fact this exactly what I have done, setting the value to null
(single cell that is).

While I was trying to perform formating operations (column witdh,
borders), I realized, after much testing, that cells needed to be
selected in order to apply formating. Applying the same rule to the
"clear" command was succesful.

The difficult part about "macrofun" is the translation of the
parameters into DNA code.

That being said the more I play with it the more I like it.

Thanks for your support, till next time,

Guy

Reply all
Reply to author
Forward
0 new messages