Solved

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

Posted on 2008-10-16
6
631 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 22738605
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 70

Expert Comment

by:Éric Moreau
ID: 22739695
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
ID: 22753052
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 70

Accepted Solution

by:
Éric Moreau earned 250 total points
ID: 22753167
>>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
ID: 22753881
0
 

Author Closing Comment

by:LennyCXIII
ID: 31516056
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

726 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