programmatically copy table to another application

R

Randall Arnold

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
 
M

Mike MacMillan

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
 
R

Randall Arnold

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
 
M

Mike MacMillan

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
 
R

Randall Arnold

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


Mike MacMillan said:
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


Randall said:
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
 
M

Mike MacMillan

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/...1E-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


Randall said:
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


Mike MacMillan said:
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


Randall said:
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

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


Randall Arnold wrote:
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
 
R

Randall Arnold

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

Mike MacMillan said:
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/...1E-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


Randall said:
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


Mike MacMillan said:
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


Randall Arnold wrote:
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

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


Randall Arnold wrote:
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
 
M

Mike MacMillan

Randall,
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

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


Randall said:
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

Mike MacMillan said:
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/...1E-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


Randall said:
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


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


Randall Arnold wrote:
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

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


Randall Arnold wrote:
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
 
R

Randall Arnold

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

Mike MacMillan said:
Randall,
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

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


Randall said:
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

Mike MacMillan said:
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/...1E-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


Randall Arnold wrote:
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


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


Randall Arnold wrote:
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

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


Randall Arnold wrote:
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
 

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,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top