Export To Excel

D

Doogie

Is there a way to export data from a control into excel if the control
is not server side? Do I have to do it with java script or can I do
it inside my VB.NET code?
 
M

Mark Rae

Is there a way to export data from a control into excel if the control
is not server side?

Difficult to say without knowing what control it is... You say it's not a
server-side control, so is it an ActiveX control or a Java applet...?
Do I have to do it with java script or can I do it inside my VB.NET code?

See above.
 
D

Doogie

Difficult to say without knowing what control it is... You say it's not a
server-side control, so is it an ActiveX control or a Java applet...?

It's a control built inside the HTML of the page but it does not have
the runat="server" tag in it. So I don't have a way to access it in
VB.NET.

I'm relatively new to ASP.NET (some training) so am not real sure the
best approach at grabbing this control and it's data.

Here is a sample of what the first part of the control's code looks
like in the HTML. I don't have any way that I can see to grab this
"DataTable" control (and it's data) inside VB.NET:

<table id="DataTable" dataSrc="#ReportResult" cellSpacing="0"
cellPadding="1" border="1">
<THEAD>
<TR>
<td class="COLHDR2" onclick="SortFields('@SomeDBParameter')"
width="65">SomeDBValue</td>
<td class="COLHDR2" width="70"
onclick="SortFields('@AnotherDBParameter')">AnotherDBValue</td>
 
M

Mark Rae

It's a control built inside the HTML of the page but it does not have
the runat="server" tag in it.

So what is it, then...???? Where does it come from? What builds it? Where
does it get its data from...?
<table id="DataTable" dataSrc="#ReportResult" cellSpacing="0"
cellPadding="1" border="1">
<THEAD>
<TR>
<td class="COLHDR2" onclick="SortFields('@SomeDBParameter')"
width="65">SomeDBValue</td>
<td class="COLHDR2" width="70"
onclick="SortFields('@AnotherDBParameter')">AnotherDBValue</td>

Wow! It's been a while since I've seen anything like that! Is this even
ASP.NET...?
http://msdn.microsoft.com/library/d...author/dhtml/reference/properties/datasrc.asp

OK, so what is populating the table's dataSrc property...?
 
D

Doogie

You'll have to bear with me. I'm new to ASP.NET and new to this app.
So what is it, then...????
It is a control that is built inside HTML. I'm not sure what else to
say to answer that question.
Where does it come from?
The control? It comes from the HTML side of this page (am I still not
getting the question)?
What builds it?
Again, isn't the HTML inside the page building this control?
Where does it get its data from...?
The data is grabbed from the database and dumped into a dataset. Then
the xml from that dataset is put into a HtmlGenericControl object.
However, once I have left the method that does this and do anything
else, that HtmlGenericControl object is empty. So I can't figure out
how to get my hands on the data.
Is this even ASP.NET Yep

OK, so what is populating the table's dataSrc property...?
Same answer as the data question above (I believe anyways)
 
M

Mark Rae

The data is grabbed from the database and dumped into a dataset. Then
the xml from that dataset is put into a HtmlGenericControl object.

Aha - now we're getting somewhere! OK, so you do have access to the
underlying data... So how precisely do you want to export it to Excel...?
You have a few possibilities here... Do you want to display the data in
Excel in a browser window, create a CSV file which the user can download and
display in Excel etc.

What is the purpose of exporting the data to Excel anyway...? Is the user
going to process it in some way...?
 
D

Doogie

So how precisely do you want to export it to Excel...?

I'd like to create it in a csv file.
What is the purpose of exporting the data to Excel anyway...? Is the user
going to process it in some way...?

the user would like to save the data off and process it at a later
time.
 
D

Doogie

So now that we know what I want to do, does anyone know how I can do
it? How do I get ahold of a control that is built in HTML and not set
as server side and do so inside the VB.NET code?
 
M

Mark Rae

So now that we know what I want to do, does anyone know how I can do
it? How do I get ahold of a control that is built in HTML and not set
as server side and do so inside the VB.NET code?

Apologies - I thought you'd got it...

You don't need to "get ahold" of this control at all, as you already have
the data anyway (i.e. the dataset).

All you need to do is add another button to your page which takes the
dataset and does the export. There are tons of examples of the various ways
you can do this:
http://www.google.co.uk/search?sour...006-28,GGLG:en&q=ASP.NET+DataSet+export+Excel
 
D

Doogie

Hi Mark, I was kind of figuring that would be an option of mine, to
use the dataset originally returned and can do that easily enough.
However, woudln't there be a performance hit of some kind if I'm
storing the data in a control on the page, and I'm storing the same
data in a dataset in memory? By the way, thank you for your continued
help here. :)
 
M

Mark Rae

Hi Mark, I was kind of figuring that would be an option of mine, to
use the dataset originally returned and can do that easily enough.

Sorted, then...?
However, woudln't there be a performance hit of some kind if I'm
storing the data in a control on the page, and I'm storing the same
data in a dataset in memory?

Only, I suppose, if every user always wants to export the data to Excel
every single time they access the page... If that's the case, then there
hardly seems any point in actually displaying the data in the first place...
 
D

Doogie

This seems like a dumb question but I'm going to ask anyways. In
VB.NET (or ASP.NET) if you have a class level variable and you set it
to a value, is there some reason that variable does not retain its
value? I created a class level dataset, dumped the results of my
search into it, walked through it and everything is fine. But the
moment I get out of the method that does the search and do anything
else, that class level variable does not contain any data??????

Does ASP.NET wipe variables - even class level ones for some reason?
 
M

Mark Rae

Does ASP.NET wipe variables - even class level ones for some reason?

Generally speaking, variables are (eventually) collected by the garbage
collecter when they go out of scope - please post your code...
 
D

Doogie

Never mind, I forgot about the whole view state thing with ASP.NET
(It's really hard to switch from behind the scenes and windows
development to the web side. :) Or harder than I thought it would
be. :))
 
D

Doogie

I do have one follow up question. I can get the data to excel just
fine now, I just use the EnableViewState property on the
HTMLGenericControl to keep my data handy. However, the problem I see
is that control has more data in it than is displayed on the form.
Several columns are in there that don't show up on the form.

I did some looking and the whole structure for what is displayed on
the form is built inside the HTML side of the page. Here's a short
version of what I'm looking at in my HTML.

<table id="DataTable" dataSrc="#ReportResult" cellSpacing="0"
cellPadding="1" border="1">
<THEAD>
<TR>
<td class="COLHDR" width="60">UpdateDt</td>
</TR>
</THEAD>
<tr>
<td nowrap><span datafld="UPDATE_DT"></span>&nbsp;</td>
</tr>
</table>

So now I'm not 100% sure how to set this up to display only the
columns that are defined in the HTML, without having to build some
sort of mapping structure. Is there another way?
 
D

Doogie

Oh yeah, because I'm writing the data from this control and it's XML,
Excel always prompts me with the following. Is there a way to set
some setting so the user doesn't get this prompt each time?

"Please select how you would like to open this file:
As an xml list
As a read-only workbook
Use the xml source task pane"

I'd like to just have it open as an XML List but when I do then it
prompts me saying that the "specified XML source does not refer to a
schema" and "Excel will create a schema based on the xml source
data". I'd like to avoid those prompts too because I'm guessing the
user is not going to want to click those everytime.
 
D

Doogie

Never mind, I finally got this to work the way I want. I went back to
using the DataTable (and storing that in the Cache object).
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top