473,401 Members | 2,125 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,401 software developers and data experts.

writting excel files

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, does anyone know any third party compononet
to write excel files without having it installed?

My code looks like:

Public Function toExcel(ByVal fileName As String, ByVal dv As DataView)
As Boolean
Try
Dim sourceFileName As String = Application.StartupPath + "\" +
CTools.getConfigValues("excelTemplate")
If IsNothing(xlApp) Then
xlApp = CreateObject("Excel.Application")
End If
xlApp.Visible = True
Dim xlWB As Excel.Workbook =
xlApp.Workbooks.Open(sourceFileName)
Dim xls As Excel.Worksheet = CType(xlWB.Sheets("Datos"),
Excel.Worksheet)
Dim i As Integer = 4
Dim indexDataView As Integer
dv.Sort = "fechaRequerimiento desc"
For indexDataView = 0 To dv.Count - 1
xls.Range("A" & i.ToString).Value =
dv(indexDataView)("ejecutor")
xls.Range("B" & i.ToString).Value =
dv(indexDataView)("tarea")
xls.Range("C" & i.ToString).Value =
dv(indexDataView)("solicitante")
i += 1
Next
xls.Range("A1").Value = "Detalle Tareas: " +
dv(0)("fechaRequerimiento").ToString + " --- " + dv(dv.Count -
1)("fechaRequerimiento").ToString
xlWB.SaveAs(fileName)
xlApp.Workbooks.Close()
xlApp.Quit()
xls = Nothing
xlWB = Nothing
xlApp = Nothing
GC.Collect()
Return True
Catch ex As Exception
Throw ex
End Try
End Function

Thanx ...
Nov 18 '05 #1
3 1961

Hi Boris,

When you reference the excel type library from your code, what happens is a
runtime wrapper is created to enable messaging with the managed .NET code and
the unmanaged excel COM. You have to be exteremely careful if you have to use
Excel as a serverside component, which is not supported nor advised by
Microsoft.

Coming back to your problem, you have to create each object and then
deallocate it. To deallocate, you have to use
Marshal.ReleaseComObject(object). For example when you refer to collections
with;

Dim xlWB As Excel.Workbook = xlApp.Workbooks.Open(sourceFileName)

what you are doing is you are creating an instance of Workbooks but not
setting it to anything. Now it dangles around and there's no way for the
garbage collector to collect it. So the Excel runtime will stay active on the
memory. So instead, create an instance of Workbooks, use then deallocate it.

In anycase, I don't recommend using Excel on server side, unless you have no
other change. I recommend using XSLT to create a transformation for HTML (For
excel versions prior to 2002) or for XML (for excel versions later than
2002). The only disadvantage with this would be, you cannot embed images or
macros.

For the 3rd apps, I will not even mention crystal because it's not meant for
creating excel reports. Now, reporting services is also on table but I don't
know how good it is. But, if your task is only putting a datagrid into an
excel sheet, there's one more option; use Infragistics. Infragistics has an
ExcelConverter component that does exactly this in a very good way. It comes
with Infragistics components, though there's no reference to it through their
web site. (I don't know why.)

Hope this helps,

Ethem Azun

"Boris Condarco" wrote:
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, does anyone know any third party compononet
to write excel files without having it installed?

My code looks like:

Public Function toExcel(ByVal fileName As String, ByVal dv As DataView)
As Boolean
Try
Dim sourceFileName As String = Application.StartupPath + "\" +
CTools.getConfigValues("excelTemplate")
If IsNothing(xlApp) Then
xlApp = CreateObject("Excel.Application")
End If
xlApp.Visible = True
Dim xlWB As Excel.Workbook =
xlApp.Workbooks.Open(sourceFileName)
Dim xls As Excel.Worksheet = CType(xlWB.Sheets("Datos"),
Excel.Worksheet)
Dim i As Integer = 4
Dim indexDataView As Integer
dv.Sort = "fechaRequerimiento desc"
For indexDataView = 0 To dv.Count - 1
xls.Range("A" & i.ToString).Value =
dv(indexDataView)("ejecutor")
xls.Range("B" & i.ToString).Value =
dv(indexDataView)("tarea")
xls.Range("C" & i.ToString).Value =
dv(indexDataView)("solicitante")
i += 1
Next
xls.Range("A1").Value = "Detalle Tareas: " +
dv(0)("fechaRequerimiento").ToString + " --- " + dv(dv.Count -
1)("fechaRequerimiento").ToString
xlWB.SaveAs(fileName)
xlApp.Workbooks.Close()
xlApp.Quit()
xls = Nothing
xlWB = Nothing
xlApp = Nothing
GC.Collect()
Return True
Catch ex As Exception
Throw ex
End Try
End Function

Thanx ...

Nov 18 '05 #2
Hi Ethem,

First of all, thanks a lot for helping me to understand what happens when
the dot net works with unmanaged code.

I spent some time searching a component in order to work with excel files
without having installed it. The following site offers a good one.

http://www.aspose.com/

Boris

"Ethem Azun" <Et*******@discussions.microsoft.com> wrote in message
news:FB**********************************@microsof t.com...

Hi Boris,

When you reference the excel type library from your code, what happens is a runtime wrapper is created to enable messaging with the managed .NET code and the unmanaged excel COM. You have to be exteremely careful if you have to use Excel as a serverside component, which is not supported nor advised by
Microsoft.

Coming back to your problem, you have to create each object and then
deallocate it. To deallocate, you have to use
Marshal.ReleaseComObject(object). For example when you refer to collections with;

Dim xlWB As Excel.Workbook = xlApp.Workbooks.Open(sourceFileName)

what you are doing is you are creating an instance of Workbooks but not
setting it to anything. Now it dangles around and there's no way for the
garbage collector to collect it. So the Excel runtime will stay active on the memory. So instead, create an instance of Workbooks, use then deallocate it.
In anycase, I don't recommend using Excel on server side, unless you have no other change. I recommend using XSLT to create a transformation for HTML (For excel versions prior to 2002) or for XML (for excel versions later than
2002). The only disadvantage with this would be, you cannot embed images or macros.

For the 3rd apps, I will not even mention crystal because it's not meant for creating excel reports. Now, reporting services is also on table but I don't know how good it is. But, if your task is only putting a datagrid into an
excel sheet, there's one more option; use Infragistics. Infragistics has an ExcelConverter component that does exactly this in a very good way. It comes with Infragistics components, though there's no reference to it through their web site. (I don't know why.)

Hope this helps,

Ethem Azun

"Boris Condarco" wrote:
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, does anyone know any third party compononet to write excel files without having it installed?

My code looks like:

Public Function toExcel(ByVal fileName As String, ByVal dv As DataView) As Boolean
Try
Dim sourceFileName As String = Application.StartupPath + "\" + CTools.getConfigValues("excelTemplate")
If IsNothing(xlApp) Then
xlApp = CreateObject("Excel.Application")
End If
xlApp.Visible = True
Dim xlWB As Excel.Workbook =
xlApp.Workbooks.Open(sourceFileName)
Dim xls As Excel.Worksheet = CType(xlWB.Sheets("Datos"),
Excel.Worksheet)
Dim i As Integer = 4
Dim indexDataView As Integer
dv.Sort = "fechaRequerimiento desc"
For indexDataView = 0 To dv.Count - 1
xls.Range("A" & i.ToString).Value =
dv(indexDataView)("ejecutor")
xls.Range("B" & i.ToString).Value =
dv(indexDataView)("tarea")
xls.Range("C" & i.ToString).Value =
dv(indexDataView)("solicitante")
i += 1
Next
xls.Range("A1").Value = "Detalle Tareas: " +
dv(0)("fechaRequerimiento").ToString + " --- " + dv(dv.Count -
1)("fechaRequerimiento").ToString
xlWB.SaveAs(fileName)
xlApp.Workbooks.Close()
xlApp.Quit()
xls = Nothing
xlWB = Nothing
xlApp = Nothing
GC.Collect()
Return True
Catch ex As Exception
Throw ex
End Try
End Function

Thanx ...

Nov 18 '05 #3
Don
"Boris Condarco" <bc*******@prueba.com> wrote in message news:<Ok**************@TK2MSFTNGP11.phx.gbl>...
Hi gurus,
Besides, does anyone know any third party compononet
to write excel files without having it installed?


Hi Boris,

Our product, Spread for Web Forms, is a server side spreadsheet
component that reads and writes Excel files, among many other things.
Excel need not be present.

You are welcome to get more info on it here and to download an
evaluation version to see if it meets your needs:
http://www.fpoint.com/netproducts/spreadweb/spread.aspx

Here's also a link to a review done on the product by asp.netPRO
magazine:
http://www.aspnetpro.com/Productrevi...200307mr_p.asp

- Donald
FarPoint Technologies
Nov 18 '05 #4

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

Similar topics

9
by: Rich | last post by:
Hi, I have a bunch of Excel reports that I would like to display on my company's intranet. The reports contain priviledged information, however. My plan was to have a page with a dropdown box...
0
by: Oci-One Kanubi | last post by:
Everything works fine in Access, but when I double-click on the resultant Excel files the first one opens correctly, but subsequent ones, and any other Excel files I try to open, fail to display at...
0
by: Jack | last post by:
Windows 2K Pro Access/Excel 2003 Hi there, I have a large number of password protected Excel Workbooks. The files are protected by code that runs when the workbook opens. The code asks the...
0
by: Emmanuel | last post by:
Hi everybody, I have already opened a thread with the same question but since I got no answers I will try to rephrase my question and be more specific. - I have already build a COM Add-In...
1
by: itsjyotika | last post by:
Hello Everyone, I need to read data from a CVS file(i created it from micosoft excel) and then need to match it with the one of the date from the command line.If the date is there then it should say...
18
by: gonzlobo | last post by:
No, I don't want to destroy them (funny how the word 'decimate' has changed definition over the years) :). We have a data acquisition program that saves its output to Excel's ..xls format....
9
by: Abhay | last post by:
How can i write a excel file through c program.?
0
by: Jon Delano | last post by:
Hello All I am working a on web application created in Visual Studio 2005 VB. It has to do some work with Excel files, so I created a DLL in VS2005. My development machine is XP SP3. When my...
5
by: wolfjmt | last post by:
Hi, I am trying to write to data to a .xlsx file. I can currently write the data to a .xls file. I tried to change the extension of the xls file (to xlsx) but Excel gave the following error:Excel...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.