473,749 Members | 2,451 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

save listview data to same excel file but different sheet

4 New Member
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 3900
pod
298 Contributor
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
4347
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
2367
by: Yoavo | last post by:
Hi, I need to read data from excel file. How do I do it ? Yoav.
1
5980
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 data from the excel file to populate it into the dataset. I think i have to use the class Range. Can any one explain how to do it ????????????? Thank YOU
2
1618
by: gireesh21 | last post by:
actually i done it what is the problem is the time stampe i amused is not coming correctly
1
1713
by: spoorthisri | last post by:
how to save html data in excel sheet should happen locally
4
10504
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 Excel File, but different worksheet. What happens now is that a new Excel file is opened for each query (with the same name, as read-only) and then the data is imported into the correct worksheet number. I just need to figure out a way to have it...
1
2683
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 help me in doing this,if possible please give any simple codes on how to do it i really need the code in doing my projects... thanks in advance
1
4498
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 for my own requirements it does not work. Please help me with an example to import data in colums in exel file into mysql table columns. Thank PHP Lover
0
2112
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 should start from column B in excel. The column A of the excel file should have heading "Extract Policy" followed by checkboxes so that the user can check which policy to extract after downloading the excel file. Can anyone suggest me how to do...
3
2151
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 I might miss? Thanks
0
8997
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8833
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9568
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9389
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9256
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6079
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4709
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3320
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2794
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.