Using streamwriter into xls. file
-
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!!;)
-
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!!;)
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 callProcess.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
-
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 callProcess.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
-
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!
-
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
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
-
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
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
-
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
Here is another method for generating Excel file from c# http://www.codeproject.com/dotnet/ExportToExcel.asp
#region signature my articles #endregion
-
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
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 -
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 -
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:
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