Click here to Skip to main content
15,925,061 members
Home / Discussions / C#
   

C#

 
GeneralRe: Dropdown list value is not retaining on page post back Pin
skhan1731-Aug-09 8:48
skhan1731-Aug-09 8:48 
GeneralRe: Dropdown list value is not retaining on page post back Pin
Christian Graus31-Aug-09 12:03
protectorChristian Graus31-Aug-09 12:03 
GeneralRe: Dropdown list value is not retaining on page post back Pin
stancrm31-Aug-09 20:30
stancrm31-Aug-09 20:30 
GeneralRe: Dropdown list value is not retaining on page post back Pin
skhan171-Sep-09 3:09
skhan171-Sep-09 3:09 
AnswerRe: [Message Deleted] Pin
Luc Pattyn31-Aug-09 16:19
sitebuilderLuc Pattyn31-Aug-09 16:19 
QuestionUDP-Server (Connection closed by remote host!?) Pin
softwarejaeger31-Aug-09 5:52
softwarejaeger31-Aug-09 5:52 
GeneralRe: UDP-Server (Connection closed by remote host!?) Pin
harold aptroot31-Aug-09 7:00
harold aptroot31-Aug-09 7:00 
QuestionInterop.Excel (2007) Trouble... Pin
Jacob Dixon31-Aug-09 5:48
Jacob Dixon31-Aug-09 5:48 
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();

AnswerRe: Interop.Excel (2007) Trouble... Pin
Not Active31-Aug-09 6:54
mentorNot Active31-Aug-09 6:54 
GeneralRe: Interop.Excel (2007) Trouble... Pin
Jacob Dixon31-Aug-09 7:51
Jacob Dixon31-Aug-09 7:51 
GeneralRe: Interop.Excel (2007) Trouble... Pin
Not Active31-Aug-09 8:18
mentorNot Active31-Aug-09 8:18 
AnswerRe: Interop.Excel (2007) Trouble... Pin
FilipKrnjic1-Sep-09 4:00
FilipKrnjic1-Sep-09 4:00 
GeneralRe: Interop.Excel (2007) Trouble... Pin
Jacob Dixon1-Sep-09 4:01
Jacob Dixon1-Sep-09 4:01 
QuestionOracle Parser Pin
Fayu31-Aug-09 5:17
Fayu31-Aug-09 5:17 
AnswerRe: Oracle Parser Pin
Richard MacCutchan31-Aug-09 6:16
mveRichard MacCutchan31-Aug-09 6:16 
GeneralRe: Oracle Parser Pin
Fayu31-Aug-09 6:47
Fayu31-Aug-09 6:47 
GeneralRe: Oracle Parser Pin
Richard MacCutchan31-Aug-09 7:12
mveRichard MacCutchan31-Aug-09 7:12 
GeneralRe: Oracle Parser Pin
Fayu31-Aug-09 7:18
Fayu31-Aug-09 7:18 
GeneralRe: Oracle Parser Pin
Richard MacCutchan31-Aug-09 9:15
mveRichard MacCutchan31-Aug-09 9:15 
GeneralRe: Oracle Parser Pin
Fayu4-Sep-09 7:30
Fayu4-Sep-09 7:30 
GeneralRe: Oracle Parser Pin
Richard MacCutchan4-Sep-09 8:02
mveRichard MacCutchan4-Sep-09 8:02 
AnswerRe: Oracle Parser Pin
Pete O'Hanlon31-Aug-09 9:32
mvePete O'Hanlon31-Aug-09 9:32 
QuestionPictureBox Stretch Problem Pin
Muammar©31-Aug-09 5:09
Muammar©31-Aug-09 5:09 
QuestionConnect to VPN server Pin
yogesh_softworld12331-Aug-09 4:41
yogesh_softworld12331-Aug-09 4:41 
AnswerRe: Connect to VPN server Pin
stancrm31-Aug-09 8:16
stancrm31-Aug-09 8:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.