Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / December 2005

Tip: Looking for answers? Try searching our database.

VB.Net MS Excel Question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
SHANE CLARK - 14 Dec 2005 16:04 GMT
I have a question...I am attempting to write the values of multiple textboxes to an MS Excel spreadsheet. I would like to be able to write the values to let say a1,b1,c1,d1...ect and then click on a button to write new values to the next row a2,b2,c2,d1...ect...This is what I came up with but it does not do what I need it to do. here is what I am missing.

 a.. I would rather write values to a prexisting MS Excell sheet ex "C:/temp/textexcell.xls"
 b.. when I click on the next button it would use either the code I have or something to prepare the user to write values to the next row.
Thanks in advance for your help!!!
Public Class Form1

   Inherits System.Windows.Forms.Form

   Dim alpha As Char

   Dim beta As Char

   Dim charlie As Char

   Dim num As Integer

   Dim a As String

   Dim b As String

   Dim c As String

   Dim exsell As New Excel.Application

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        num = 1

       alpha = "a"

       beta = "b"

           Charlie ="c"

       a = Convert.ToString(alpha & num)

       b = Convert.ToString(beta & num)

       c = Convert.ToString(Charlie & num)

       Dim exsell As New Excel.Application

       exsell.Visible = True

       exsell.Workbooks.Add()

       exsell.Range(a).Select()

       exsell.ActiveCell.FormulaR1C1 = TextBox1.Text

       exsell.Range(b).Select()

       exsell.ActiveCell.FormulaR1C1 = TextBox2.Text

           textbox1.text =""

       textbox2.text =""

       textbox3.text =""

       

   End Sub

   'Private Sub btnNextRow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

   '    num = num + 1

   '    alpha = "a"

   '    beta = "b"

     '        Charlie ="c"

   '    a = Convert.ToString(alpha & num)

   '    b = Convert.ToString(beta & num)

   '    c = Convert.ToString(charlie & num)

       exsell.Range(a).Select()

       exsell.ActiveCell.FormulaR1C1 = TextBox1.Text

       exsell.Range(b).Select()

       exsell.ActiveCell.FormulaR1C1 = TextBox2.Text

   '    exsell.Range(c).Select()

   '    exsell.ActiveCell.FormulaR1C1 = TextBox3.Text

   'End Sub
Signature

SHANE CLARK

Randy Cragin - 14 Dec 2005 22:44 GMT
First, you'll be spamming your users with Excel apps everytime they click
button1 :).  Fix that first. Next change exsell.Workbooks.Add() to
exsell.Workbooks.Open("C:/temp/textexcell.xls") Without testing it, I'd say
that calling it again when it's open should just pop it to the front, but
check that to be sure.

Do you have a definate number of colums? because plotting by letter & number
is really only useful for very few cells, after that you might want to locate
cells by addressing Cells(row,column) This should act just like a range
object and allow you to select individual cells.  You can either keep track
of the rows in particular to a single user, or search down for the next empty
row and keeping a RowIndex in the scope of your class. Everytime a row is
filled: RowIndex =+1 and call your columns.
cells(RowIndex,1),cells(RowIndex,2) for each colum you want. I'm guessing to
the number of text boxes you have.

Randy

> I have a question...I am attempting to write the values of multiple textboxes to an MS Excel spreadsheet. I would like to be able to write the values to let say a1,b1,c1,d1...ect and then click on a button to write new values to the next row a2,b2,c2,d1...ect...This is what I came up with but it does not do what I need it to do. here is what I am missing.
>
[quoted text clipped - 90 lines]
>
>     'End Sub

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.