Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 3.5 and Visual Studio. 2008 > Visual Studio 2008
|
Visual Studio 2008 For discussing Visual Studio 2008. Please post code questions about a specific language (C#, VB, ASP.NET, etc) in the correct language forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Studio 2008 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 28th, 2011, 02:01 AM
Registered User
 
Join Date: Nov 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default save listview data to same excel file but different sheet

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?

code for saving:

Code:
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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Save Listview Data to a DataBase ecabralrojas Beginning VB 6 0 June 30th, 2008 10:33 AM
how to save as an excel sheet azizsaad19 Beginning VB 6 2 May 25th, 2007 09:48 AM
to save datagrid content to a excel sheet josna VB.NET 1 March 4th, 2006 07:10 AM
Exporting listview data to excel file dotnetprogrammer VS.NET 2002/2003 2 May 10th, 2005 08:13 AM
save Excel spread-sheet to SQL Server ybao Classic ASP Databases 1 July 12th, 2004 03:02 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.