Get input from spreadsheet control to server for processing

A

aspiring geek

Hi all,

I'm new to asp.net, and using Visual Web Dev express. As such I cannot
see the spreadsheet control and directly access the object properties
from the VB code in the back of my page.


I have declared it as an object as follows:
<object classid="clsid:0002E559-0000-0000-C000-000000000046"
id="Spreadsheet1" name="Spreadsheet1" style="width: 331px; height:
215px" >
note: all users have Office 2003 Web Components
Can only interact with this user entered data client-side, via
"document.all.item("Spreadsheet1").csvdata"


<input type=hidden id="TextBox1" name="TextBox1" />
Can only use this client side, so I can't get the contents of
spreadsheet in here and use it on the server. (If someone knows how it
can be done, please share )


<asp:TextBox ID="TextBox2" runat="server" TextMode="MultiLine"
AutoPostBack="True" Height="76px" Width="99px"
Visible="false"></asp:TextBox>
This is an asp box, so users can interact with, but it is not
recognized in client side vbscript. It works if I make it visible and
paste directly.
I was also unsuccessful at getting a javascript function to recognize
this textbox. I kept getting "Object Required" errors.


What I am trying to do is get the csvdata into my temp table. I tried
to do it in the following function (VB on back) and it works if I can
get the data:


Private Sub fnBeforePaste(ByVal txtPassed As String)
Dim i As Int32


Dim Idata() As String = Split(txtPassed, Chr(13) & Chr(10))
'or use Environment.Newline
If InStr(txtPassed, Environment.NewLine) Then
MsgBox("Environment.Newline")
For i = 0 To Idata.GetUpperBound(0) - 1
Dim stCells() As String = Split(Idata(i), Chr(9)) 'or
use ',' for csvdata
stCells(0) = Replace(stCells(0), Chr(10), "")
If Len(stCells(0)) < 2 Then GoTo ExitPasteGrid
AccessDataSource2.InsertCommand = "INSERT INTO Temptbl
(ESN,[MIN]) SELECT '" & stCells(0) & "' AS Expr1, '" & stCells(1) & "'
AS Expr2;"
'"INSERT INTO Temptbl ( ESN, [MIN] ) SELECT " & stCells(0)
& "," & stCells(1)
AccessDataSource2.Insert()
Next
ExitPasteGrid:
'TextBox2.Text = ""
GridEntry.DataBind()
End Sub


This way I can run a query in the database, and return the query
results in a second grid on the page. I have to use something easy for
users to enter two columns of unknown rows of numerical text values in
a temp table in order to join it to the other query table.


Any suggestions on how to approach this problem are much appreciated.
:)
 
J

Jay Pondy

Hi all,

I'm new to asp.net, and using Visual Web Dev express. As such I cannot
see the spreadsheet control and directly access the object properties
from the VB code in the back of my page.


I have declared it as an object as follows:
<object classid="clsid:0002E559-0000-0000-C000-000000000046"
id="Spreadsheet1" name="Spreadsheet1" style="width: 331px; height:
215px" >
note: all users have Office 2003 Web Components
Can only interact with this user entered data client-side, via
"document.all.item("Spreadsheet1").csvdata"


<input type=hidden id="TextBox1" name="TextBox1" />
Can only use this client side, so I can't get the contents of
spreadsheet in here and use it on the server. (If someone knows how it
can be done, please share )

Use Java Script:
TextBox1.value = aspnetForm.Spreadsheet1.csvData;
<asp:TextBox ID="TextBox2" runat="server" TextMode="MultiLine"
AutoPostBack="True" Height="76px" Width="99px"
Visible="false"></asp:TextBox>
This is an asp box, so users can interact with, but it is not
recognized in client side vbscript. It works if I make it visible and
paste directly.
I was also unsuccessful at getting a javascript function to recognize
this textbox. I kept getting "Object Required" errors.

In your client side Java Script Code you need to reference this object
by the Client Side ID that ASP.Net assigns to it:

var myTextBox = aspnetForm. said:
What I am trying to do is get the csvdata into my temp table. I tried
to do it in the following function (VB on back) and it works if I can
get the data:


Private Sub fnBeforePaste(ByVal txtPassed As String)
Dim i As Int32


Dim Idata() As String = Split(txtPassed, Chr(13) & Chr(10))
'or use Environment.Newline
If InStr(txtPassed, Environment.NewLine) Then
MsgBox("Environment.Newline")
For i = 0 To Idata.GetUpperBound(0) - 1
Dim stCells() As String = Split(Idata(i), Chr(9)) 'or
use ',' for csvdata
stCells(0) = Replace(stCells(0), Chr(10), "")
If Len(stCells(0)) < 2 Then GoTo ExitPasteGrid
AccessDataSource2.InsertCommand = "INSERT INTO Temptbl
(ESN,[MIN]) SELECT '" & stCells(0) & "' AS Expr1, '" & stCells(1) & "'
AS Expr2;"
'"INSERT INTO Temptbl ( ESN, [MIN] ) SELECT " & stCells(0)
& "," & stCells(1)
AccessDataSource2.Insert()
Next
ExitPasteGrid:
'TextBox2.Text = ""
GridEntry.DataBind()
End Sub


This way I can run a query in the database, and return the query
results in a second grid on the page. I have to use something easy for
users to enter two columns of unknown rows of numerical text values in
a temp table in order to join it to the other query table.


Any suggestions on how to approach this problem are much appreciated.
:)

Try something like this:

Private Sub Save(ByVal CSV As String)

Dim oStream As New System.IO.StringReader(CSV)
Dim oFields As String() = {}

Using oParser As New TextFieldParser(oStream)

oParser.SetDelimiters(",")

While Not oParser.EndOfData

Try
oFields = oParser.ReadFields()

Try
'Validate Field Contents
Catch Ex As Exception

End Try

Catch ex As Exception

End Try

End While

End Using
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top