473,406 Members | 2,345 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to generate excel files at asp.net server side

Hi,

We have Excel 2003 templates and we need to automatically generate excel
2003 xls files based on our SQL server database tables' data. Since we need
to generate the xls files at out asp.net server side, I assume we cannot use
excel automation based on the license agreement.

What would b the best way to do that?

Any help would be appreciated,
Max
Dec 6 '06 #1
3 5509
"Maxwell2006" <al******@newsgroup.nospamwrote in message
news:Oj**************@TK2MSFTNGP03.phx.gbl...
We have Excel 2003 templates and we need to automatically generate excel
2003 xls files based on our SQL server database tables' data. Since we
need to generate the xls files at out asp.net server side, I assume we
cannot use excel automation based on the license agreement.
You can use automation, but it's strongly discouraged, and Microsoft won't
support you if you do...
What would b the best way to do that?
If you just need plain text, export the data to CSV.

Otherwise, save it as XML in the Excel XML file format, or use a 3rd-party
utility like this: http://www.aspose.com/Products/Aspos...s/Default.aspx
Dec 6 '06 #2
I've always outputed it as an HTML table with an XLS file extension. Excel
is able to interpret it as a regular worksheet. However, if you want to
output a workbook (multiple tables across multiple sheets), you will need to
output to the Excel XML-based format and Strong.Format in the user ID,
company name, and workbook XML based on this template (it's escaped for
appearing in an XML-based .resx file) (and subsequently do a Response.Write
of the resulting string):

The response content header:
HttpResponse response = HttpContext.Current.Response;
response.ContentType = "application/vnd.ms-excel";
response.Charset = String.Empty;
response.AddHeader("Content-Disposition",
"attachment;filename=report.xlw");
The template:
<data name="ExcelWorkbook">
<value>&lt;?xml version="1.0"?&gt;
&lt;Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40"&gt;
&lt;DocumentProperties
xmlns="urn:schemas-microsoft-com:office:office"&gt;
&lt;Author&gt;{0}&lt;/Author&gt;
&lt;LastAuthor&gt;{1}&lt;/LastAuthor&gt;
&lt;Created&gt;{2}&lt;/Created&gt;
&lt;Company&gt;{3}&lt;/Company&gt;
&lt;Version&gt;10.3501&lt;/Version&gt;
&lt;/DocumentProperties&gt;
&lt;OfficeDocumentSettings
xmlns="urn:schemas-microsoft-com:office:office"&gt;
&lt;RelyOnVML/&gt;
&lt;AllowPNG/&gt;
&lt;DownloadComponents/&gt;
&lt;/OfficeDocumentSettings&gt;
&lt;ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel"&gt;
&lt;WindowHeight&gt;9720&lt;/WindowHeight&gt;
&lt;WindowWidth&gt;14235&lt;/WindowWidth&gt;
&lt;WindowTopX&gt;120&lt;/WindowTopX&gt;
&lt;WindowTopY&gt;135&lt;/WindowTopY&gt;
&lt;ActiveSheet&gt;0&lt;/ActiveSheet&gt;
&lt;ProtectStructure&gt;False&lt;/ProtectStructure&gt;
&lt;ProtectWindows&gt;False&lt;/ProtectWindows&gt;
&lt;/ExcelWorkbook&gt;
&lt;Styles&gt;
&lt;Style ss:ID="Default" ss:Name="Normal"&gt;
&lt;Alignment ss:Vertical="Bottom"/&gt;
&lt;Borders/&gt;
&lt;Font/&gt;
&lt;Interior/&gt;
&lt;NumberFormat/&gt;
&lt;Protection/&gt;
&lt;/Style&gt;
&lt;Style ss:ID="Header"&gt;
&lt;Font ss:Bold="1"/&gt;
&lt;/Style&gt;
&lt;Style ss:ID="ShortDateCell"&gt;
&lt;NumberFormat ss:Format="m/d/yyyy;@" /&gt;
&lt;/Style&gt;
&lt;/Styles&gt;
{4}
&lt;/Workbook&gt;
</value>
</data>
Dec 6 '06 #3
Hi Max,

You might want to take a look at following KB articles:

#How To Export Data in a DataGrid on an ASP . NET WebForm to Microsoft
Excel
http://support.microsoft.com/kb/317719

#How to transform a DataSet to spreadsheet XML for Excel by using Visual
Basic .NET and ASP.NET
http://support.microsoft.com/kb/319180/
However, as I understand from your post, you're using an existing Excel
template to create new excel file, this might not work with using normal
exporting approaches.

Also, as Mark pointed, automation excel at server-side is not supported by
Microsoft:

#Considerations for server-side Automation of Office
http://support.microsoft.com/kb/257757/
Microsoft does not currently recommend, and does not support, Automation of
Microsoft Office applications from any unattended, non-interactive client
application or component (including ASP, DCOM, and NT Services), because
Office may exhibit unstable behavior and/or deadlock when run in this
environment.
Therefore, I'm afraid you either have to use third party components to
generate the excel file or you could use following workaround if the data
needs to be generated isn't complicated:

You can save the template file as xml format, and load it as xml document,
then use XPath expression to find existing cell data or add new cell data.

Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

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://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

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

Dec 7 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: LBT | last post by:
Hi experts, With response.contenttype = "application/vnd.ms-excel", I can easily export my data to Excel which is embeded and shown within a browser. If I'm going to save the Excel file...
3
by: Boris Condarco | last post by:
Hi gurus, I'm using excel 2000 to show data that comes from datagrid. The problem is that for any reason the asp.net application maintains the excel open, even though, i do close it. Besides,...
4
by: BillyLiu007 | last post by:
Hi all: Its easy for us to use the wdsl.exe to generate a proxy or server side stub from the .wsdl file. but when .wdsl file its not just one file, it import another .wdsl file and schema file,...
9
by: jazzslider | last post by:
I have a headache. I've done a LOT of research lately into XForms, and I am thoroughly convinced that a good implementation of this technology would help me immensely in converting my...
0
by: icy111 | last post by:
Hi All, I need to generate excel files with password protected in ASP? Kindly help. Thanks in Advance. Regards icy111
1
by: Doogie | last post by:
Hi, I am sure this is a very "newbie" question, but I need to export data from a web page to Excel. However the control is built inside HTML and I can't figure out how to get ahold of it. When...
11
by: Andy Burchill | last post by:
Hi there, I am trying to find out what the best way of creating an excel spreadsheet is, this will need to be done dynamically by an aspx website on the server side. The main way would be to...
8
by: kamel3d | last post by:
Hello I would ask if there is any possibility to generate events in php I mean generate it on server side Exemple: If (cond1) and (cond2) { send email to user } cond1 and cond2 exists in...
1
by: helplakshmi | last post by:
Hi All, I wish you a Happy new year!!!.. My requirement is to upload an excel file using PHP and to update the data in MSSQL. For which i have designed a screen so that the user can browse 2...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.