Could you please help me how to achieve a Excel created and downloaded using C# having amount column should show as millions for other currencies. But for INR it should show in lakhs.

Soumya Ganapathi 1 Reputation point
2021-02-10T12:42:58.717+00:00

I am generating an excel with some amounts columns in it using C#.
After downloading user should see the values in Lakhs if the currency of those amounts are in INR and if it is in other currencies it should show in Millions.

Developer technologies | C#
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Daniel Zhang-MSFT 9,656 Reputation points
    2021-02-11T07:03:16.21+00:00

    Hi SoumyaGanapathi-8239,
    First, you can use Microsoft.Office.Interop.Excel to create an excle. And then use Range.NumberFormat property to set the corresponding column to currency format.
    Here is a simple you can refer to.

    using Excel = Microsoft.Office.Interop.Excel;  
      
    Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();  
    Excel.Workbook xlWorkBook;  
    Excel.Worksheet xlWorkSheet;  
    object misValue = System.Reflection.Missing.Value;  
    xlWorkBook = xlApp.Workbooks.Add(misValue);  
    xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);  
    xlWorkSheet.Cells[1, 1] = "ID";  
    xlWorkSheet.Cells[1, 2] = "NUMBER";  
    xlWorkSheet.Cells[2, 1] = "1";  
    xlWorkSheet.Cells[2, 2] = 123;  
    xlWorkSheet.Cells[3, 1] = "2";  
    xlWorkSheet.Cells[3, 2] = 333;  
      
    xlWorkSheet.Range["B2", "B3"].NumberFormat = "[$$-en-US] #,##0.00";  
      
    xlWorkBook.SaveAs(@"C:\Users\Desktop\csharp-Excel.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);  
    xlWorkBook.Close(true, misValue, misValue);  
    xlApp.Quit();  
    

    Best Regards,
    Daniel Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.