I have a C# program that takes a text file of a legacy report and maps to an excel sheet.
but for the transaction cells it is output as “Number stored as text” this does not allow
any formatting. We want to show 1,000.00 but it only as 1000.
Is there a way I can get this formatting? those columns are Balance and Amount.
here it is defined:
ndcRange = currentSheet.Cells[transactionRowNo + pageOffset, 13];
ndcRange.NumberFormat = "@";
ndcRange.Value2 = tr.Amount;
ndcRange = currentSheet.Cells[transactionRowNo + pageOffset, 16];
ndcRange.NumberFormat = "@";
ndcRange.Value2 = tr.Balance;
Here is some code where some formatting is done:
string balance = transaction;
if (lastSpaceIndex != -1)
{
balance = transaction.Substring(lastSpaceIndex, (transaction.Length)lastSpaceIndex);
}
transac.Balance = balance;
transaction = transaction.Replace(balance, "");
transaction = transaction.Trim();
if (!string.IsNullOrWhiteSpace(transaction))
{
transac.Description = transaction;
}
patient.TransactionsList.Add(transac);
Use Range.NumberFormat from the Microsoft Excel Object Library. Check this link.
Sample code:
References:
How to automate Microsoft Excel from Microsoft Visual C#.NET
StackOverflow example