Click here to Skip to main content
15,924,482 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionClipboard usage Pin
zebos1-Jan-06 23:43
zebos1-Jan-06 23:43 
AnswerRe: Clipboard usage Pin
Dave Kreskowiak2-Jan-06 11:04
mveDave Kreskowiak2-Jan-06 11:04 
Questioncalling form's submit event ffrom AXWebBrowser Pin
Sufyan_shani1-Jan-06 22:38
Sufyan_shani1-Jan-06 22:38 
AnswerRe: calling form's submit event ffrom AXWebBrowser Pin
oldlight3-Jan-06 16:41
oldlight3-Jan-06 16:41 
QuestionCrystal Report For VS 2005 Setup File Pin
ayuba asia1-Jan-06 21:31
ayuba asia1-Jan-06 21:31 
AnswerRe: Crystal Report For VS 2005 Setup File Pin
karim ben romdhane2-Jan-06 20:55
karim ben romdhane2-Jan-06 20:55 
GeneralRe: Crystal Report For VS 2005 Setup File Pin
ayuba asia4-Jan-06 2:10
ayuba asia4-Jan-06 2:10 
Questionregarding excel sheet Pin
nagalakshmibasireddy1-Jan-06 21:17
nagalakshmibasireddy1-Jan-06 21:17 
hello,
The code shown below is for excel sheet generation but when i execute this i am getting an error as access is denied .plz go though the code and if any mistake plz correct it ....
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
da1.MissingSchemaAction = MissingSchemaAction.AddWithKey

CMD.Connection = con
con.Open()
CMD.CommandType = CommandType.StoredProcedure
CMD.CommandText = "ACE_CONTROLTOWER"
Dim cellid As New SqlParameter
Dim fromDATE As New SqlParameter
'Dim tomonth As New SqlParameter
'Dim fromyear As New SqlParameter
Dim toDATE As New SqlParameter

cellid.ParameterName = "@CELLID"
cellid.SqlDbType = SqlDbType.VarChar
cellid.Value = TextBox1.Text
cellid.Direction = ParameterDirection.Input


CMD.Parameters.Add(cellid)
fromDATE.ParameterName = "@fromDATE"
fromDATE.SqlDbType = SqlDbType.DateTime
fromDATE.Value = TextBox2.Text
fromDATE.Direction = ParameterDirection.Input
CMD.Parameters.Add(fromDATE)

toDATE.ParameterName = "@toDATE"
toDATE.SqlDbType = SqlDbType.DateTime
toDATE.Value = TextBox5.Text
toDATE.Direction = ParameterDirection.Input
CMD.Parameters.Add(toDATE)
Dim dr As SqlDataReader
dr = CMD.ExecuteReader()
DataGrid2.DataSource = dr
DataGrid2.DataBind()
dr.Close() 'closing data reader
CMD.Dispose()
con.Close()
End Sub



Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click


bln = CreateExcelWorkbook("example")
'= Server.MapPath(".") + "\PWReports\"

filePath = "c:\"
filename = "example"

filePath = filePath & filename & ".xls"
Dim MyFileStream As FileStream = New FileStream(filePath, FileMode.Open)
Dim FileSize As Long
FileSize = MyFileStream.Length
Dim Buffer(FileSize) As Byte
MyFileStream.Read(Buffer, 0, MyFileStream.Length)
MyFileStream.Close()
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("content-disposition", "attachment; filename=" & filename & " .xls")
Response.BinaryWrite(Buffer)

End Sub
Public Function CreateExcelWorkbook(ByVal strFileName As String) As Boolean

Dim oXL As Excel.Application
Dim oWB As Excel._Workbook
Dim oSheet, oSheet1, oSheet2 As Excel._Worksheet
Dim oRng As Excel.Range
filePath = "c:\"
filename = "example"
'Dim strCurrentDir As String
'strCurrentDir = Server.MapPath(".") + "\PWReports\"
Try
GC.Collect() '// clean up any other excel guys hangin' around...
oXL = New Excel.Application
oXL.Visible = False
'//Get a new workbook.
oWB = CType(oXL.Workbooks.Add("WorkBook"), Excel._Workbook)

oSheet = CType(oWB.Sheets("sheet1"), Excel._Worksheet)
oSheet.Name = "controltower"
oSheet.Range("A1", "O1").Font.Name = "Arial"
oSheet.Range("A1", "O1").Font.Size = 13.5
oSheet.Range("A1", "O1").Font.Color = RGB(255, 0, 0)

oSheet.Range(oSheet.Cells(1, 1), oSheet.Cells(1, 2)).Merge()
oSheet.Range(oSheet.Cells(1, 1), oSheet.Cells(1, 2)).Interior.Color = RGB(255, 255, 153)
oSheet.Range(oSheet.Cells(1, 1), oSheet.Cells(1, 2)).Value = "Infotech LCS Report : "
oSheet.Range(oSheet.Cells(1, 1), oSheet.Cells(1, 2)).Borders.ColorIndex = RGB(0, 0, 0)
oSheet.Range(oSheet.Cells(1, 1), oSheet.Cells(1, 2)).Font.Color = RGB(0, 0, 255)
oSheet.Range(oSheet.Cells(1, 1), oSheet.Cells(1, 2)).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter
oSheet.Range("A1", "O1").Font.Bold = True
oSheet.Range("A1", "O1").VerticalAlignment = Excel.XlVAlign.xlVAlignCenter


oXL.WindowState = Excel.XlWindowState.xlMinimized
oXL.Visible = True
oXL.UserControl = True

oSheet.Activate()
oXL.ActiveWindow.Zoom = 73
oSheet.Range("A4", "O4").Select()
oXL.ActiveWindow.FreezePanes = True




strfile = filename & ".xls"
Call RemoveFiles(filepath, strfile)
oWB.SaveAs(filePath + strfile, Excel.XlFileFormat.xlWorkbookNormal, Nothing, Nothing, False, False, Excel.XlSaveAsAccessMode.xlNoChange, False, True, Nothing, Nothing)
'// Need all following code to clean up and extingush all references!!!
oWB.Close(Nothing, Nothing, Nothing)
oXL.Workbooks.Close()
oXL.Quit()

Call KillProcess("EXCEL")
'System.Runtime.InteropServices.Marshal.ReleaseComObject(oRng)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oXL)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oSheet)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oSheet1)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oSheet2)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oWB)

oSheet = Nothing
oSheet1 = Nothing
oSheet2 = Nothing

oWB = Nothing
oXL = Nothing
GC.Collect() '// force final cleanup!

'Dim strMachineName As String = Request.ServerVariables("SERVER_NAME")
'errLabel.Text = "Download Report"
Return True
Catch theException As Exception
Response.Write(Err.Description)
Response.End()

Dim errorMessage As String
errorMessage = "Error: "
errorMessage = String.Concat(errorMessage, theException.Message)
errorMessage = String.Concat(errorMessage, " Line: ")
errorMessage = String.Concat(errorMessage, theException.Source)

Call KillProcess("EXCEL")
'System.Runtime.InteropServices.Marshal.ReleaseComObject(oRng)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oXL)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oSheet)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oSheet1)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oSheet2)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oWB)

oSheet = Nothing
oWB = Nothing
oXL = Nothing
GC.Collect() '// force final cleanup!
Return False
End Try
End Function
'Removing Excel Files
Private Sub RemoveFiles(ByVal strPath As String, ByVal fileName As String)
Dim di As System.IO.DirectoryInfo = New DirectoryInfo(strPath)
Dim fiArr() As FileInfo = di.GetFiles()
Dim fri As FileInfo
For Each fri In fiArr
If (fri.Name.ToString() = fileName) Then
fri.Delete()
End If
Next
End Sub
'Killing The Process
Private Sub KillProcess(ByVal strPrc As String)
Dim myproc As System.Diagnostics.Process = New System.Diagnostics.Process
Dim i As Integer
''Get all instances of proc that are open, attempt to close them.
Try
' i = Process.GetProcessesByName(strPrc).Length
For Each myproc In Process.GetProcessesByName(strPrc)
If Not (myproc.CloseMainWindow()) Then
''If closing is not successful or no desktop window handle, then force termination.
myproc.Kill()
Exit For
End If
Next myproc
Catch
Response.Write(Err.Description)
End Try
End Sub
End Class

thanks & regards
nagalakshmi
AnswerRe: regarding excel sheet Pin
Sufyan_shani1-Jan-06 23:13
Sufyan_shani1-Jan-06 23:13 
QuestionUser Controls can be added in datagridTextBoxColumn Pin
HemaRawat1-Jan-06 20:27
HemaRawat1-Jan-06 20:27 
Questionembed listview in Combobox (Urgent) Pin
HemaRawat1-Jan-06 19:55
HemaRawat1-Jan-06 19:55 
AnswerRe: embed listview in Combobox (Urgent) Pin
Sufyan_shani1-Jan-06 23:19
Sufyan_shani1-Jan-06 23:19 
GeneralRe: embed listview in Combobox (Urgent) Pin
HemaRawat1-Jan-06 23:28
HemaRawat1-Jan-06 23:28 
GeneralRe: embed listview in Combobox (Urgent) Pin
Sufyan_shani1-Jan-06 23:45
Sufyan_shani1-Jan-06 23:45 
GeneralRe: embed listview in Combobox (Urgent) Pin
HemaRawat1-Jan-06 23:49
HemaRawat1-Jan-06 23:49 
GeneralRe: embed listview in Combobox (Urgent) Pin
Sufyan_shani2-Jan-06 2:52
Sufyan_shani2-Jan-06 2:52 
Questionstream reader /writer or file access thru the api call Pin
nickhere1-Jan-06 12:54
nickhere1-Jan-06 12:54 
AnswerRe: stream reader /writer or file access thru the api call Pin
Dave Kreskowiak1-Jan-06 12:56
mveDave Kreskowiak1-Jan-06 12:56 
QuestionCopying Locked File Pin
Sameers Javed1-Jan-06 11:42
Sameers Javed1-Jan-06 11:42 
AnswerRe: Copying Locked File Pin
Dave Kreskowiak1-Jan-06 12:43
mveDave Kreskowiak1-Jan-06 12:43 
GeneralRe: Copying Locked File Pin
Sameers Javed2-Jan-06 0:01
Sameers Javed2-Jan-06 0:01 
GeneralRe: Copying Locked File Pin
Dave Kreskowiak2-Jan-06 7:05
mveDave Kreskowiak2-Jan-06 7:05 
GeneralRe: Copying Locked File Pin
Colin Angus Mackay2-Jan-06 22:34
Colin Angus Mackay2-Jan-06 22:34 
QuestionAdding C# class to VB.NET project Pin
militiaware1-Jan-06 11:27
militiaware1-Jan-06 11:27 
AnswerRe: Adding C# class to VB.NET project Pin
Dave Kreskowiak1-Jan-06 12:34
mveDave Kreskowiak1-Jan-06 12:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.