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

  • Home
  • SEARCH
  • 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

Using AspectJ, how do you replace an existing annotation? I have the following code
I'm working on a message-passing runtime system that has existing message allocation code that
I'm writing two Django applications: one that generates a lot of data in time,
I'm writing some code that has to cascade delete records in a certain database,
I have used maven plugin for hibernate and it has generated entity classes without
I would like to implement a custom database initialization strategy so that I can
When two models are related to each other, Doctrine automatically generates foreign key constraints
I have a Panatone Huey, a monitor calibration probe (device you attach to the
I'm lazy, I know (by hey, at least next time I Google it then
I'm just learning Python & Django. (Thanks to everyone who contributes here -- it's

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.