August 23, 2022, 6:23am
Hi all, I have a table that I read in via read range and whose headings I need for a new data table. The problem is that the original table comes from a report whose columns change from time to time. How can I transfer the headings to a new data table without having to manually adjust the build data table each time?
You can use the
Clone to get the structure of the table that you are reading.
NewDT = InputDT.Clone
Have a look on this thread, this will help you out.
Suppose I have a data table with 5 columns (3 string,2 int32)
I want to get another data table with same headers and same data types
Can I get it Using Build Data Table
August 23, 2022, 6:31am
@Sanjit_Pal , If I clone the datatable I get the complete content, don’t I? but I only need the headings.
@NHoe, by cloning you will get the headers only not the content.
@NHoe use this one to get columns headers
August 23, 2022, 9:06am
and how do I get the headings output?
@NHoe I am not getting your point. what you want?
August 23, 2022, 9:10am
eg as string array:
arrColNames = yourDT.Columns.Cast(of DataColumns).Select(Function (x) x.ColumnName).toArray
strFlatString = String.Join(“,”, arrColNames)
August 23, 2022, 9:18am
This works almost the way I would like it to. How do I get this value into the heading of the new DataTable?
August 23, 2022, 9:22am
we are not sure if we get your questions as above the datatable.Clone method was mentioned
August 23, 2022, 11:33am
I have created a file here. The aim is to get the headings from the DT_Input in the DT_Clone.
Main.xaml (17.7 KB)
August 26, 2022, 8:37am
follow issue i understand.
He has a Source File (ReadRange) where the Header is changed after the Process is developed.
He want a new Datatable what only use the exisiting headers, without this new Header Column.
The new Column ‘Date’ should be ignored, and only the first 2 column should be used.
ReadRange old: ID, OrderNumber
ReadRange new: ID, OrderNumber, Date
WriteRange new: ID, OrdnerNumber
I try a example, and found out dtInput.Clone (only Headers) – with the new Column, and the dtInput.Copy create a copy of the Source File, with the new Headers.
Maybe a solution will be, create a Excel Template with the Header (ID, OrderNumber) and somehow ^^ the new Datatable have only the Column ID, OrderNumber with the row Data.
or Merge Data Table
August 26, 2022, 9:30am
Merge Data Table with a Excel Template
Merge Data Table.zip (67,8 KB)
Create a Excel Template with the Header you need (Template.xlsx) and with MergeDatatable and MissingSchemaAction
ignore you get only this column from the Template with the Data from input.xlsx
August 30, 2022, 2:27pm
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.