Kodi:
Imports Microsoft.Office
Imports Microsoft.Office.Interop
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim fd As FolderBrowserDialog = New FolderBrowserDialog()
'hap nje dialogBox per te zgjedhur nje folder
If fd.ShowDialog() = DialogResult.OK Then
Dim selectedFolder As String = fd.SelectedPath
TextBox1.Text = selectedFolder
TextBox1.Enabled = False
ListBox1.Items.Clear()
listo(selectedFolder, ListBox1)
End If
End Sub
Sub listo(ByVal folder, ByRef ListBox1)
Dim di As New IO.DirectoryInfo(folder)
Dim diar1 As IO.FileInfo() = di.GetFiles("*.*")
Dim dra As IO.FileInfo
'liston cdo file te tipit *txt ne ListBox
For Each dra In diar1
ListBox1.Items.Add(dra)
Next
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
delTemp()
'cdo file te shtypur ne Listbox, shfaq ne Textbox2
Dim selectedFile As String = TextBox1.Text + "\" + ListBox1.SelectedItem.ToString()
Dim fi As New IO.FileInfo(selectedFile)
Try
Select Case (fi.Extension.ToLower())
Case ".jpg", ".bmp", ".png", ".gif", ".ico"
shfaq_foto()
PictureBox1.Image = Image.FromFile(selectedFile)
Case ".txt", ".ini", ".log", ".bat", ".js", ".php", ".css"
shfaq_text()
TextBox2.Text = My.Computer.FileSystem.ReadAllText(selectedFile)
Case ".pdf", ".htm", ".html", ".xml"
WebBrowser1.Navigate(selectedFile)
shfaq_web()
Case ".docx", ".doc"
WebBrowser1.Navigate(shfaq_doc(selectedFile))
shfaq_web()
Case ".xlsx", ".xls"
WebBrowser1.Navigate(shfaq_xls(selectedFile))
shfaq_web()
Case ".mp3", ".avi", ".vob", ".wma", ".wav", ".mid"
shfaq_media()
AxWindowsMediaPlayer1.URL = selectedFile
Case Else
'MessageBox.Show("Ky lloj File nuk suportohet!")
End Select
Catch
End Try
End Sub
Private Sub delTemp()
If IO.Directory.Exists(Application.StartupPath & "\temp") Then
IO.Directory.Delete(Application.StartupPath & "\temp", True)
End If
IO.Directory.CreateDirectory(Application.StartupPath & "\temp")
End Sub
Private Sub shfaq_foto()
PictureBox1.Visible = True
TextBox2.Visible = False
WebBrowser1.Visible = False
AxWindowsMediaPlayer1.Visible = False
AxWindowsMediaPlayer1.close()
End Sub
Private Sub shfaq_text()
PictureBox1.Visible = False
TextBox2.Visible = True
WebBrowser1.Visible = False
AxWindowsMediaPlayer1.Visible = False
AxWindowsMediaPlayer1.close()
End Sub
Private Sub shfaq_web()
PictureBox1.Visible = False
TextBox2.Visible = False
WebBrowser1.Visible = True
AxWindowsMediaPlayer1.Visible = False
AxWindowsMediaPlayer1.close()
End Sub
Private Sub shfaq_media()
PictureBox1.Visible = False
TextBox2.Visible = False
WebBrowser1.Visible = False
AxWindowsMediaPlayer1.Visible = True
End Sub
Private Function shfaq_doc(ByVal selectedFile As String) As String
Label1.Text = "Duke punuar..."
Label1.BackColor = Color.Red
Dim creHtml As String = Application.StartupPath & "\temp\x.html"
Dim oWord As New Word.Application()
Dim oWordDoc As New Word.Document()
oWord.Visible = False
oWordDoc = oWord.Documents.Open(selectedFile)
oWordDoc.SaveAs(creHtml, Word.WdSaveFormat.wdFormatHTML)
oWordDoc.Close()
oWord.Quit()
shfaq_doc = creHtml
Label1.BackColor = Color.Transparent
Label1.Text = ""
End Function
Private Function shfaq_xls(ByVal selectedFile As String) As String
Label1.Text = "Duke punuar..."
Label1.BackColor = Color.Red
Dim creHtml As String = Application.StartupPath & "\temp\x.html"
Dim path As String = selectedFile
Dim objexcel As New Excel.Application
Dim o_nullobject As Object = System.Reflection.Missing.Value
Dim o_filePath As Object = path
Dim doc As Excel.Workbook = objexcel.Workbooks.Open(o_filePath, o_nullobject, _
o_nullobject, o_nullobject, o_nullobject, o_nullobject, o_nullobject, _
o_nullobject, o_nullobject, o_nullobject, o_nullobject, o_nullobject, o_nullobject, o_nullobject, o_nullobject)
Dim o_newfilename As Object = creHtml
Dim o_format As Object = Excel.XlFileFormat.xlHtml
Dim o_encoding As Object = Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8
objexcel.ActiveWorkbook.SaveAs(o_newfilename, o_format, o_nullobject, o_nullobject, o_nullobject, o_nullobject, _
Excel.XlSaveAsAccessMode.xlNoChange, o_nullobject, o_nullobject, o_nullobject, o_nullobject, o_nullobject)
doc.Close(o_nullobject, o_nullobject, o_nullobject)
objexcel.Quit()
shfaq_xls = creHtml
Label1.BackColor = Color.Transparent
Label1.Text = ""
End Function
End Class
Pasi qe ne projekt jane futur Componente te Word, Excel, Windows Media Player.. projekti tejkalon madhesine e lejuar e nuk mund ta bashkangjis.
Krijoni Kontakt