save listview data to same excel file but different sheet

  • (2 Pages)
  • +
  • 1
  • 2

28 Replies - 8379 Views - Last Post: 06 December 2011 - 07:42 PM Rate Topic: -----

#1 sigridish  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 09-November 11

save listview data to same excel file but different sheet

Posted 24 November 2011 - 10:04 PM

hi everybody! i already know how to save in excel using openfiledialog. but what i want to happen is that when i save another file, i want it to be saved in my existing file but in a different sheet. can you guys help me?

this is my code for saving

Public Sub saveExcelFile(ByVal FileName As String)
        Dim xls As New Excel.Application
        Dim sheet As Excel.Worksheet
        Dim i As Integer
        xls.Workbooks.Add()
        sheet = xls.ActiveWorkbook.ActiveSheet
        Dim row As Integer = 1
        Dim col As Integer = 1
        For Each item As ListViewItem In ListView1.Items
            For i = 0 To item.SubItems.Count - 1
                sheet.Cells(row, col) = item.SubItems(i).Text
                col = col + 1
            Next
            row += 1
            col = 1
        Next
        xls.ActiveWorkbook.SaveAs(FileName)
        xls.Workbooks.Close()
        xls.Quit()
    End Sub



Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
        Dim saveFileDialog1 As New SaveFileDialog
        saveFileDialog1.Filter = "Excel File|*.xlsx"
        saveFileDialog1.Title = "Save an Excel File"
        saveFileDialog1.ShowDialog()
        If saveFileDialog1.FileName <> "" Then
            saveExcelFile(saveFileDialog1.FileName)
        End If
        MessageBox.Show("Record Saved!")
    End Sub



Is This A Good Question/Topic? 0
  • +

Replies To: save listview data to same excel file but different sheet

#2 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: save listview data to same excel file but different sheet

Posted 24 November 2011 - 10:33 PM

I found this link - it could help you. It's on vbForums:
http://www.vbforums....ad.php?t=501483
Was This Post Helpful? 0
  • +
  • -

#3 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1820
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: save listview data to same excel file but different sheet

Posted 24 November 2011 - 10:41 PM

*Moved to Vb.Net*
Please reserve Vb.Net Programmer forum for non help related questions. Post questions in Vb.Net forum Thanks
Was This Post Helpful? 0
  • +
  • -

#4 sigridish  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 09-November 11

Re: save listview data to same excel file but different sheet

Posted 24 November 2011 - 10:46 PM

isn't this vb.net forums?
Was This Post Helpful? 0
  • +
  • -

#5 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: save listview data to same excel file but different sheet

Posted 24 November 2011 - 10:50 PM

It is. Smohd explained it - the Vb.Net programmers forum is not for programming questions - it is for advanced, non-help related topics.
Was This Post Helpful? 0
  • +
  • -

#6 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1820
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: save listview data to same excel file but different sheet

Posted 24 November 2011 - 10:50 PM

View Postsigridish, on 25 November 2011 - 11:31 AM, said:

isn't this vb.net forums?

Ya sure now it is after I moved it :)
Was This Post Helpful? 0
  • +
  • -

#7 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: save listview data to same excel file but different sheet

Posted 24 November 2011 - 10:51 PM

You posted in the Vb.Net programmers forum and it was inappropriate content so it had to be moved to here.
Thanks for your co-operation :)
Was This Post Helpful? 0
  • +
  • -

#8 sigridish  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 09-November 11

Re: save listview data to same excel file but different sheet

Posted 24 November 2011 - 10:58 PM

sorry guys :|
Was This Post Helpful? 0
  • +
  • -

#9 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: save listview data to same excel file but different sheet

Posted 24 November 2011 - 11:00 PM

Meh. It's nothing :)
We all learn.
Was This Post Helpful? 0
  • +
  • -

#10 sigridish  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 09-November 11

Re: save listview data to same excel file but different sheet

Posted 24 November 2011 - 11:39 PM

JimmyBo,
im using save file dialog. is it still possible to save it in the sheet that i want even if im using save file dialog? because i need 5 sheets for every excel file
Was This Post Helpful? 0
  • +
  • -

#11 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: save listview data to same excel file but different sheet

Posted 25 November 2011 - 12:25 AM

You can display an InputBox, TryParse it into an Integer, then save the sheet at the index specified by the Integer
:)
Was This Post Helpful? 0
  • +
  • -

#12 sigridish  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 09-November 11

Re: save listview data to same excel file but different sheet

Posted 27 November 2011 - 06:54 PM

hi JimmyBo!

would i still use savefiledialog?
i have attached a picture of my form. what im thinking is that, i would add a textbox that would copy the name from combo box2. then in my code, i will activate the sheet that is named from my textbox. is that possible?

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#13 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: save listview data to same excel file but different sheet

Posted 27 November 2011 - 07:07 PM

Yeah, you can use a SaveFileDialog. BTW, your form looks good! :) Keep up the good work.
What the process could be:
  • Enter sheet to be saved
  • Dispay Dialog
  • Save

Was This Post Helpful? 0
  • +
  • -

#14 sigridish  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 09-November 11

Re: save listview data to same excel file but different sheet

Posted 27 November 2011 - 07:15 PM

thanks JimmyBo!

but how can i save the file in an existing excel file if i still use savefiledialog? i want the data to be saved in an existing file but in a different sheet. :|
Was This Post Helpful? 0
  • +
  • -

#15 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: save listview data to same excel file but different sheet

Posted 27 November 2011 - 07:17 PM

Maybe you could load the file, store it in memory, add the worksheets to it and then save it. Is that a kind of all right idea.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2