473,748 Members | 11,145 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to write to XL from ASP.NEt without installing XL

hi all,
My requirement is to generate xl reports throu Asp.Net without installing
xl on web server computer.
i am using Response object and wrtifile method as below. i dont know
whether it is correct, but giving error says " file is accessed by other
process cannot access"
I have some logic inbetween and write the info using response.write in to
html format Ex: Response.Write( "<td>" & "client_no" & "</td>").
I am getting the error at :
Response.WriteF ile(strDir & "\" & strFileName & ".xls")
line. says " xls file is accessed by other process and cannot access"
pls help me how to do this. if possible pls mail the code to
vh***********@h otmail.com.
pls see below code.
regards,
Hari.
Public Function PrintExcel(ByRe f Response As HttpResponse)

Dim intSecid As Integer
Dim strCondition As String
Dim strTempGpBy As String
Dim intTmpCount As Integer
Dim IsHdrFirstTime As Boolean
Dim intCol As Integer
Dim intRow As Integer
Dim intRecCount As Integer
Dim strPrintMsg As String

intTmpCount = 0
IsHdrFirstTime = True
intRow = 1
intCol = 1

Response.Conten tType = "applicatio n/vnd.ms-excel"
Response.AddHea der("content-disposition", "filename=" + strDir &
strFileName + ".xls")
Response.Write( "<html
xmlns:x=""urn:s chemas-microsoft-com:office:exce l"">")
Response.Write( "<head>")
Response.Write( "<xml>")
Response.Write( "<x:ExcelWorkbo ok>")
Response.Write( "<x:ExcelWorksh eets>")
Response.Write( "<x:ExcelWorksh eet>")
Response.Write( "<x:Name>" & strFileName & "</x:Name>")
Response.Write( "<x:WorksheetOp tions>")
Response.Write( "<x:Print>" )
Response.Write( "<x:ValidPrinte rInfo/>")
Response.Write( "</x:Print>")
Response.Write( "</x:WorksheetOpti ons>")
Response.Write( "</x:ExcelWorkshee t>")
Response.Write( "</x:ExcelWorkshee ts>")
Response.Write( "</x:ExcelWorkbook >")
Response.Write( "</xml>")
Response.Write( "</head>")
Response.Write( "<body>")
Response.Write( "<table>")
Response.Write( "<tr></tr>")

Try
intRecCount = dtClientDetails .Rows.Count

For Each dr As DataRow In dtClientDetails .Rows 'group header loop

intTmpCount = intTmpCount + 1

'for each sub report
For intSecid = 1 To SectionCount

'print section header
If IsHdrFirstTime = True Then ' IsHdrFirstTime= true =>
only one section header should come on each page
oGrpHeader.Prin tExcel(dr(strGr oupHeaderGroupB y),
Response, intRow, intCol, strErrPath)
intRow = intRow + 1
oSecHeader.Prin tExcel(Response , intSecid, intRow,
intCol, strErrPath)
IsHdrFirstTime = False
End If
'frame the beginning text for each section
If strTempGpBy = "" Then
If strReportId = 9 Then
'intRow = intRow + 2
intRow = intRow + 1
intCol = 1
strPrintMsg = "<tr><td>AE Code : </td><td> " &
dr(strGroupHead erGroupBy) & "</td></tr>"
Response.Write( strPrintMsg)
'myExcel.Cells( intRow, intCol) = "AE Code :" &
dr(strGroupHead erGroupBy)
End If
If strReportId = 5 Then
'intRow = intRow + 2
intRow = intRow + 1
intCol = 1
strPrintMsg = "<tr><td>De aler : </td><td> " &
dr(strGroupHead erGroupBy) & "</td></tr>"
Response.Write( strPrintMsg)
'myExcel.Cells( intRow, intCol) = "Dealer :" &
dr(strGroupHead erGroupBy)
End If
If strReportId = 16 Or strReportId = 17 Then
intRow = intRow + 1
intCol = 1
strPrintMsg = "<tr><td>Accoun t Status :
</td><td> " & dr(strGroupHead erGroupBy) & "</td></tr>"
Response.Write( strPrintMsg)
'myExcel.Cells( intRow, intCol) = "Account Status
:" & dr(strGroupHead erGroupBy)
End If
strTempGpBy = dr(strGroupHead erGroupBy)
End If
'print End of List statement after each section is over
If strTempGpBy <> dr(strGroupHead erGroupBy) And
strReportId = 5 Then
intRow = intRow + 2
intCol = 1
strPrintMsg = "<tr><td>En d of List : Dealer :
</td><td> " & strTempGpBy & "</td></tr>"
Response.Write( strPrintMsg)
'myExcel.Cells( intRow, intCol) = "End of List :
Dealer : " & strTempGpBy
If intTmpCount <= intRecCount Then
'intRow = intRow + 2
intRow = intRow + 1
intCol = 1
strPrintMsg = "<tr><td>En d of List : Dealer :
</td><td> " & strTempGpBy & "</td></tr>"
Response.Write( strPrintMsg)
'myExcel.Cells( intRow, intCol) = "Dealer :" &
dr(strGroupHead erGroupBy)
End If
strTempGpBy = dr(strGroupHead erGroupBy)
End If
If strTempGpBy <> dr(strGroupHead erGroupBy) And
(strReportId = 6 Or strReportId = 7 Or strReportId = 8) Then
'intRow = intRow + 2
intRow = intRow + 1
intCol = 1
strPrintMsg = "<tr><td>En d of List : AE Code :
</td><td> " & strTempGpBy & "</td></tr>"
Response.Write( strPrintMsg)
'myExcel.Cells( intRow, intCol) = "End of List : AE
Code : " & strTempGpBy
strTempGpBy = dr(strGroupHead erGroupBy)
End If
If strTempGpBy <> dr(strGroupHead erGroupBy) And
strReportId = 9 Then
'intRow = intRow + 2
intRow = intRow + 1
intCol = 1
If strTempGpBy <> "" Then
strPrintMsg = "<tr><td>En d of List : AE Code :
</td><td> " & strTempGpBy & "</td></tr>"
Response.Write( strPrintMsg)
'myExcel.Cells( intRow, intCol) = "End of List :
AE Code : " & strTempGpBy
If intTmpCount <= intRecCount Then
intRow = intRow + 1
intCol = 1
strPrintMsg = "<tr><td>AE Code : </td><td> "
& dr(strGroupHead erGroupBy) & "</td></tr>"
Response.Write( strPrintMsg)
'myExcel.Cells( intRow, intCol) = "AE Code :"
& dr(strGroupHead erGroupBy)
End If
End If
strTempGpBy = dr(strGroupHead erGroupBy)
End If
If strTempGpBy <> dr(strGroupHead erGroupBy) And
(strReportId = 16 Or strReportId = 17) Then
'intRow = intRow + 2
intRow = intRow + 1
intCol = 1
If strTempGpBy <> "" Then
strPrintMsg = "<tr><td>En d of List : Account
Status : </td><td> " & strTempGpBy & "</td></tr>"
Response.Write( strPrintMsg)
'myExcel.Cells( intRow, intCol) = "End of List :
Account Status : " & strTempGpBy
If intTmpCount <= intRecCount Then
intRow = intRow + 1
intCol = 1
strPrintMsg = "<tr><td>Accoun t Status :
</td><td> " & dr(strGroupHead erGroupBy) & "</td></tr>"
Response.Write( strPrintMsg)
'myExcel.Cells( intRow, intCol) = "Account
Status :" & dr(strGroupHead erGroupBy)
End If
End If
strTempGpBy = dr(strGroupHead erGroupBy)
End If

'frame the filter
If strGroupHeaderF ilter = "" Then
strCondition = strGroupHeaderG roupBy & "='" &
dr(strGroupHead erGroupBy) & "'"
Else
strCondition = strGroupHeaderF ilter & "='" &
dr(strGroupHead erFilter) & "'"
End If

If strTempGpBy = "" Then
If strReportId = 9 Or strReportId = 6 Or strReportId
= 7 Then
intRow = intRow + 2
intCol = 1
strPrintMsg = "<tr><td>AE Code :</td><td> " &
dr(strGroupHead erGroupBy) & "</td></tr>"
Response.Write( strPrintMsg)
'myExcel.Cells( intRow, intCol) = "AE Code :" &
dr(strGroupHead erGroupBy)
intRow = intRow + 1
intCol = 1
End If
If strReportId = 5 Then
intRow = intRow + 2
intCol = 1
strPrintMsg = "<tr><td>De aler :</td><td> " &
dr(strGroupHead erGroupBy) & "</td></tr>"
Response.Write( strPrintMsg)
'myExcel.Cells( intRow, intCol) = "Dealer :" &
dr(strGroupHead erGroupBy)
intRow = intRow + 1
intCol = 1
End If
If strReportId = 16 Or strReportId = 17 Then
intRow = intRow + 2
intCol = 1
strPrintMsg = "<tr><td>Accoun t Status :
</td><td> " & dr(strGroupHead erGroupBy) & "</td></tr>"
Response.Write( strPrintMsg)
'myExcel.Cells( intRow, intCol) = "Account Status
:" & dr(strGroupHead erGroupBy)
intRow = intRow + 1
intCol = 1
End If
strTempGpBy = dr(strGroupHead erGroupBy)
End If

'print section detail for each section
Dim strGp As String
strGp = arrGpBy(intSeci d)
If strGroupHeaderF ilter = "" Then

oSecDtl.PrintEx cel(Integer.Par se(strReportId. ToString()), intSecid, strGp,
strCondition, oSecHeader, oSecST, PairingSecId, dr(strGroupHead erGroupBy),
intSPCountOnEac hSB, "", Response, intRow, intCol, False, strErrPath)
Else

oSecDtl.PrintEx cel(Integer.Par se(strReportId. ToString()), intSecid, strGp,
strCondition, oSecHeader, oSecST, PairingSecId, dr(strGroupHead erGroupBy),
intSPCountOnEac hSB, dr(strGroupHead erFilter), Response, intRow, intCol,
False, strErrPath)
End If

'print End of List statement if the printing has reached
the end of the report
If strTempGpBy = dr(strGroupHead erGroupBy) And
intTmpCount >= dtClientDetails .Rows.Count And intSecid = SectionCount Then
If strReportId = 5 Then
intRow = intRow + 2
intCol = 1
strPrintMsg = "<tr><td>En d of List : Dealer :
</td><td> " & strTempGpBy & "</td></tr>"
Response.Write( strPrintMsg)
'myExcel.Cells( intRow, intCol) = "End of List :
Dealer : " & strTempGpBy
End If
If strReportId = 6 Or strReportId = 7 Or strReportId
= 9 Or strReportId = 8 Then
intRow = intRow + 2
intCol = 1
strPrintMsg = "<tr><td>En d of List : AE code
:</td><td> " & strTempGpBy & "</td></tr>"
Response.Write( strPrintMsg)
'myExcel.Cells( intRow, intCol) = "End of List :
AE code : " & strTempGpBy
End If
If strReportId = 9 Then
intRow = intRow + 2
intCol = 1
strPrintMsg = "<tr><td>Pe r FTA 12A. We have to
immidietely notify the authority if any account is under margined by any
amount which exceeds 100% of our ANC.</td></tr>"
Response.Write( strPrintMsg)
'myExcel.Cells( intRow, intCol) = "Per FTA 12A.
We have to immidietely notify the authority if any account is under margined
by any amount which exceeds 100% of our ANC."
End If
If strReportId = 16 Or strReportId = 17 Then
intRow = intRow + 2
intCol = 1
strPrintMsg = "<tr><td>En d of List : Account
Status :</td><td> " & strTempGpBy & "</td></tr>"
Response.Write( strPrintMsg)
'myExcel.Cells( intRow, intCol) = "End of List :
Account Status :" & strTempGpBy
End If
End If
Next
Next
'print summary section body
intRow = intRow + 2
intCol = 1
If SectionCount < 1 Then
oGrpHeader.Grou pHeaderForExcel Summary(Respons e, intRow,
intCol, strErrPath)
intRow = intRow + 1
End If
Dim tmpCount As Integer
Dim strGp1 As String
For intTmpCount = 0 To intSummaryCount - 1
strGp1 = arrGpBy(ArSumma rySB(intTmpCoun t))
tmpCount =
Integer.Parse(A rSummarySB(intT mpCount).ToStri ng()) - 1
'print section header
oSecHeader.Prin tExcel(Response , ArSummarySB(int TmpCount),
intRow, intCol, strErrPath)
'print section detail
oSecDtl.PrintEx cel(Integer.Par se(strReportId. ToString()),
ArSummarySB(int TmpCount), strGp1, "", oSecHeader, oSecST, PairingSecId, "",
intSPCountOnEac hSB, "", Response, intRow, intCol, True, strErrPath)
intRow = intRow + 1 'after printing each section leave 2
blank rows
Next
strFileName = strFileName.Rep lace("DATE", strDate)
'Calculate.Gene rateDate())

Response.Write( "</table></body></html>")
strDir = strDir & strDate & "\"

'strDir = "c:\Reports\Dai lyReports\20040 812"

If Not Directory.Exist s(strDir) Then
Directory.Creat eDirectory(strD ir)
End If

If Not File.Exists(str Dir & "\" & strFileName & ".xls") Then
File.Create(str Dir & "\" & strFileName & ".xls")
End If

Response.WriteF ile(strDir & "\" & strFileName & ".xls")
Response.Flush( )
Response.End()

Catch ex As Exception
ErrorLog.Log(st rErrPath, ex.Message, ex.Source, ex.StackTrace)
End Try
End Function

Jul 21 '05 #1
0 1760

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

Similar topics

0
2376
by: Kevin McDaniel | last post by:
Has anyone ever heard of installing Oracle 9.2 on an Alpha OpenVMS box without using OUI? I know the Installation Guide says that ORACLEINS no longer exists, but I'm being told that it is STILL possible to install Oracle without using OUI. If ORACLEINS is not available, and you can't use an X-Windows based environment, how can you get around the java pieces? Even if you're not using OpenVMS and you know the answer, I'm still interested...
18
6791
by: reclusive monkey | last post by:
Firstly is this possible?! I've been playing around with XML for various things, and it would be very helpful if I could manage to write to an XML file with no server-side work. The reason for this is simple; I work for a local council (UK), and thus I don't have access to anything server-side. I've read around various sites and most of the articles I have looked at use ASP or PHP to do this. I *think* this is possible using some...
13
2479
by: gsb | last post by:
Object tag to write HTML page to via JavaScript? I've used iFrames and Objects to load web pages into another page. I want to do similar but not load a uri, rather write the page, <HTML> ....to...</HTML> via a JavaScript function. Is this possible with either of these two tags? Thanks, gsb
0
841
by: perpolis | last post by:
how can i use Xp commands to write on a CD?without installing any write programs like Nero???
5
1780
by: cyberstrike | last post by:
Hi guys, my company was wondering if it's possible to develop ASP.NET/Webservices easily using a IIS installed on a server instead of installing IIS locally on the development boxes. Can you develop for ASP.NET/Webservices without IIS installed on your local box without having to resort to more difficult debugging or using notepad for development? Thanks for the help!!
0
4848
by: Anonieko Ramos | last post by:
Self Installing Service Enter a topic name to show or a new topic name to create; then press Enter .. Start by writing a service. This involves deriving a class from System.ServiceProcess.ServiceBase and overriding a few methods. It's detailed in the documentation. Once you have your service written, you'll need to add an installer
0
304
by: hari krishna | last post by:
hi all, My requirement is to generate xl reports throu Asp.Net without installing xl on web server computer. i am using Response object and wrtifile method as below. i dont know whether it is correct, but giving error says " file is accessed by other process cannot access" I have some logic inbetween and write the info using response.write in to html format Ex: Response.Write("<td>" & "client_no" & "</td>"). I am getting the error at :...
3
7199
by: tkpmep | last post by:
I downloaded PyExcelerator.zip as I need to write some data into Excel files, and tried unsuccessfully to install it. I unzipped the files into C:/Python24/Lib/site-packages/PyExcelerator, and in a python command line window typed >>>os.chdir("C:/Python24/Lib/site-packages/PyExcelerator") followed by >>>python ./setup.py install
2
10266
by: Alex | last post by:
Hello, is there a chance to run a exe (written in vb.net) without installing the .net framework? i want start my exe and the .net framework from a cd (e.g. to show a customer a view functions of the program) Sincerely A. Huberti
0
8989
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9537
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9367
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9243
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8241
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4599
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3309
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.