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. Using streamwriter into xls. file

Using streamwriter into xls. file

Scheduled Pinned Locked Moved C#
helptutorialquestion
10 Posts 5 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.
  • A Offline
    A Offline
    andredani
    wrote on last edited by
    #1

    Hi would appreciate if you helped me with this strange problem. i´m trying to write text from my listview into a excel file but the problem is that i want to change cells, now its writing in the same cell. for example: a1 a2 a3 a4 subitem[0] subitem[1] subitem[2] subitem[3] subitem[0] subitem[1] subitem[2] subitem[3] tryade this: using (StreamWriter sw = new StreamWriter((path3 + namn), true)) { for (int listIndex = 0; listIndex < this.listView2.Items.Count; listIndex++) { sw.WriteLine(this.listView2.Items[listIndex].Text + this.listView2.Items[listIndex].SubItems[1].Text + this.listView2.Items[listIndex].SubItems[2].Text + this.listView2.Items[listIndex].SubItems[3].Text); } Process.Start(namn); enyone with a good knowledge with this problem??? TNX!!;)

    P 1 Reply Last reply
    0
    • A andredani

      Hi would appreciate if you helped me with this strange problem. i´m trying to write text from my listview into a excel file but the problem is that i want to change cells, now its writing in the same cell. for example: a1 a2 a3 a4 subitem[0] subitem[1] subitem[2] subitem[3] subitem[0] subitem[1] subitem[2] subitem[3] tryade this: using (StreamWriter sw = new StreamWriter((path3 + namn), true)) { for (int listIndex = 0; listIndex < this.listView2.Items.Count; listIndex++) { sw.WriteLine(this.listView2.Items[listIndex].Text + this.listView2.Items[listIndex].SubItems[1].Text + this.listView2.Items[listIndex].SubItems[2].Text + this.listView2.Items[listIndex].SubItems[3].Text); } Process.Start(namn); enyone with a good knowledge with this problem??? TNX!!;)

      P Offline
      P Offline
      pmarfleet
      wrote on last edited by
      #2

      The code you have provided makes no sense. Nothing in your code explicitly refers to Excel. You write some text to a StreamWriter but then don't do anything with it. You call Process.Start with a variable that you haven't defined. What are you trying to do here? When you say you are trying to create an Excel file, do you actually mean a delimited text file?

      Paul Marfleet

      A 1 Reply Last reply
      0
      • P pmarfleet

        The code you have provided makes no sense. Nothing in your code explicitly refers to Excel. You write some text to a StreamWriter but then don't do anything with it. You call Process.Start with a variable that you haven't defined. What are you trying to do here? When you say you are trying to create an Excel file, do you actually mean a delimited text file?

        Paul Marfleet

        A Offline
        A Offline
        andredani
        wrote on last edited by
        #3

        no.. i just givin my example of what i thought.. this code writes in a .xls file but in one cell. I want to change cells foreach subitems.. how do i do that appreciate this. Big tnx!

        P 1 Reply Last reply
        0
        • A andredani

          no.. i just givin my example of what i thought.. this code writes in a .xls file but in one cell. I want to change cells foreach subitems.. how do i do that appreciate this. Big tnx!

          P Offline
          P Offline
          pmarfleet
          wrote on last edited by
          #4

          You haven't posted all your code. There are a number of variables that are not defined. Post all of your code. I can't help you unless I can understand what you are doing.

          Paul Marfleet

          A 1 Reply Last reply
          0
          • P pmarfleet

            You haven't posted all your code. There are a number of variables that are not defined. Post all of your code. I can't help you unless I can understand what you are doing.

            Paul Marfleet

            A Offline
            A Offline
            andredani
            wrote on last edited by
            #5

            ok.. my code to send info from my listview to a .xls file look like this: string[] lines3 = System.IO.File.ReadAllLines("datainställningar.txt"); string path3 = lines3[0]; string text = textBox1.Text; string namn = text + ".xls"; if (MessageBox.Show("Vill du skapa diagramet " + text + "?", "Mitt jobb", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { using (StreamWriter sw = new StreamWriter(path3 + namn)) { for (int listIndex = 0; listIndex < this.listView2.Items.Count; listIndex++) { sw.WriteLine(this.listView2.Items[listIndex].Text + this.listView2.Items[listIndex].SubItems[1].Text + this.listView2.Items[listIndex].SubItems[2].Text + this.listView2.Items[listIndex].SubItems[3].Text); } Process.Start(namn); } } But now it´s writes in only a1 cells in .xls, but i want it to write every subitems in each cell. is it more clearly now?? tnx

            P D 2 Replies Last reply
            0
            • A andredani

              ok.. my code to send info from my listview to a .xls file look like this: string[] lines3 = System.IO.File.ReadAllLines("datainställningar.txt"); string path3 = lines3[0]; string text = textBox1.Text; string namn = text + ".xls"; if (MessageBox.Show("Vill du skapa diagramet " + text + "?", "Mitt jobb", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { using (StreamWriter sw = new StreamWriter(path3 + namn)) { for (int listIndex = 0; listIndex < this.listView2.Items.Count; listIndex++) { sw.WriteLine(this.listView2.Items[listIndex].Text + this.listView2.Items[listIndex].SubItems[1].Text + this.listView2.Items[listIndex].SubItems[2].Text + this.listView2.Items[listIndex].SubItems[3].Text); } Process.Start(namn); } } But now it´s writes in only a1 cells in .xls, but i want it to write every subitems in each cell. is it more clearly now?? tnx

              P Offline
              P Offline
              pmarfleet
              wrote on last edited by
              #6

              AFAIK, there are 2 ways to create an Excel file in .NET. 1. Excel Automation. Allows you to programmatically control the Excel application. Requies Excel to be installed on the machine your application is running on. 2. JET OLEDB Provider. Allows you to connect to an Excel spreadsheet like a database and read/write data to it. Doesn't require Excel to be installed, only the JET driver. Google either of these and you should find numerous examples to get you started.

              Paul Marfleet

              G 1 Reply Last reply
              0
              • P pmarfleet

                AFAIK, there are 2 ways to create an Excel file in .NET. 1. Excel Automation. Allows you to programmatically control the Excel application. Requies Excel to be installed on the machine your application is running on. 2. JET OLEDB Provider. Allows you to connect to an Excel spreadsheet like a database and read/write data to it. Doesn't require Excel to be installed, only the JET driver. Google either of these and you should find numerous examples to get you started.

                Paul Marfleet

                G Offline
                G Offline
                Giorgi Dalakishvili
                wrote on last edited by
                #7

                Here is another method for generating Excel file from c# http://www.codeproject.com/dotnet/ExportToExcel.asp

                #region signature my articles #endregion

                1 Reply Last reply
                0
                • A andredani

                  ok.. my code to send info from my listview to a .xls file look like this: string[] lines3 = System.IO.File.ReadAllLines("datainställningar.txt"); string path3 = lines3[0]; string text = textBox1.Text; string namn = text + ".xls"; if (MessageBox.Show("Vill du skapa diagramet " + text + "?", "Mitt jobb", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { using (StreamWriter sw = new StreamWriter(path3 + namn)) { for (int listIndex = 0; listIndex < this.listView2.Items.Count; listIndex++) { sw.WriteLine(this.listView2.Items[listIndex].Text + this.listView2.Items[listIndex].SubItems[1].Text + this.listView2.Items[listIndex].SubItems[2].Text + this.listView2.Items[listIndex].SubItems[3].Text); } Process.Start(namn); } } But now it´s writes in only a1 cells in .xls, but i want it to write every subitems in each cell. is it more clearly now?? tnx

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #8

                  This code will nevcer generate a REAL .xls file. You can generate a text .CSV (comma seperated values) file that Excel will import but it's not an .xls file.

                  A guide to posting questions on CodeProject[^]
                  Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                       2006, 2007

                  D 1 Reply Last reply
                  0
                  • D Dave Kreskowiak

                    This code will nevcer generate a REAL .xls file. You can generate a text .CSV (comma seperated values) file that Excel will import but it's not an .xls file.

                    A guide to posting questions on CodeProject[^]
                    Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                         2006, 2007

                    D Offline
                    D Offline
                    darkelv
                    wrote on last edited by
                    #9

                    I am not sure why MS decided to make CSV able to be imported into Excel by default. Quite a lot of people I know now, think that anything .CSV is an Excel file. :mad:

                    D 1 Reply Last reply
                    0
                    • D darkelv

                      I am not sure why MS decided to make CSV able to be imported into Excel by default. Quite a lot of people I know now, think that anything .CSV is an Excel file. :mad:

                      D Offline
                      D Offline
                      Dave Kreskowiak
                      wrote on last edited by
                      #10

                      darkelv wrote:

                      I am not sure why MS decided to make CSV able to be imported into Excel by default

                      Because it was too bloody easy?? :confused:

                      darkelv wrote:

                      Quite a lot of people I know now, think that anything .CSV is an Excel file.

                      That shows you how much they really know about Excel and CSV files. Pretty much nothing, right?

                      A guide to posting questions on CodeProject[^]
                      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                           2006, 2007

                      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