Run Excel Template

This is a discussion on Run Excel Template within the DOTNET forums in Framework and Interface Programming category; Hello Apart from the solutions of ActiveX, 3rd Party software, lowing IE security, there are possibly another two solutions that can meet your need. However, the two require not using the standard Excel template file: ===================== Possible Solution 1: Define the template in a web form, and render the web form to xls Step1. Design a HtmlForm as the template. We can easy include pictures in it. In order to dynamically or statically fill a table with data, we can add a ASP.NET GridView control and bind the control the data source. Step2. Add a button "Export" in the asp.net ...

Go Back   Application Development Forum > Framework and Interface Programming > DOTNET

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #11  
Old 09-08-2008, 06:33 AM
Jialiang Ge [MSFT]
Guest
 
Default Re: Run Excel Template

Hello

Apart from the solutions of ActiveX, 3rd Party software, lowing IE
security, there are possibly another two solutions that can meet your need.
However, the two require not using the standard Excel template file:

=====================
Possible Solution 1: Define the template in a web form, and render the web
form to xls

Step1. Design a HtmlForm as the template. We can easy include pictures in
it. In order to dynamically or statically fill a table with data, we can
add a ASP.NET GridView control and bind the control the data source.

Step2. Add a button "Export" in the asp.net page, and add the following
code to its event handler:

// (Suppose "form1" is the server ID of our HtmlForm in step1.)
string attachment = "attachment; filename=Employee.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/ms-excel";
StringWriter stw = new StringWriter();
HtmlTextWriter htextw = new HtmlTextWriter(stw);
form.Controls.Add(gvEmployee);
this.Controls.Add(form);
form1.RenderControl(htextw);
Response.Write(stw.ToString());
Response.End();

When users click on the Export button, ASP.NET will render the form to a
xls file, and allows your client to open it in Excel and operate on it as
usual.

=====================
Possible Solution 2: Design the template in a normal xls file, and we
generate report by using ADO.NET OleDb provider.

Step1. We design the template in a normal xls file.
We can still include pictures in it. In order to dynamically or statically
fill a table with data, we put a named range in the workbook. The named
range will be exposed as a table from OleDb.

Step2. In our ASP.NET code, when a new request of report is received, we
first make a copy of the xls file in step1. Then we write code to insert
data into the tables (or named ranges) of the workbook. Here is an example:

Reading and Writing Excel using OLEDB
http://www.codeproject.com/KB/office...ing_oledb.aspx

Step3. Give the resulting location of the xls in step2 to the client.

For more readings,

New ways to automate corporate reporting
http://office.microsoft.com/en-us/ex...548031033.aspx

Export DataSets to Excel...
http://www.dotnetjohn.com/articles.aspx?articleid=36

Regards,
Jialiang Ge (jialge@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================

Reply With Quote
  #12  
Old 09-08-2008, 06:34 AM
Jialiang Ge [MSFT]
Guest
 
Default Re: Run Excel Template

Thanks for pointing it out, Mark. :-)

Regards,
Jialiang Ge (jialge@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================

Reply With Quote
  #13  
Old 09-08-2008, 09:21 AM
Peter
Guest
 
Default Re: Run Excel Template

Right!
Don't tell anyone
Security by obscurity - That's Microsoft's way.

"Mark Rae [MVP]" <mark@markNOSPAMrae.net> wrote in message
news:%239kf54YEJHA.4104@TK2MSFTNGP04.phx.gbl...
> ""Jialiang Ge [MSFT]"" <jialge@online.microsoft.com> wrote in message
> news:g2gV$cWEJHA.6100@TK2MSFTNGHUB02.phx.gbl...
>
>> However, as Mark Rae said, Office automation in server app like ASP.NET
>> is
>> NOT recommended. Microsoft does not support this scenario.

>
> Therefore, as an employee of Microsoft, you should *NOT* be even
> suggesting it...
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net



Reply With Quote
  #14  
Old 09-08-2008, 09:32 AM
Mark Rae [MVP]
Guest
 
Default Re: Run Excel Template

"Peter" <czupet@nospam.nospam> wrote in message
news:uYSpXXbEJHA.1460@TK2MSFTNGP03.phx.gbl...

[top-posting corrected]

> "Mark Rae [MVP]" <mark@markNOSPAMrae.net> wrote in message
> news:%239kf54YEJHA.4104@TK2MSFTNGP04.phx.gbl...
>> ""Jialiang Ge [MSFT]"" <jialge@online.microsoft.com> wrote in message
>> news:g2gV$cWEJHA.6100@TK2MSFTNGHUB02.phx.gbl...
>>
>>> However, as Mark Rae said, Office automation in server app like ASP.NET
>>> is
>>> NOT recommended. Microsoft does not support this scenario.

>>
>> Therefore, as an employee of Microsoft, you should *NOT* be even
>> suggesting it...

>
> Right!
> Don't tell anyone


Don't tell people to use a technology in a way for which it was not designed
at all, and which more often than not results in a web server crash leading
to loss of data...?

Yeah, I would say so...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Reply With Quote
  #15  
Old 09-08-2008, 10:00 AM
Peter
Guest
 
Default Re: Run Excel Template

Right, don't tell people what are the options and consiquences, they will
never to that if we don't tell them.

"Mark Rae [MVP]" <mark@markNOSPAMrae.net> wrote in message
news:uamkfdbEJHA.612@TK2MSFTNGP06.phx.gbl...
> "Peter" <czupet@nospam.nospam> wrote in message
> news:uYSpXXbEJHA.1460@TK2MSFTNGP03.phx.gbl...
>
> [top-posting corrected]
>
>> "Mark Rae [MVP]" <mark@markNOSPAMrae.net> wrote in message
>> news:%239kf54YEJHA.4104@TK2MSFTNGP04.phx.gbl...
>>> ""Jialiang Ge [MSFT]"" <jialge@online.microsoft.com> wrote in message
>>> news:g2gV$cWEJHA.6100@TK2MSFTNGHUB02.phx.gbl...
>>>
>>>> However, as Mark Rae said, Office automation in server app like ASP.NET
>>>> is
>>>> NOT recommended. Microsoft does not support this scenario.
>>>
>>> Therefore, as an employee of Microsoft, you should *NOT* be even
>>> suggesting it...

>>
>> Right!
>> Don't tell anyone

>
> Don't tell people to use a technology in a way for which it was not
> designed at all, and which more often than not results in a web server
> crash leading to loss of data...?
>
> Yeah, I would say so...
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net



Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 08:07 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.