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. Add column to excel

Add column to excel

Scheduled Pinned Locked Moved C#
helptutorialquestion
4 Posts 3 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.
  • Y Offline
    Y Offline
    yadlaprasad
    wrote on last edited by
    #1

    HI, in my code, I am checking for a excel file exists or not. if it doesn't exists i am trying to creating new one along with some columns. here i am able to create the excel file but i don't know how to add columns to it. can any one please help?? below is my code block.

    private void CheckExcelfile()
    {
    string path = @"C:\Servicedeatils.xls";
    if (!File.Exists(path))
    {
    using (StreamWriter sw = File.CreateText(path))
    {
    How to add columns to the created excel file??

                }
            }
    
            
        }
    

    fttyhtrhyfytrytrysetyetytesystryrty

    D Y 2 Replies Last reply
    0
    • Y yadlaprasad

      HI, in my code, I am checking for a excel file exists or not. if it doesn't exists i am trying to creating new one along with some columns. here i am able to create the excel file but i don't know how to add columns to it. can any one please help?? below is my code block.

      private void CheckExcelfile()
      {
      string path = @"C:\Servicedeatils.xls";
      if (!File.Exists(path))
      {
      using (StreamWriter sw = File.CreateText(path))
      {
      How to add columns to the created excel file??

                  }
              }
      
              
          }
      

      fttyhtrhyfytrytrysetyetytesystryrty

      D Offline
      D Offline
      Dan Mos
      wrote on last edited by
      #2

      This is very wrong. You are not creating a Excel file, but a text file with the extension .xls. To use Excel you mainly have 2 options: 1) Interrop 2) OleDB * 3) Commercial apps that ease process of writing/reading to/from Excel. Bingle for "Excel C#" and you'll find many resources. Here on CP there are some nice articles on using Excel.

      Just an irritated, ranting son of ... an IT guy. At your trolling services

      1 Reply Last reply
      0
      • Y yadlaprasad

        HI, in my code, I am checking for a excel file exists or not. if it doesn't exists i am trying to creating new one along with some columns. here i am able to create the excel file but i don't know how to add columns to it. can any one please help?? below is my code block.

        private void CheckExcelfile()
        {
        string path = @"C:\Servicedeatils.xls";
        if (!File.Exists(path))
        {
        using (StreamWriter sw = File.CreateText(path))
        {
        How to add columns to the created excel file??

                    }
                }
        
                
            }
        

        fttyhtrhyfytrytrysetyetytesystryrty

        Y Offline
        Y Offline
        yadlaprasad
        wrote on last edited by
        #3

        Hi, Thanks for reply. instead of using File.CreateText, i can use File.Create(path) also i think this will create the required file. but here i am struck with adding columns to it. how to do that?

        fttyhtrhyfytrytrysetyetytesystryrty

        E 1 Reply Last reply
        0
        • Y yadlaprasad

          Hi, Thanks for reply. instead of using File.CreateText, i can use File.Create(path) also i think this will create the required file. but here i am struck with adding columns to it. how to do that?

          fttyhtrhyfytrytrysetyetytesystryrty

          E Offline
          E Offline
          Estys
          wrote on last edited by
          #4

          You should read the reply from MDL=>Moshu more carefully. There is no such thing as File.CreateExcel(path) in C#. Real xls files are created by Excel or some library that knows about xls files. Cheers

          I don't like my signature at all

          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