0
I am making an excel import for a dataGridView and the formatting of the field type Value does not bring the comma, period and decimal place, example:
In the Excel
it’s like this: 995.800,00 (certain) and after import into dataGrdiView
gets like this: 995800 (wrong)
Relevant excerpt from Code c#:
FileInfo File = new FileInfo(txtArquivoOrigem.Text);
ExcelPackage package = new ExcelPackage(new FileInfo(txtArquivoOrigem.Text));
ExcelWorksheet workSheet = package.Workbook.Worksheets.First();
for (int i = workSheet.Dimension.Start.Row + 1; i <= workSheet.Dimension.End.Row; i++)
{
Cliente cliente = new Cliente();
for (int j = workSheet.Dimension.Start.Column; j <= workSheet.Dimension.End.Column; j++)
{
if (j == 9)
{
decimal faturamento;
bool resultado = decimal.TryParse(workSheet.Cells[i, j].Value.ToString(), out faturamento);
if (resultado)
cliente.Faturamento = Convert.ToDecimal(workSheet.Cells[i, j].Value.ToString());
}
}
lCliente.Add(cliente);
}
I tried to implement the suggestion of Vik , but does not compile, returns the following error: None under load for the "Tostring" method takes 1 arguments. :
tried to implement the suggestion, but neither compile, returns the following error:
Nenhuma sobre carga para o método "ToString" leva 1 argumentos.
, I changed the post and put the error print.– hard123
Billing = billing; and then when presenting the result use then. Tostring("n"), you cannot use this string format on Object type objects... post the code of how to display/pass the data to the datagridview
– vik
could make a customer. Billing = Convert.Todecimal(billing.Tostring("n")); but would only take the two decimal places, to also take the thousands separator will have to format the decimal var at "output".
– vik