ASP Export into Excel with Multiple Worksheets

Please accept my apologies in advance for this additional posting and also for any help you can offer.  I've searched around, found several examples of solutions, but I can't get any of them to work completely.

To be clear, I'm trying to export data through an ASP page, ideally .NET, to render in Excel 2000.  My current station is a Windows 2000 station.  I have an ASP Classic version that works, but it won't allow me to create multiple sheets.

This article will be a good starting point as far as the research I've done: http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_20919538.html

I tried the version with <x:ExcelWorksheet> in combination with the table tags provided by Fritz the Blank, and it sets up/names multiple sheets for me, but the data appears on a single sheet only.  (I've at least been able to duplicate Fritz's initial state and prove I'm able to at least create  multiple sheets.)

I followed the complete XML example provided by sybe, but it wouldn't create multiple sheets, and the data all showed up on one sheet, all data in one cell per row.

If the sybe example is supposed to work as Fritz indicates, and I have every confidence it does, then the issue is somewhere else.  Station configuration, maybe?  Can anyone offer a suggestion as to how I should proceed?

Thank you again for taking the time to read this and also for any assistance you can provide.

jeristotleAsked:
Who is Participating?
 
geteConnect With a Mentor Commented:
I thought this would only need a few tweak here and there but boy I was wrong :) But, before the answer:
I tried sybe's XML example as is, it worked fine. Btw I'm using Excel 2007 but it's supposed to work in earlier version.

As for the hybrid HTML/XML (fritz's initial idea), the following are my references:

Can I Get That As a Spreadsheet?
http://www.15seconds.com/issue/031007.htm

Microsoft Office HTML and XML Reference
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnoffxml/html/ofxml2k.asp
(download the .exe file and just extract the .chm if you have WinZip or other compression tool)

From the 15seconds article, you can have a good tutorial about the setup. And from Microsoft documentation, it's confirmed that in order to have multiple worksheets, you need to separate the data/table in different files. The good thing is, Excel support MIME HTML (.mht/.mhtml) file (at least in Office 2007, haven't tried it in earlier ver). With MHTML, you only need to produce 1 output file.

Here's my initial setup:

*** books.xls ***
<html xmlns:x="urn:schemas-microsoft-com:office:excel">
<head>
<meta name="Excel Workbook Frameset">
<xml>
      <x:ExcelWorkbook>
            <x:ExcelWorksheets>
                  <x:ExcelWorksheet>
                        <x:Name>First Sheet</x:Name>
                        <x:WorksheetSource HRef="sheet1.htm"/>
                  </x:ExcelWorksheet>
                  <x:ExcelWorksheet>
                        <x:Name>Second Sheet</x:Name>
                        <x:WorksheetSource HRef="sheet2.htm"/>
                  </x:ExcelWorksheet>
            </x:ExcelWorksheets>
      </x:ExcelWorkbook>
</xml>
</head>
</html>

*** sheet1.htm ***
<table>
      <tr>
            <td>1asdf</td>
            <td>2</td>
            <td>3</td>
      </tr>
      <tr>
            <td>4</td>
            <td>5</td>
            <td>6</td>
      </tr>
</table>

*** sheet2.htm ***
<table>
      <tr>
            <td>a</td>
            <td>b</td>
            <td>c</td>
      </tr>
      <tr>
            <td>d</td>
            <td>e</td>
            <td>f</td>
      </tr>
</table>

Regardless of what 15seconds article stated, I find the above setup works fine without needing to create filelist.xml. So, basically the steps are:
1) Create the worksheets container/frameset with references to individual worksheet files. This is books.xls (which is just an HTML/XML file)
2) Create individual worksheet file as a normal HTML file. These are sheet1.htm and sheet2.htm. Note: the above examples is a simple <table>. You can use <body bgcolor=...> etc. as per normal HTML.

Now, the next step is to make a multipart MIME HTML from those 3 files:

*** booksmultipart.xls ***
MIME-Version: 1.0
X-Document-Type: Workbook
Content-Type: multipart/related; boundary=3D"----=_NextPart_ExcelWorkbook"

------=_NextPart_ExcelWorkbook
Content-Location: books.xls
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=3D"us-ascii"

<html xmlns:x=3D"urn:schemas-microsoft-com:office:excel">
<head>
<meta name=3D"Excel Workbook Frameset">
<xml>
      <x:ExcelWorkbook>
            <x:ExcelWorksheets>
                  <x:ExcelWorksheet>
                        <x:Name>First Sheet</x:Name>
                        <x:WorksheetSource HRef=3D"sheet1.htm"/>
                  </x:ExcelWorksheet>
                  <x:ExcelWorksheet>
                        <x:Name>Second Sheet</x:Name>
                        <x:WorksheetSource HRef=3D"sheet2.htm"/>
                  </x:ExcelWorksheet>
            </x:ExcelWorksheets>
      </x:ExcelWorkbook>
</xml>
</head>
</html>

------=_NextPart_ExcelWorkbook
Content-Location: sheet1.htm
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=3D"us-ascii"

<table>
      <tr>
            <td>1</td>
            <td>2</td>
            <td>3</td>
      </tr>
      <tr>
            <td>4</td>
            <td>5</td>
            <td>6</td>
      </tr>
</table>

------=_NextPart_ExcelWorkbook
Content-Location: sheet2.htm
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=3D"us-ascii"

<table>
      <tr>
            <td>a</td>
            <td>b</td>
            <td>c</td>
      </tr>
      <tr>
            <td>d</td>
            <td>e</td>
            <td>f</td>
      </tr>
</table>
------=_NextPart_ExcelWorkbook--

Basically booksmultipart.xls is just a text file combining the 3 files. Just take note you need to make the contents quoted-printable, e.g. you can do Replace(contents, "=", "=3D") for that.
0
 
jeristotleAuthor Commented:
I apologize for leaving this open.  I tried the sample, seemed to work OK for what I needed.  Thank you for your help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.