|
I am having the hardest time tyring to read from a Excel workbook and putting it into a listview.
I cannot seem to find any good examples online of how to do this with Excel 2007.
Below is basically what I have. It is a standard template. I will NOT know how many rows will be in the workbook either.
So what I am trying to do it take what is in the excel workbook and put it into a listview to get ready to IMPORT into a database.
The reason I am not using the OLB driver is because I didn't really like it. It tended to mess up formats or not import anything.
Excel.Application xla = new Excel.Application();
Excel.Workbook wb = xla.Workbooks.Open(txtFile.Text, 0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "\t", true, false, 0, true, false, false);
Excel.Sheets excelSheets = wb.Worksheets;
Excel.Worksheet ws = (Excel.Worksheet)excelSheets.get_Item(1);
int g = 1;
for (int i = 1; g <= ws.Rows.Count - 1; i++)
{
Excel.Range range = ws.get_Range("A" + i.ToString(), "J" + i.ToString());
System.Array _values = (System.Array)range.Cells.Value2;
ListViewItem lstItem = new ListViewItem();
lstItem.Text = _values.GetValue(g, 1).ToString();
lstItem.SubItems[1].Text = _values.GetValue(g, 2).ToString();
lstItem.SubItems[2].Text = _values.GetValue(g, 3).ToString();
lstItem.SubItems[3].Text = _values.GetValue(g, 4).ToString();
lstItem.SubItems[4].Text = _values.GetValue(g, 5).ToString();
lstItem.SubItems[5].Text = _values.GetValue(g, 6).ToString();
lstItem.SubItems[6].Text = _values.GetValue(g, 7).ToString();
lstItem.SubItems[7].Text = _values.GetValue(g, 8).ToString();
lstItem.SubItems[8].Text = _values.GetValue(g, 9).ToString();
lstItem.SubItems[9].Text = _values.GetValue(g, 10).ToString();
lstImport.Items.Add(lstItem);
g++;
}
xla.Quit();
|
|
|
|
|
If you're just telling us what your working on, then use Twitter or Facebook, otherwise clearly state the problem and/or question you have.
only two letters away from being an asset
|
|
|
|
|
Let me quote this out for you on what I'm trying to do:
So what I am trying to do it take what is in the excel workbook and put it into a listview to get ready to IMPORT into a database.
I did forget to put in the error. It is giving me a index out of range error. Now how about you state "Hey you forgot to post the error it was getting".
I understand that I forgot that. Now I did provide what I was TRYING to do.
So maybe you should read it before jumping down someones throat.
|
|
|
|
|
Jacob Dixon wrote: So what I am trying to do it take what is in the excel workbook and put it into a listview to get ready to IMPORT into a database.
Yes, you've stated that before. Repeating it doesn't change it.
Jacob Dixon wrote: Now how about you state "Hey you forgot to post the error it was getting".
No, it's your responsiblity to include all relavant information.
Jacob Dixon wrote: Now I did provide what I was TRYING to do.
So we are supposed to imply the difficulties and/or exceptions or errors you are getting simply because you've state what you are TRYING to do.
Jacob Dixon wrote: So maybe you should read it before jumping down someones throat.
Perhaps the same advice to you. Read this[^] and pay attention to item #2.
Jacob Dixon wrote: It is giving me a index out of range error.
Have you debugged this code? Where is it throwing this exception? Is it when accessing the Excel Workbook, Row or the ListViewItem. We're not here to debug your code for you.
only two letters away from being an asset
|
|
|
|
|
|
Thank you so much. I will give the free version a try.
Thanks again
|
|
|
|
|
Hi,
I am trying to write custom grammar to parse oracle statements. Can anyone point me to the right direction.
Thanks in advance.
|
|
|
|
|
Could you be a bit more specific as to:
1) what you are trying to achieve
2) what you have tried
3) what problems you encountered.
|
|
|
|
|
I want to write a parser that will allow me to take a pl/sql statement and ensure that the statement is correct based on some type of grammer that I will specify.
I have not tried anything yet because I dont even know where to start. I am looking for a resource which I can start using that will help me acheive my goal.
------------------------------------------------------------
1. Parse a selected plsql statement and validate it based on some grammar.
2. I have not tried anything yet because this is completely new to me. I am hoping someone can point me to some resource/documentation/tutorial that will help me acheive this task.
|
|
|
|
|
OK, but I don't think this is a technical C# question. I would suggest using Google, or the CodeProject search facility, looking for the keywords 'parse' and 'grammar' as a starting point.
|
|
|
|
|
I was hoping it was possible to do this in C#.
|
|
|
|
|
Fayu wrote: I was hoping it was possible to do this in C#.
Well it may be, but before you can start coding you need to design the structure of your program and the logic of your parser and associated grammar. As I said before, try to search on the subjects you are interested in and you may find that someone has written a technical paper on that very subject which will lead you to a solution. Always remember that CodeProject Search and Google are the first steps in finding an answer.
But don't expect anyone on these forums to write your program for you. We are all working on our own problems as well as answering questions.
|
|
|
|
|
I was not expecting you to write code for me. I have googled it and have seen that antlr is one way of going but I wanted to know if it was possible to do this in C#.
|
|
|
|
|
Well, as a general statement yes, it is possible to do it (or anything else) in C#. However, your original question was framed in such a way that implied you were asking for a full solution to your problem.
|
|
|
|
|
Why not take a look at using ANTLR[^]? It even has an PL/SQL grammar available here[^].
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hi,
Why do I get a funny brightening gradient-like behavior when setting the size mode to stretch a small image in a large pictureBox control??
Thank you.
|
|
|
|
|
Hi,
I am suffering from one problem since few weeks. Could you please try to help me?
I am a C# programmer, i have client needs:
He have 10 computers in office (VPN connection). one computer is server and all are clients. server computer has one folder it always updated time to time, i had to writer code to copy that folder from server computer. i made it and it works fine when i run that software in two system LAN connected.
But VPN server needs user authentication. how can i connect to VPN server through C# program, this is my question.
Hope nice to hear from you!
Thanks!
yogesh
|
|
|
|
|
|
i could not open the link given...
yogesh
|
|
|
|
|
Snippet from the link:
For all of you who are looking to do a similar feat to what I did, the command is as follows:
rasdial <vpn_name> <vpn_username> <vpn_password>
To disconnect:
rasdial <vpn_name> /d
Thus, in usable terms, my line would look like this:
System.Diagnostics.Process.Start("rasdial.exe", "My_VPN My_Username My_Password");
To disconnect from the VPN, simply use this line:
System.Diagnostics.Process.Start("rasdial.exe", "My_VPN /d");
|
|
|
|
|
Can anyone tell me how shall I create a new control a button inside a textbox. The button will have a search(loop) picture I will use it as a lookup control in my application.
|
|
|
|
|
why put a button inside a text box? Surely a control designed to distinguish importance like a group box would serve a better purpose then trying to couple a text box that contains a button?
|
|
|
|
|
Hi,
use Button.Controls.Add() ;-
bye
|
|
|
|
|
You have it backwards, he wants a button within a text box, not the other way around.
|
|
|
|
|
Take a look at the source code for v 1.1 in this[^] article. The FileChooserLibrary contains a control which enables the sort of functionality you are looking for. It is unfinished, but working, and should give you some ideas at the very least.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|