E
Erik
Good Morning,
I have a request that timesheet records for employees be printed on a
separate sheet of paper, essentially doing a bulk 'hard-copy' print the
week's time. I have tried building a dataset for each employee's timesheets,
binding a datagrid to it and exporting to Excel, but
Response.Write("<script>window.print();history.back();</script>") does not
force the print and return scope back to the for each loop. Instead the
initial bound datagrid is rendered and scope is on the Excel spreadsheet.
Below is the current code. Any help or insight is greatly appreciated.
Thank you, Erik
For Each dr As DataRow In dstEmployeeNumbers.Tables(0).Rows
iRecCnt = GetTimeSheets(dr(0))
If iRecCnt > 0 Then
dgrdExport.DataSource = dstTimeSheets.Tables("TimeSheets")
dgrdExport.DataBind()
' Set the content type to Excel.
Response.ContentType = "application/vnd.ms-excel"
' Remove the charset from the Content-Type header.
Response.Charset = ""
' Turn off the view state.
Me.EnableViewState = False
Response.AddHeader("Content-Disposition",
"attachment;filename=TimeSheets" & _
Replace(calEndDt.SelectedDate.ToShortDateString, "/",
"") & ".xls")
dgrdExport.RenderControl(hw)
Response.Write(tw.ToString())
Response.Write("<script>window.print();history.back();</script>")
Response.End()
End If
dstTimeSheets.Clear()
Next
I have a request that timesheet records for employees be printed on a
separate sheet of paper, essentially doing a bulk 'hard-copy' print the
week's time. I have tried building a dataset for each employee's timesheets,
binding a datagrid to it and exporting to Excel, but
Response.Write("<script>window.print();history.back();</script>") does not
force the print and return scope back to the for each loop. Instead the
initial bound datagrid is rendered and scope is on the Excel spreadsheet.
Below is the current code. Any help or insight is greatly appreciated.
Thank you, Erik
For Each dr As DataRow In dstEmployeeNumbers.Tables(0).Rows
iRecCnt = GetTimeSheets(dr(0))
If iRecCnt > 0 Then
dgrdExport.DataSource = dstTimeSheets.Tables("TimeSheets")
dgrdExport.DataBind()
' Set the content type to Excel.
Response.ContentType = "application/vnd.ms-excel"
' Remove the charset from the Content-Type header.
Response.Charset = ""
' Turn off the view state.
Me.EnableViewState = False
Response.AddHeader("Content-Disposition",
"attachment;filename=TimeSheets" & _
Replace(calEndDt.SelectedDate.ToShortDateString, "/",
"") & ".xls")
dgrdExport.RenderControl(hw)
Response.Write(tw.ToString())
Response.Write("<script>window.print();history.back();</script>")
Response.End()
End If
dstTimeSheets.Clear()
Next