Run Excel Template

  • Thread starter Thread starter Peter
  • Start date Start date
P

Peter

VS2008 ans ASP.NET 3.5, Office 2003

What is the best way to run Excel Template from ASP.NET web page were the
Excel is only installed on the client without any ActiveX? If so can someone
point me to an example? Do not have Sharepoint.

This is for Intranet and security is not important.


Thank You


Peter
 
From a web page I want to open an Excel Template from a shared drive and
populated it with data in cluding pictures?

Is using Java Script the best way to accomplish this?
 
If use JavaScript I can't do Client Side automation?
Can't I open an Excel Template from a shared drive and passs the data from
JavaScript into Excel spreadsheet?

Mark Rae said:
[top-posting corrected]
From a web page I want to open an Excel Template from a shared drive and
populated it with data in cluding pictures?

Is using Java Script the best way to accomplish this?

Not so long as you're doing this from ASP.NET... That would involve
server-side Office automation which is neither recommended nor supported
by Microsoft because Office is not designed to be automated in this way:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2
http://support.microsoft.com/default.aspx/kb/288367

Presumably, if you want to open an Excel template and populate it with
data, it's because you want to create an Excel workbook. If so, then you
need this:
http://www.aspose.com/categories/file-format-components/aspose.cells-for-.net-and-java/default.aspx
 
I am trying to create a report from Excel Template.
Once the Excel spreadsheet is created it will be displayed in Excel and the
used will be able to do what ever they want with it.
But I guess that's not possible without ActiveX or 3rd party software or
lowering your security.


Mark Rae said:
[please don't top-post]
[top-posting corrected]

What precisely do you mean by "run Excel Template"...?

What are you trying to run and where are you trying to run it?

From a web page I want to open an Excel Template from a shared drive
and populated it with data in cluding pictures?

Is using Java Script the best way to accomplish this?

Not so long as you're doing this from ASP.NET... That would involve
server-side Office automation which is neither recommended nor supported
by Microsoft because Office is not designed to be automated in this way:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2
http://support.microsoft.com/default.aspx/kb/288367

Presumably, if you want to open an Excel template and populate it with
data, it's because you want to create an Excel workbook. If so, then you
need this:
http://www.aspose.com/categories/file-format-components/aspose.cells-for-.net-and-java/default.aspx

If use JavaScript I can't do Client Side automation?

Not natively in a browser...
Can't I open an Excel Template from a shared drive and pass the data from
JavaScript into Excel spreadsheet?

Not without using ActiveX and seriously ramping down your security
settings...

The sticking point here is the browser. All modern browsers are designed
specifically to prevent any sort of direct interaction with the client
hardware and software.

What are you *precisely* trying to do?

As I said, presumably you're trying to create an Excel workbook based on a
template. What happens to this newly created workbook?
 
Hello Peter,

A. If you expect that your clients can create an Excel workbook according
to the Excel template in their client machine by clicking on a button in
the web page, the following two solutions may help you:

Solution 1. have a link to the template file in your web page.
When you clients click on the link, a "File download" dialog appears. If
the client click on "Open", an excel workbook will be created according to
the template, and be opened in the web browser (if the client is using
Office 2003), or in Excel (if the client is using Office 2007). If the
client click on "Save", he/she can save the template to his local directory.

The weakness of this solution: there is an unavoidable "File download"
dialog.

Solution 2. Write Office automation code in the client script, to automate
the client Office app to create and open a workbook according to the Excel
template.

Sample vbscript:
Dim app
set app = CreateObject("Excel.Application")
app.Workbooks.Open("URL TO THE .xlt FILE IN THE SHARED FOLDER")
app.Visible = True

The weakness of this solution: though this solution avoids the "File
download" dialog, it requires a setting in the client's IE:
"Initialize and script ActiveX control not marked as safe"
Otherwise, the script fails for sake of security.

B. If you expect to populate the Excel Template to a web page, you would
need to use Office automation on the server side. For instance, in asp.net
code, we automate Excel in the server to create a workbook based on the
template, save it as html, and embed the html content to our web page.
However, as Mark Rae said, Office automation in server app like ASP.NET is
NOT recommended. Microsoft does not support this scenario.

Regards,
Jialiang Ge ([email protected], 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:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
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/excel_using_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/excel/HA010548031033.aspx

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

Regards,
Jialiang Ge ([email protected], 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:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
 
Thanks for pointing it out, Mark. :-)

Regards,
Jialiang Ge ([email protected], 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:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
 
Right, don't tell people what are the options and consiquences, they will
never to that if we don't tell them.

Mark Rae said:
[top-posting corrected]
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...
 
Back
Top