CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2009
    Posts
    27

    Need Help Formatting in OfficeOpenXML via C#

    Wondering if there is someone in this discussion forum who has experienced OfficeOpenXml to be able to give me some enlightenment on how to format cells (or column) so that it is becomes a Number, Category: Accounting or a Number, Category: Currency... all in an Excel spreadsheet as shown in attachment?

    I have tried to do it for hours without any luck ... I do not know where to find documention on this except that of playing with the intellisense objects and would appreciate all the help anyone can give on the matter.

    Thanks so much I really appreciate it.

    Matt

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Need Help Formatting in OfficeOpenXML via C#

    If Open Office Excel has the same format as MS Excel, then I would search for info in msdn.

    Btw, I don't see an attached file.

  3. #3
    Join Date
    Apr 2009
    Posts
    27

    Re: Need Help Formatting in OfficeOpenXML via C#

    Currently the only code I have looks like the one below .. it is not a file I am at that stage where I am trying to make the few lines of code work, unfortunately I do not know if I am even in the right direction: (I cannot seem to put the attachment I was planning
    that attachment does not give much though all
    it shows is a few cells in spreadsheet with numbers and
    $ sign in the format when viewed from excel )

    Anyhow ... first I tried:
    worksheet.Cells[3,5].Style.Numberformat = true; // does not accept the true I was
    // hoping the thing would be intuitive

    So I tried another:

    OfficeOpenXml.Style.ExcelNumberFormat numFrm = new OfficeOpenXml.Style.ExcelNumberFormat(); //no constructor defined it says
    //but when I remove everything
    //to the right of the equal sign
    //the line below gives a use of
    //unassigned variable error

    worksheet.Cells[3,5].Style.Numberformat = numFrm;

    At this point it becomes obvious that I do not know where to go ... I wish there is just a simple way to do this as all I want is to put a $ sign in the values and make it a number with two decimal place ....

    Thanks again for all the help I really appreciate it ..

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Need Help Formatting in OfficeOpenXML via C#

    Quote Originally Posted by matt_1ca View Post
    Anyhow ... first I tried:
    worksheet.Cells[3,5].Style.Numberformat = true; // does not accept the true I was
    // hoping the thing would be intuitive
    You are going to have to lookup what the NumberFormat values are in Msdn. Think about it, do true as a value really make sense? It doesn't because there are too many different formats for a number such as including commas, where the decimal point goes, etc.

    I searched bing or google for "NumberFormat Excel xml" and came up with several helpful hints. Check it out.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured