all groups > asp.net webcontrols > december 2005 >
You're in the

asp.net webcontrols

group:

programmatically copy table to another application


Re: programmatically copy table to another application Mike MacMillan
12/29/2005 11:09:49 AM
asp.net webcontrols: Randall,
if the functionality you require is for someone to copy-and-paste a
table from the website to word, this should be inherently supported
with IE. my recommendation though would be to binary write the html
for the table to the client, but change the ContentType to
application/vnd-msword or application/vnd-msexcel. ive found by binary
writing directly to these applications and letting the os handle which
program to open (hopefully word and excel), the html comes out just
fine, without the need to save files or use the windows clipboard.

let me know if this helps,
Mike MacMillan


[quoted text, click to view]
Re: programmatically copy table to another application Mike MacMillan
12/29/2005 12:30:27 PM
Randall,
ive included a simple page that binary writes the rendered html of a
table to the client using the contentType application/msword.
obviously, this is the most basic example, but should be enough to get
you going. let me know if you have any questions.

<%@ page language="c#" inherits="System.Web.UI.Page"
autoEventWireup="true" %>
<%@ import namespace="System.IO" %>
<%@ import namespace="System.Text" %>
<%@ import namespace="System.Web.UI" %>

<script runat="server">
void OnExportData(object sender, EventArgs e) {
StringWriter sw;
HtmlTextWriter html;
byte[] arStuff;

//** create our output stream and htmltextwriter
sw = new StringWriter();
html = new HtmlTextWriter(sw);

//** get the table's rendered content
tblStuff.RenderControl(html);
sw.Flush();

//** get the byte array of the html output
arStuff = Encoding.ASCII.GetBytes(sw.ToString());

//** set the contentType and binary write to the client
Response.Clear();
Response.ContentType = "application/msword";
Response.AddHeader("Content-Disposition", "inline");
Response.AddHeader("Content-Length", ""+ arStuff.Length);
Response.BinaryWrite(arStuff);
Response.End();
}
</script>

<html>
<head>
<style type="text/css">
tr.columnHeaders td { background-color: #eee; font-weight: bold; }
</style>
</head>
<body>
<form runat="server">

<table border="0" width="100%" cellpadding="2" cellspacing="0"
id="tblStuff" runat="server">
<tr class="columnHeaders">
<td>Column 1</td>
<td>Column 2</td>
<td>Column 3</td>
<td>Column 4</td>
</tr>

<tr>
<td>test data 01</td>
<td>test data 02</td>
<td>test data 03</td>
<td>test data 04</td>
</tr>

<tr>
<td>test data 11</td>
<td>test data 12</td>
<td>test data 13</td>
<td>test data 14</td>
</tr>

<tr>
<td>test data 21</td>
<td>test data 22</td>
<td>test data 23</td>
<td>test data 24</td>
</tr>

<tr>
<td>test data 31</td>
<td>test data 32</td>
<td>test data 33</td>
<td>test data 34</td>
</tr>
</table>

<asp:Button id="btnExport" text="Export Data" onclick="OnExportData"
runat="server"/>

</form>
</body>
</html>



hope this helps,
Mike MacMillan


[quoted text, click to view]
programmatically copy table to another application Randall Arnold
12/29/2005 12:30:41 PM
I'm about to give up on what I thought would be a simple effort but figured
I'd give it one more try here.

I want to programmatically select an html table rendered on an aspx page
(using VB) and copy it to another application (Word, Powerpoint, Excel, et
al)... probably using the Windows clipboard.

So far I have a really crude method that involves saving the table as an
html file, reloading it in Word, copying table to clipboard, etc etc etc--
but *surely* there has to be a more elegant method, ie, accessing the table
as an object right off the web page and copying it from there. Problem is,
I can't find a single example of how to do this and the few suggestions I've
received aren't helpful.

So one last gasp: anyone here have any ideas?

Thanks,

Randall Arnold

Re: programmatically copy table to another application Randall Arnold
12/29/2005 1:17:38 PM
Mike:

Your solution looks more like what I want to do than any other I've come
across, thought of or been told to try. Unfortunately, I lack experience in
this area (binary writes). However, I'll certainly research it because
everything else has failed miserably and I've almost given up getting this
to work.

All I really want is an asp.net web application that presents tables and
charts of quality reports, and allow users to publish them in formats with
which they are accustomed (Word, Powerpoint, et al). I never in my wildest
dreams imagined it'd be as difficult an effort as it has turned out to be.
I hope I can make your suggestion work. Thanks,

Randall

[quoted text, click to view]

Re: programmatically copy table to another application Randall Arnold
12/29/2005 2:56:34 PM
Wow! you sure went to a lot of effort there and I really appreciate it.
Just hope it works!

What's extremely frustrating for me here is that one line of code is all it
takes to get my chart object to the clipboard, to wit:

Clipboard.SetImage(Chart1.GetChartBitmap)

After that, a simple paste operation gets it into Powerpoint:

objPres.Slides(1).Shapes.PasteSpecial(Microsoft.Office.Interop.PowerPoint.PpPasteDataType.ppPasteBitmap,
Microsoft.Office.Core.MsoTriState.msoFalse)

That was all I was looking for, but darned if I could make the quivalent
method (SetDataObject) work for an html table. I'm still blown away by the
fact that Microsoft made this so difficult! But maybe I shouldn't be by
now.

Anyway, I'll give your suggestion a shot! Thanks again.

Randall


[quoted text, click to view]

Re: programmatically copy table to another application Mike MacMillan
12/29/2005 3:20:03 PM
Randall,
i noticed you're using the PowerPoint object directly. another
suggestion then might be to use the COM object's for office to build a
word doc (or whatever format) on the server side, then send it to the
client via the binary write sample from earlier. you can accomplish
this using the Office PIAs (primary interop assemblies):


http://www.microsoft.com/downloads/details.aspx?FamilyId=C41BD61E-3060-4F71-A6B4-01FEBA508E52&displaylang=en

also, make sure you read through the known issues first so you avoid
spinning your wheels:


http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnoxpta/html/odc_piaissues.asp

hope this helps,
Mike MacMillan


[quoted text, click to view]
Re: programmatically copy table to another application Mike MacMillan
12/29/2005 3:53:54 PM
Randall,
[quoted text, click to view]

keep in mind that any office docs u create/manipulate with the pia's
are on the server side, not the client side. you're still bound by the
limitations of http for sending data to the client. a solution for
sending a single table might be to use the pia's to create a word doc,
save it to a temp folder on the server, then send it to the client.
this will allow you more direct control over what is built, rather then
hoping word renders your html correctly.

Mike MacMillan


[quoted text, click to view]
Re: programmatically copy table to another application Randall Arnold
12/29/2005 5:42:17 PM
Thanks again. Your earlier method worked, although with some limitations.
I'll check the links you provided later. I had originally envisioned using
the interops, but just can't figure out how they can help me get the table
object from the asp.net page and into the target application. There's a
serious lack of info out there on this, and people are even telling me it
flat can't be done the way I want to do it (ie, simple and direct). if
that's true, asp.net is seriously flawed IMO.

Randall

[quoted text, click to view]
Re: programmatically copy table to another application Randall Arnold
12/29/2005 11:29:27 PM
This might all be moot if I could place Microsoft Office Web Components on
an asp.net page as I was led to believe was possible. The components aren't
available to Visual Web Developer Express, however, for reasons no one has
been able to explain to me.

What a fiasco. I just want to copy a simple table to another app. I never
in my wildest dreams imagines this task would turn out to be such a
nightmare.

: (

Randall Arnold

[quoted text, click to view]
AddThis Social Bookmark Button