Can we rename a Column Name to null value?

Hi all,

I need to rename a column header/Name to empty or null. Is there any way to do that.

I was able to rename the header to other names but not to null.

Used assign activity with
ipDt.Columns(“Column1”).ColumnName = “New column name” and it worked !!

But while giving ipDt.Columns(“Column1”).ColumnName = “” it throws error.

The error msg is (Source: Assign

Message: Exception has been thrown by the target of an invocation.

Exception Type: System.Reflection.TargetInvocationException)

Can we rename column name to null? any suggestions

Thanks in advance.

Hi @VishnuMV

You can try with write cell activity

image

Regards
Gokul

Hi @VishnuMV ,

You can’t rename it to null, also I’m not sure exactly why you want to rename it to null.

If you don’t want to reference the columns by their names, you have the option of doing so through the index(location)

CurrentRow(0).ToString

Is there any specific reason as to why you want to rename it to null?

Kind Regards,
Ashwin A.K

Are u sure we can’t rename to null?

It is requirement! need to remove the generated column Header names to null but the column values has to be present.

Hi @VishnuMV ,

You can try toggling off Add Headers and read the column from the second line like so:

image

But even then, the system will generate its only set of columns.
Say you have five columns, these are the names of the autogenerated Columns:

[Column1,Column2,Column3,Column4,Column5]

But that doesn’t matter, since when you are writing the range back to Excel, you can toggle Add Headers off once again, and it will add the items from A2 onwards.

image

Kind Regards,
Ashwin A.K

HI @VishnuMV

If you want to rename all the column in the excel file

Regards
Gokul

Tried toggling off headers.

But I need to keep the first header and have to remove all other column headers.

Hi

We won’t be able to name a column as empty when it is a DATATABLE

but

We can name that in an excel
Using WRITE CELL activity

It worked for me

The steps involved is as follow

  1. Say you have a DATATABLE named dt

  2. Get the column index of that column to get the cell position

str_cellposition = Convert.ToChar(65 + dt.Columns.IndexOf(“Columnname”) ).ToString + (dt.Rows.IndexOf(CurrentRow)+1).ToString

  1. Use a write range and pass dt as knock and enable add headers so that it will first write the entire DATATABLE to the excel file

  2. Now use a Write cell activity and mention the input value as String.Empty and cell position as str_cellposition

This will work

And if you want to use that as a DATATABLE once after using write cell activity use a rrad range act and get the DATATABLE with header
Now the column with empty header will come as Column1

Cheers @VishnuMV

Hi @VishnuMV ,

An Alternate Method would be to Add another Data Row as the first row with the values of the Column Names.

Then Later, we can choose which of the values you need to make null.

For instance, the below example adds an Empty Row at the first and then using the Write Range Activity without Add Headers enabled, we get the Empty values as the first row in Excel or as the Column Names in Excel.

image

Creating a New Datarow and adding at the first position.

Resultant DT with Empty first row values which you can make as the Columns in Excel
image

But we do need to understand that since we have to reference each of the column with some name, if the column Names are empty we get Column1, Column2, Column3,.... and so on as default column names

Workflow attached below :
UpdateColumNames_To_Empty.xaml (8.7 KB)

Let us know if you are still facing difficulties and maybe explain as to what are the inputs and output data as a sample in your case.

Hi @VishnuMV

As said in the pervious post you can try with Write cell activity

Regards
Gokul