Solved

Need to display data in an excel spreadsheet in IE from an xls template.

Posted on 2008-10-16
6
586 Views
Last Modified: 2013-11-26
How can i create an excel spreadsheet in an asp.net vb aspx.vb page?

I tried the following code and i just get a blank page....

*********************CODE***************************************************************

Imports System.Reflection
Imports System.Runtime.InteropServices
Imports Excel = Microsoft.Office.Interop.Excel

Partial Class Report_Forecasting_Excel_1
    Inherits System.Web.UI.Page

    'Create Excel Objects
    Dim thisExcel As Excel.Application
    Dim thisWorkbook As Excel.Workbook
    Dim thisWorksheet As Excel.Worksheet

    Private Sub CreateSpreadsheet()
        thisExcel = New Excel.Application
        thisExcel.Workbooks.Add("D:\INTERNET\test.JazzCameras.com\Test\Excel_Templates\Forecasting_Template_1.xls")
        thisWorkbook = thisExcel.Workbooks(1)
        thisWorkbook.Activate()
        thisWorksheet = thisWorkbook.Worksheets(1)
        thisWorkbook.Application.Visible = True
        thisWorksheet.Cells(10, 10) = "hello there"
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        CreateSpreadsheet()
    End Sub
End Class
0
Comment
Question by:LennyCXIII
  • 2
  • 2
  • 2
6 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
You are creating the spreadsheet but not returning it to the client. Use a streat to return the created spreadsheet to the client using the response.write method.
0
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
having Office and use its automation on a web server is not really a good idea, not recommended. You should really use product like http://www.aspose.com/categories/file-format-components/aspose.cells-for-.net-and-java/default.aspx
0
 

Author Comment

by:LennyCXIII
Comment Utility
CodeCruiser:  Can you be more specific in how to create the "stream"...

my need was to create an excel document that users can save as a formated excel file
with styles and printing preferences already applied...
seting pagebreaks and printing header rows on each page etc....
i worked arround this by making a table and changing the content type to excel in the aspx.vb code and putting the excel xml documentation in the <head></head> aspx code

this worked real well..

But i would still like to know how to create the stream as you mentioned.

and emoreau Why is it such a bad idea?




 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 

<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">
 

<head id="Head1" runat="server">

<meta http-equiv="Content-Type" content="text/html; charset=us-ascii"/>

<meta name="ProgId" content="Excel.Sheet" />

<meta name="Generator" content="Microsoft Excel 11"/>
 

<title>Jazz Forecast By Product</title>

    <link href="JazzExcel_Styles.css" rel="stylesheet" type="text/css" />

    

 <xml>

 <o:DocumentProperties>

  <o:LastAuthor>Jazz Management Application</o:LastAuthor>

  <o:Version>2.0</o:Version>

 </o:DocumentProperties>

</xml>
 

<style>

<!--table

	{mso-displayed-decimal-separator:"\.";

	mso-displayed-thousand-separator:"\,";}

@page

	{mso-header-data:"&L&\0022Arial\,Bold\0022Jazz Confidential&C&D&RPage &P of &N";

	margin:0in .75in .5in .75in;

	mso-header-margin:.5in;

	mso-footer-margin:0in;

	mso-page-orientation:landscape;}

tr

	{mso-height-source:auto;}

br

	{mso-data-placement:same-cell;}

.style0

	{

	mso-protection:locked visible;

	mso-style-id:0;}

td

	{mso-style-parent:style0;

	padding-top:1px;

	padding-right:1px;

	padding-left:1px;

	mso-ignore:padding;

	mso-protection:locked visible;

	}

-->

</style>
 

<xml>

 <x:ExcelWorkbook>

  <x:ExcelWorksheets>

   <x:ExcelWorksheet>

    <x:Name>Test</x:Name>

    <x:WorksheetOptions>

     <x:Print>

      <x:ValidPrinterInfo/>

      <x:PaperSizeIndex>5</x:PaperSizeIndex>

      <x:HorizontalResolution>300</x:HorizontalResolution>

      <x:VerticalResolution>0</x:VerticalResolution>

     </x:Print>

     <x:PageBreakZoom>60</x:PageBreakZoom>

     <x:Selected/>

     <x:DoNotDisplayGridlines/>

     <x:ProtectContents>False</x:ProtectContents>

     <x:ProtectObjects>False</x:ProtectObjects>

     <x:ProtectScenarios>False</x:ProtectScenarios>

    </x:WorksheetOptions>

   </x:ExcelWorksheet>

  </x:ExcelWorksheets>

  <x:WindowHeight>13425</x:WindowHeight>

  <x:WindowWidth>24780</x:WindowWidth>

  <x:WindowTopX>240</x:WindowTopX>

  <x:WindowTopY>135</x:WindowTopY>

  <x:ProtectStructure>False</x:ProtectStructure>

  <x:ProtectWindows>False</x:ProtectWindows>

 </x:ExcelWorkbook>

 <x:ExcelName>

  <x:Name>Print_Titles</x:Name>

  <x:SheetIndex>1</x:SheetIndex>

  <x:Formula>='Test'!$1:$5</x:Formula>

 </x:ExcelName>

</xml>

    

</head>

Open in new window

0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 69

Accepted Solution

by:
Éric Moreau earned 250 total points
Comment Utility
>>and emoreau Why is it such a bad idea?

from http://support.microsoft.com/?kbid=257757:

Although such programmatic development can be implemented on a client system with relative ease, a number of complications can occur if Automation takes place from server-side code such as Microsoft Active Server Pages (ASP), ASP.NET, DCOM, or a Windows NT service.
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 250 total points
Comment Utility
0
 

Author Closing Comment

by:LennyCXIII
Comment Utility
both answers were right in thier own respect...
I found it easiest to set the excel params in the aspx file create the tables programatically in the aspx.vb and tell the browser its an excel file and let the user end figure the rest out and it works great I've had to impliment this at least 10 diff ways in the past two weeks... its quick and easy and alows me to set the printing properties like repeating table heading (top 2 cells) at each page. Thanks
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now