10x for the reply i am checking it right now...
well in the report i need to calculate a percentage (actually i can do that from sql) and according to this average (lets say between 80-90 excellent ...70-80 very good and so on...) i think thats y i need to fill each cell individually...i dont know if its a good idea :S...and i asked a fellow in the office about it and he told me that this is how they do it here and they didnt do it in asp.net before..they did it in VB6 and
vb.net...(maybe u are correct there is no need to it like that..i may be try to touch my right ear with my left hand..)
plus the report should be shown at the end of a series of pages starting by the weekly work,then promoters report,promoter detailed report,promoter daily detailed report and a couple of other reports to get to that...
now if i want to use the method u told me about..do i need to rebuild all the datagrids and redo all the sql statements over again (which i should do eventually if i want to fill each cell individually...) all i got till now is this piece of code..
Dim oExcel As New Excel.Application
Dim oBooks As Excel.Workbooks, oBook As Excel.Workbook
Dim oSheets As Excel.Sheets, oSheet As Excel.Worksheet
Dim oCells As Excel.Range
Dim sFile As String, sTemplate As String
'Dim dt As DataTable = CType(Application.Item("MyDataTable"), DataTable)
sTemplate = Server.MapPath(Request.ApplicationPath) & "\AltadisBook.xls"
oBooks = oExcel.Workbooks
oBooks.Open(Server.MapPath(Request.ApplicationPath ) & "\AltadisBook.xls") 'Load colorful template with chart
oExcel.Visible = True
oBook = oBooks.Item(1)
oSheets = oBook.Worksheets
oSheet = CType(oSheets.Item(1), Excel.Worksheet)
oSheet.Name = "First Sheet"
oCells = oSheet.Cells
'DumpData(dt, oCells) 'Fill in the data
oSheet.SaveAs(sTemplate)
oBook.Close()
'Quit Excel and thoroughly deallocate everything
oExcel.Quit()
ReleaseComObject(oCells) : ReleaseComObject(oSheet)
ReleaseComObject(oSheets) : ReleaseComObject(oBook)
ReleaseComObject(oBooks) : ReleaseComObject(oExcel)
oExcel = Nothing : oBooks = Nothing : oBook = Nothing
oSheets = Nothing : oSheet = Nothing : oCells = Nothing
GC.Collect()
'Response.Redirect(sFile) 'Send the user to the file
Response.Redirect(sTemplate)
which generates an error on "oSheet.SaveAs(sTemplate)"-->Cannot access read-only document 'AltadisBook.xls'.
and this function used to fill a the cells in the excel
Dim dr As DataRow, ary() As Object
Dim iRow As Integer, iCol As Integer
'Output Column Headers
For iCol = 0 To dt.Columns.Count - 1
oCells(2, iCol + 1) = dt.Columns(iCol).ToString
Next
'Output Data
For iRow = 0 To dt.Rows.Count - 1
dr = dt.Rows.Item(iRow)
ary = dr.ItemArray
For iCol = 0 To UBound(ary)
oCells(iRow + 3, iCol + 1) = ary(iCol).ToString
Response.Write(ary(iCol).ToString & vbTab)
Next
Next
which i dont seem to be able to use since
'Dim dt As DataTable = CType(Application.Item("MyDataTable"), DataTable)
is nothing..
i am really lost...
10x in advance