Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# interacting with Excel

C# interacting with Excel

Scheduled Pinned Locked Moved C#
csharpvisual-studiotutorialquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    Ismael Oliveira 2021
    wrote on last edited by
    #1

    Hello. I use C# in Visual Studio and need to work with Excels spreadsheets. I know how to create and save the spreadsheets, but I need to format the plan, like to define the cell color, a collumn width and so on. Can anyone tell me how to access the commands in Excel through C#? Thanks.

    Richard DeemingR L S 3 Replies Last reply
    0
    • I Ismael Oliveira 2021

      Hello. I use C# in Visual Studio and need to work with Excels spreadsheets. I know how to create and save the spreadsheets, but I need to format the plan, like to define the cell color, a collumn width and so on. Can anyone tell me how to access the commands in Excel through C#? Thanks.

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      How to access Office interop objects - C# Programming Guide | Microsoft Docs[^] How to automate Microsoft Excel from Microsoft Visual C#.NET - Office | Microsoft Docs[^] Microsoft.Office.Interop.Excel Namespace | Microsoft Docs[^] NB: You will need Office installed on the computer where your application runs, and you cannot use Office Interop from an unattended application like ASP.NET or a Windows service:

      Considerations for server-side Automation of Office[^]

      Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      I 1 Reply Last reply
      0
      • I Ismael Oliveira 2021

        Hello. I use C# in Visual Studio and need to work with Excels spreadsheets. I know how to create and save the spreadsheets, but I need to format the plan, like to define the cell color, a collumn width and so on. Can anyone tell me how to access the commands in Excel through C#? Thanks.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        You can use the Range[^] class to refer to rows, columns and cells. You can add formatting, formulas etc through these objects. I have a sample application that contains the following sequence to control a range of cells:

        cellRange = worksheet.get_Range("D2", "D6"); // select some cells
        cellRange.Formula = "=RAND()*100000"; // add a formula to each cell
        cellRange.NumberFormat = "£#,##0.00"; // format the values as pounds sterling

        There are a number of websites run by Excel experts that offer help which Google can find for you.

        1 Reply Last reply
        0
        • Richard DeemingR Richard Deeming

          How to access Office interop objects - C# Programming Guide | Microsoft Docs[^] How to automate Microsoft Excel from Microsoft Visual C#.NET - Office | Microsoft Docs[^] Microsoft.Office.Interop.Excel Namespace | Microsoft Docs[^] NB: You will need Office installed on the computer where your application runs, and you cannot use Office Interop from an unattended application like ASP.NET or a Windows service:

          Considerations for server-side Automation of Office[^]

          Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          I Offline
          I Offline
          Ismael Oliveira 2021
          wrote on last edited by
          #4

          Thanks Richard.

          1 Reply Last reply
          0
          • I Ismael Oliveira 2021

            Hello. I use C# in Visual Studio and need to work with Excels spreadsheets. I know how to create and save the spreadsheets, but I need to format the plan, like to define the cell color, a collumn width and so on. Can anyone tell me how to access the commands in Excel through C#? Thanks.

            S Offline
            S Offline
            SpiveyC
            wrote on last edited by
            #5

            I use the EPPlus lib. Gives me full control

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups