Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6030195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:00:00+00:00 2026-05-23T05:00:00+00:00

i have existing code that generates a spreadsheet from excel using OpenXML. It works

  • 0

i have existing code that generates a spreadsheet from excel using OpenXML. It works fine but i always have to go into the spreadsheet afterwards and add formatting.

Is there anyway in my C# code I can specify that i want a column formatted with a certain number formatting) commas, decimals, etc?

any links to examples would be great.

here is how i am saving data now:

 public void SetCell<T>(string column, uint rowIndex, T value)
    {
        SheetData sheetData = _positionSheet;
        Cell cell = GetCell(sheetData, column, rowIndex);
        string stringValue = value == null ? "" : value.ToString();
        cell.CellValue = new CellValue(stringValue);
        switch (typeof(T).Name)
        {
            case "Date":
            case "DateTime": 
                cell.DataType = CellValues.Date;
                break;
            case "Int32":
                cell.DataType = CellValues.Number;
                break;
            default:
                cell.DataType = CellValues.String;
                break;
        }
    }

below is the GetCell() method (even though i guess thats not really relevant for the question:

 static private Cell GetCell(SheetData sheet, string column, uint rowIndex)
    {
        Cell cell;
        Row row = GetRow(sheet, rowIndex);
        if (row.Elements<Cell>().Where(c => c.CellReference.Value == column + rowIndex).Any())
        {
            cell = row.Elements<Cell>().Where(c => c.CellReference.Value == column + rowIndex).First();
        }
        else
        {
            Cell refCell = null;
            var comparer = new CellComparer();
            foreach (Cell existingCell in row.Elements<Cell>())
            {
                if (comparer.Compare(existingCell.CellReference.Value, column + rowIndex) > 0)
                {
                    refCell = existingCell;
                    break;
                }
            }

            cell = new Cell { CellReference = column + rowIndex };
            row.InsertBefore(cell, refCell);
        }
        return cell;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T05:00:01+00:00Added an answer on May 23, 2026 at 5:00 am

    Yes it’s possible, however it’s all buried deep into styles. Consider using ClosedXML it have object model similar to old good Excel Object Model and uses OpenXML under the hood. Everything is much simplier with it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some existing code that retrieves data from a database using ADO.NET that
I have an existing website that uses the same code base, but is deployed
Using AspectJ, how do you replace an existing annotation? I have the following code
I have been trying to learn how to add testing to existing code --
I have to analyse some existing Erlang code. Does anybody knows about a tool
If I have an existing database, I want to be able to automatically code
For whatever reason, I have a lot of clients that have existing data that's
We have an existing WCF service that makes use of wsDualHttpBinding to enable callbacks
I'm writing a PHP page that generates a podcast feed by scraping an existing
I'm using a custom-built inhouse application that generates a standard set of reports on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.