Using Data Scraping method, i have scraped some details from web application and write it as Excel file. In that excel i have Price amount like as 1343.305, 1234.1234 in price column. i want to reduce the decimal points to 2 numbers like 1334.30 for entire column. When i tried the below method using assign activity, getting error in column name. Kindly advise how to fix it.
Hello @BaskaranVenkatesan
You can use linq here
use this code (From x In DT.AsEnumerable() Select DT.Clone.Rows.Add({CDbl(x("Price").ToString.Split("."c)(0)+"."+x("Price").ToString.Split("."c)(1).Substring(0,2))})).copytodatatable
After write in Exce file I had read the same File and stored it as DT1. Then using assign activity i have applied above code. After that what can i do for change decimal point in excel. Please explain clearly.
the above code will make the required changes in your price Column
All you have to do is
add other column Name so for instance if you have two columns Named as ID & Price
than your code should look like this
(From x In DT.AsEnumerable() Select DT.Clone.Rows.Add({(x("ID"),CDbl(x("Price").ToString.Split("."c)(0)+"."+x("Price").ToString.Split("."c)(1).Substring(0,2))})).copytodatatable
thats it you just have to add your column names inside the Curly Brackets in this format x(“ColumnName”)
Than Assign this new value to Datatable Type Variable and write it in an Excel File
I had tried above method but getting an error like as below. Please advise.
(From x In UnitPriceDT.AsEnumerable() Select UnitPriceDT.Clone.Rows.Add({CDbl(x(“Unit Price”).ToString.Split(“.“c) (0)+”.”+x(“Unit Price”).ToString.Split("."c)(1).Substring(0,2))})).copytodatatable
Hi, Yes i had copied the code correctly. First i had read the Excel and and stored it as UnitPriceDT. Then using assign activity assign the code to UnitPriceDT. Then again tried to write the Same DT but this also getting the same error message like as “conversion from string”" to type ‘double’ is not valid. This time i had copied the assign activity from your xaml file but getting same error message. Please advise.
Hi Vicky, I had reviewed you Unit Excel, it like same as my column. When i tried to open your xaml file an error message was occurred like as below. This time also i had tried your assign activity but getting same error.
Also Try this and let me know about this code (From x In UnitPriceDT.AsEnumerable() Select UnitPriceDT.Clone.Rows.Add({CStr(If(CStr((x("Unit Price"))).Contains("."),CStr(x("Unit Price")).Split("."c)(0)+"."+CStr(x("Unit Price")).Split("."c)(1).Substring(0,2),x("Unit Price"))) })).copytodatatable