473,386 Members | 1,644 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,386 software developers and data experts.

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.WriteFile(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***********@hotmail.com.
pls see below code.
regards,
Hari.
Public Function PrintExcel(ByRef 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.ContentType = "application/vnd.ms-excel"
Response.AddHeader("content-disposition", "filename=" + strDir &
strFileName + ".xls")
Response.Write("<html
xmlns:x=""urn:schemas-microsoft-com:office:excel"">")
Response.Write("<head>")
Response.Write("<xml>")
Response.Write("<x:ExcelWorkbook>")
Response.Write("<x:ExcelWorksheets>")
Response.Write("<x:ExcelWorksheet>")
Response.Write("<x:Name>" & strFileName & "</x:Name>")
Response.Write("<x:WorksheetOptions>")
Response.Write("<x:Print>")
Response.Write("<x:ValidPrinterInfo/>")
Response.Write("</x:Print>")
Response.Write("</x:WorksheetOptions>")
Response.Write("</x:ExcelWorksheet>")
Response.Write("</x:ExcelWorksheets>")
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.PrintExcel(dr(strGroupHeaderGroupBy),
Response, intRow, intCol, strErrPath)
intRow = intRow + 1
oSecHeader.PrintExcel(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(strGroupHeaderGroupBy) & "</td></tr>"
Response.Write(strPrintMsg)
'myExcel.Cells(intRow, intCol) = "AE Code :" &
dr(strGroupHeaderGroupBy)
End If
If strReportId = 5 Then
'intRow = intRow + 2
intRow = intRow + 1
intCol = 1
strPrintMsg = "<tr><td>Dealer : </td><td> " &
dr(strGroupHeaderGroupBy) & "</td></tr>"
Response.Write(strPrintMsg)
'myExcel.Cells(intRow, intCol) = "Dealer :" &
dr(strGroupHeaderGroupBy)
End If
If strReportId = 16 Or strReportId = 17 Then
intRow = intRow + 1
intCol = 1
strPrintMsg = "<tr><td>Account Status :
</td><td> " & dr(strGroupHeaderGroupBy) & "</td></tr>"
Response.Write(strPrintMsg)
'myExcel.Cells(intRow, intCol) = "Account Status
:" & dr(strGroupHeaderGroupBy)
End If
strTempGpBy = dr(strGroupHeaderGroupBy)
End If
'print End of List statement after each section is over
If strTempGpBy <> dr(strGroupHeaderGroupBy) And
strReportId = 5 Then
intRow = intRow + 2
intCol = 1
strPrintMsg = "<tr><td>End 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>End of List : Dealer :
</td><td> " & strTempGpBy & "</td></tr>"
Response.Write(strPrintMsg)
'myExcel.Cells(intRow, intCol) = "Dealer :" &
dr(strGroupHeaderGroupBy)
End If
strTempGpBy = dr(strGroupHeaderGroupBy)
End If
If strTempGpBy <> dr(strGroupHeaderGroupBy) And
(strReportId = 6 Or strReportId = 7 Or strReportId = 8) Then
'intRow = intRow + 2
intRow = intRow + 1
intCol = 1
strPrintMsg = "<tr><td>End of List : AE Code :
</td><td> " & strTempGpBy & "</td></tr>"
Response.Write(strPrintMsg)
'myExcel.Cells(intRow, intCol) = "End of List : AE
Code : " & strTempGpBy
strTempGpBy = dr(strGroupHeaderGroupBy)
End If
If strTempGpBy <> dr(strGroupHeaderGroupBy) And
strReportId = 9 Then
'intRow = intRow + 2
intRow = intRow + 1
intCol = 1
If strTempGpBy <> "" Then
strPrintMsg = "<tr><td>End 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(strGroupHeaderGroupBy) & "</td></tr>"
Response.Write(strPrintMsg)
'myExcel.Cells(intRow, intCol) = "AE Code :"
& dr(strGroupHeaderGroupBy)
End If
End If
strTempGpBy = dr(strGroupHeaderGroupBy)
End If
If strTempGpBy <> dr(strGroupHeaderGroupBy) And
(strReportId = 16 Or strReportId = 17) Then
'intRow = intRow + 2
intRow = intRow + 1
intCol = 1
If strTempGpBy <> "" Then
strPrintMsg = "<tr><td>End 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>Account Status :
</td><td> " & dr(strGroupHeaderGroupBy) & "</td></tr>"
Response.Write(strPrintMsg)
'myExcel.Cells(intRow, intCol) = "Account
Status :" & dr(strGroupHeaderGroupBy)
End If
End If
strTempGpBy = dr(strGroupHeaderGroupBy)
End If

'frame the filter
If strGroupHeaderFilter = "" Then
strCondition = strGroupHeaderGroupBy & "='" &
dr(strGroupHeaderGroupBy) & "'"
Else
strCondition = strGroupHeaderFilter & "='" &
dr(strGroupHeaderFilter) & "'"
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(strGroupHeaderGroupBy) & "</td></tr>"
Response.Write(strPrintMsg)
'myExcel.Cells(intRow, intCol) = "AE Code :" &
dr(strGroupHeaderGroupBy)
intRow = intRow + 1
intCol = 1
End If
If strReportId = 5 Then
intRow = intRow + 2
intCol = 1
strPrintMsg = "<tr><td>Dealer :</td><td> " &
dr(strGroupHeaderGroupBy) & "</td></tr>"
Response.Write(strPrintMsg)
'myExcel.Cells(intRow, intCol) = "Dealer :" &
dr(strGroupHeaderGroupBy)
intRow = intRow + 1
intCol = 1
End If
If strReportId = 16 Or strReportId = 17 Then
intRow = intRow + 2
intCol = 1
strPrintMsg = "<tr><td>Account Status :
</td><td> " & dr(strGroupHeaderGroupBy) & "</td></tr>"
Response.Write(strPrintMsg)
'myExcel.Cells(intRow, intCol) = "Account Status
:" & dr(strGroupHeaderGroupBy)
intRow = intRow + 1
intCol = 1
End If
strTempGpBy = dr(strGroupHeaderGroupBy)
End If

'print section detail for each section
Dim strGp As String
strGp = arrGpBy(intSecid)
If strGroupHeaderFilter = "" Then

oSecDtl.PrintExcel(Integer.Parse(strReportId.ToStr ing()), intSecid, strGp,
strCondition, oSecHeader, oSecST, PairingSecId, dr(strGroupHeaderGroupBy),
intSPCountOnEachSB, "", Response, intRow, intCol, False, strErrPath)
Else

oSecDtl.PrintExcel(Integer.Parse(strReportId.ToStr ing()), intSecid, strGp,
strCondition, oSecHeader, oSecST, PairingSecId, dr(strGroupHeaderGroupBy),
intSPCountOnEachSB, dr(strGroupHeaderFilter), 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(strGroupHeaderGroupBy) And
intTmpCount >= dtClientDetails.Rows.Count And intSecid = SectionCount Then
If strReportId = 5 Then
intRow = intRow + 2
intCol = 1
strPrintMsg = "<tr><td>End 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>End 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>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.</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>End 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.GroupHeaderForExcelSummary(Response, intRow,
intCol, strErrPath)
intRow = intRow + 1
End If
Dim tmpCount As Integer
Dim strGp1 As String
For intTmpCount = 0 To intSummaryCount - 1
strGp1 = arrGpBy(ArSummarySB(intTmpCount))
tmpCount =
Integer.Parse(ArSummarySB(intTmpCount).ToString()) - 1
'print section header
oSecHeader.PrintExcel(Response, ArSummarySB(intTmpCount),
intRow, intCol, strErrPath)
'print section detail
oSecDtl.PrintExcel(Integer.Parse(strReportId.ToStr ing()),
ArSummarySB(intTmpCount), strGp1, "", oSecHeader, oSecST, PairingSecId, "",
intSPCountOnEachSB, "", Response, intRow, intCol, True, strErrPath)
intRow = intRow + 1 'after printing each section leave 2
blank rows
Next
strFileName = strFileName.Replace("DATE", strDate)
'Calculate.GenerateDate())

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

'strDir = "c:\Reports\DailyReports\20040812"

If Not Directory.Exists(strDir) Then
Directory.CreateDirectory(strDir)
End If

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

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

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

Jul 21 '05 #1
0 1728

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

Similar topics

0
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...
18
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...
13
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>...
0
by: perpolis | last post by:
how can i use Xp commands to write on a CD?without installing any write programs like Nero???
5
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...
0
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...
0
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...
3
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...
2
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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...

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.