473,395 Members | 1,442 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

save listview data to same excel file but different sheet

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

Expand|Select|Wrap|Line Numbers
  1. Public Sub saveExcelFile(ByVal FileName As String)
  2.             Dim xls As New Excel.Application
  3.             Dim sheet As Excel.Worksheet
  4.             Dim i As Integer
  5.             xls.Workbooks.Add()
  6.             sheet = xls.ActiveWorkbook.ActiveSheet
  7.             Dim row As Integer = 1
  8.             Dim col As Integer = 1
  9.             For Each item As ListViewItem In ListView1.Items
  10.                     For i = 0 To item.SubItems.Count - 1
  11.                             sheet.Cells(row, col) = item.SubItems(i).Text
  12.                             col = col + 1
  13.                     Next
  14.                     row += 1
  15.                     col = 1
  16.             Next
  17.             xls.ActiveWorkbook.SaveAs(FileName)
  18.             xls.Workbooks.Close()
  19.             xls.Quit()
  20.     End Sub
  21.  
  22.  
  23. Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
  24.             Dim saveFileDialog1 As New SaveFileDialog
  25.             saveFileDialog1.Filter = "Excel File|*.xlsx"
  26.             saveFileDialog1.Title = "Save an Excel File"
  27.             saveFileDialog1.ShowDialog()
  28.             If saveFileDialog1.FileName <> "" Then
  29.                     saveExcelFile(saveFileDialog1.FileName)
  30.             End If
  31.             MessageBox.Show("Record Saved!")
  32.     End Sub
  33.  
  34.  
Nov 28 '11 #1
1 3859
pod
298 100+
Expand|Select|Wrap|Line Numbers
  1. if fileExist then
  2.   workbook.open file
  3.   worksheet.add sheet
  4.   put content in sheet
  5.   save and close workbook
  6. else
  7.   workbook.add new book
  8.   put content in activesheet
  9.   save and close workbook
  10. end if
  11.  
Nov 29 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: bienwell | last post by:
Hi all, Do you have any source code to import data from Excel file or text file into database in ASP.NET program ? Please give me your reference if you have. Thanks in advance
1
by: Yoavo | last post by:
Hi, I need to read data from excel file. How do I do it ? Yoav.
1
by: madhu sudhan | last post by:
HI, I want to read data from excel file and export this data to dataset. I know abt the basics of opening a file using application, workbook and worksheet classes. But i don't know how to read...
2
by: gireesh21 | last post by:
actually i done it what is the problem is the time stampe i amused is not coming correctly
1
by: spoorthisri | last post by:
how to save html data in excel sheet should happen locally
4
by: Chris Gilpin | last post by:
Hey everybody. I have Access set up using VBA to run a bunch of queries automatically, and then export the results into Excel. The only problem is, I want each query to be exported to the same...
1
slapshock
by: slapshock | last post by:
Hi good day Please help me with my problem i want to save my data into excel using vb.net but i have no idea on how to do it i search in the internet but i couldnt found the answer... Please...
1
by: arshigill | last post by:
I want to import data from excel file inot mysql database table but unable to solve this problem. I have searched google and find an example of importing of CSV excel file. But when I modify it...
0
by: JFKJr | last post by:
Hello everyone! I am trying to export Access table data into Excel file in such a way that the table field names should be in the first line of each column in excel file followed by field data, and...
3
by: qfchen | last post by:
Hi In order to save data into excel file in my application, I need to define Dim excelApp As New Excel.Application but I got error message: "Type Excel.Application" is not defined. What component...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.