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
@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
and how do I get the headings output?
@NHoe I am not getting your point. what you want?
eg as string array:
arrColNames = yourDT.Columns.Cast(of DataColumns).Select(Function (x) x.ColumnName).toArray
strFlatString = String.Join(“,”, arrColNames)
This works almost the way I would like it to. How do I get this value into the heading of the new DataTable?
we are not sure if we get your questions as above the datatable.Clone method was mentioned
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)
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
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
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.