473,763 Members | 6,638 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 1762

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

Similar topics

0
2378
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
6792
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
2482
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
842
by: perpolis | last post by:
how can i use Xp commands to write on a CD?without installing any write programs like Nero???
5
1781
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
7201
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
10271
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
9564
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
9387
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10002
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...
1
9938
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9823
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
8822
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...
1
7368
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
3528
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2794
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.