DocumentViewer: Support Streams
This commit is contained in:
parent
594d71bc75
commit
10e2579df4
@ -7,6 +7,7 @@ Imports DevExpress.Spreadsheet
|
|||||||
Imports GdPicture14
|
Imports GdPicture14
|
||||||
Imports DevExpress
|
Imports DevExpress
|
||||||
Imports DevExpress.Office.Utils
|
Imports DevExpress.Office.Utils
|
||||||
|
Imports System.IO
|
||||||
|
|
||||||
Public Class DocumentViewer
|
Public Class DocumentViewer
|
||||||
Private Enum ZoomMode
|
Private Enum ZoomMode
|
||||||
@ -83,9 +84,6 @@ Public Class DocumentViewer
|
|||||||
Exit Sub
|
Exit Sub
|
||||||
End If
|
End If
|
||||||
|
|
||||||
GdViewer.ZoomMode = ViewerZoomMode.ZoomModeWidthViewer
|
|
||||||
GdViewer.DocumentAlignment = ViewerDocumentAlignment.DocumentAlignmentTopCenter
|
|
||||||
|
|
||||||
_logger.Info("Loading File {0}", FilePath)
|
_logger.Info("Loading File {0}", FilePath)
|
||||||
|
|
||||||
DoLoadFile(FilePath)
|
DoLoadFile(FilePath)
|
||||||
@ -93,6 +91,21 @@ Public Class DocumentViewer
|
|||||||
UpdateMainUi()
|
UpdateMainUi()
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
|
Public Sub LoadFile(FileName As String, Stream As Stream)
|
||||||
|
If _licenseKey = String.Empty Then
|
||||||
|
_logger.Warn("License key was not provided. File [{0}] not loaded.", FileName)
|
||||||
|
Exit Sub
|
||||||
|
End If
|
||||||
|
|
||||||
|
Dim oExtension As String = FileName.Substring(FileName.LastIndexOf("."))
|
||||||
|
|
||||||
|
_logger.Info("Loading File [{0}]", FileName)
|
||||||
|
|
||||||
|
DoLoadFile(Stream, oExtension)
|
||||||
|
|
||||||
|
UpdateMainUi()
|
||||||
|
End Sub
|
||||||
|
|
||||||
Public Sub CloseDocument()
|
Public Sub CloseDocument()
|
||||||
GdViewer.CloseDocument()
|
GdViewer.CloseDocument()
|
||||||
UpdateMainUi()
|
UpdateMainUi()
|
||||||
@ -139,32 +152,13 @@ Public Class DocumentViewer
|
|||||||
RichEditControl1.Dock = DockStyle.Fill
|
RichEditControl1.Dock = DockStyle.Fill
|
||||||
|
|
||||||
Case ".EML", ".DOC", ".DOCX", ".ODT", ".RTF", ".TXT"
|
Case ".EML", ".DOC", ".DOCX", ".ODT", ".RTF", ".TXT"
|
||||||
Dim oFormat As XtraRichEdit.DocumentFormat = XtraRichEdit.DocumentFormat.Undefined
|
RichEditControl1.LoadDocument(FilePath, GetDocumentFormat(oExtension))
|
||||||
|
|
||||||
Select Case oExtension.ToUpper
|
|
||||||
Case ".EML" : oFormat = XtraRichEdit.DocumentFormat.Mht
|
|
||||||
Case ".DOC" : oFormat = XtraRichEdit.DocumentFormat.Doc
|
|
||||||
Case ".DOCX" : oFormat = XtraRichEdit.DocumentFormat.OpenXml
|
|
||||||
Case ".ODT" : oFormat = XtraRichEdit.DocumentFormat.OpenDocument
|
|
||||||
Case ".RTF" : oFormat = XtraRichEdit.DocumentFormat.Rtf
|
|
||||||
Case ".TXT" : oFormat = XtraRichEdit.DocumentFormat.PlainText
|
|
||||||
End Select
|
|
||||||
|
|
||||||
RichEditControl1.LoadDocument(FilePath, oFormat)
|
|
||||||
|
|
||||||
RichEditControl1.Visible = True
|
RichEditControl1.Visible = True
|
||||||
RichEditControl1.Dock = DockStyle.Fill
|
RichEditControl1.Dock = DockStyle.Fill
|
||||||
|
|
||||||
Case ".XLSX", ".XLS", "CSV"
|
Case ".XLSX", ".XLS", "CSV"
|
||||||
Dim oFormat As Spreadsheet.DocumentFormat = Spreadsheet.DocumentFormat.Undefined
|
SpreadsheetControl1.LoadDocument(FilePath, GetSpreadsheetFormat(oExtension))
|
||||||
|
|
||||||
Select Case oExtension.ToUpper
|
|
||||||
Case "XLSX" : oFormat = Spreadsheet.DocumentFormat.Xlsx
|
|
||||||
Case "XLS" : oFormat = Spreadsheet.DocumentFormat.Xls
|
|
||||||
Case "CSV" : oFormat = Spreadsheet.DocumentFormat.Csv
|
|
||||||
End Select
|
|
||||||
|
|
||||||
SpreadsheetControl1.LoadDocument(FilePath, oFormat)
|
|
||||||
|
|
||||||
Dim oRange = SpreadsheetControl1.ActiveWorksheet.GetUsedRange()
|
Dim oRange = SpreadsheetControl1.ActiveWorksheet.GetUsedRange()
|
||||||
oRange.AutoFitColumns()
|
oRange.AutoFitColumns()
|
||||||
@ -175,13 +169,103 @@ Public Class DocumentViewer
|
|||||||
Case Else
|
Case Else
|
||||||
mainToolStrip.Visible = True
|
mainToolStrip.Visible = True
|
||||||
|
|
||||||
|
GdViewer.ZoomMode = ViewerZoomMode.ZoomModeWidthViewer
|
||||||
|
GdViewer.DocumentAlignment = ViewerDocumentAlignment.DocumentAlignmentTopCenter
|
||||||
|
|
||||||
GdViewer.DisplayFromFile(FilePath)
|
GdViewer.DisplayFromFile(FilePath)
|
||||||
End Select
|
End Select
|
||||||
|
|
||||||
|
UpdateMainUi()
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
_logger.Error(ex)
|
_logger.Error(ex)
|
||||||
End Try
|
End Try
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
|
Private Sub DoLoadFile(Stream As Stream, Extension As String)
|
||||||
|
Try
|
||||||
|
RichEditControl1.Visible = False
|
||||||
|
RichEditControl1.Dock = DockStyle.None
|
||||||
|
|
||||||
|
SpreadsheetControl1.Visible = False
|
||||||
|
SpreadsheetControl1.Dock = DockStyle.None
|
||||||
|
|
||||||
|
mainToolStrip.Visible = False
|
||||||
|
|
||||||
|
Select Case Extension.ToUpper
|
||||||
|
Case ".MSG"
|
||||||
|
Dim oMsg As New Message(Stream)
|
||||||
|
|
||||||
|
' TODO: Improve Encoding, maybe convert based on encoding
|
||||||
|
oMsg.Encoding = System.Text.Encoding.UTF32
|
||||||
|
Dim oMime = oMsg.ConvertToMimeMessage()
|
||||||
|
Dim oTempFileName = IO.Path.GetTempFileName()
|
||||||
|
oMime.Save(oTempFileName, True)
|
||||||
|
|
||||||
|
RichEditControl1.LoadDocument(oTempFileName, XtraRichEdit.DocumentFormat.Mht)
|
||||||
|
|
||||||
|
_TempFiles.Add(oTempFileName)
|
||||||
|
|
||||||
|
RichEditControl1.Visible = True
|
||||||
|
RichEditControl1.Dock = DockStyle.Fill
|
||||||
|
|
||||||
|
Case ".EML", ".DOC", ".DOCX", ".ODT", ".RTF", ".TXT"
|
||||||
|
RichEditControl1.LoadDocument(Stream, GetDocumentFormat(Extension))
|
||||||
|
|
||||||
|
RichEditControl1.Visible = True
|
||||||
|
RichEditControl1.Dock = DockStyle.Fill
|
||||||
|
|
||||||
|
Case ".XLSX", ".XLS", "CSV"
|
||||||
|
SpreadsheetControl1.LoadDocument(Stream, GetSpreadsheetFormat(Extension))
|
||||||
|
|
||||||
|
Dim oRange = SpreadsheetControl1.ActiveWorksheet.GetUsedRange()
|
||||||
|
oRange.AutoFitColumns()
|
||||||
|
|
||||||
|
SpreadsheetControl1.Visible = True
|
||||||
|
SpreadsheetControl1.Dock = DockStyle.Fill
|
||||||
|
|
||||||
|
Case Else
|
||||||
|
mainToolStrip.Visible = True
|
||||||
|
|
||||||
|
GdViewer.ZoomMode = ViewerZoomMode.ZoomModeWidthViewer
|
||||||
|
GdViewer.DocumentAlignment = ViewerDocumentAlignment.DocumentAlignmentTopCenter
|
||||||
|
|
||||||
|
GdViewer.DisplayFromStream(Stream)
|
||||||
|
End Select
|
||||||
|
|
||||||
|
UpdateMainUi()
|
||||||
|
Catch ex As Exception
|
||||||
|
_logger.Error(ex)
|
||||||
|
End Try
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Private Function GetSpreadsheetFormat(Extension) As Spreadsheet.DocumentFormat
|
||||||
|
Dim oFormat As Spreadsheet.DocumentFormat = Spreadsheet.DocumentFormat.Undefined
|
||||||
|
|
||||||
|
Select Case Extension.ToUpper
|
||||||
|
Case "XLSX" : oFormat = Spreadsheet.DocumentFormat.Xlsx
|
||||||
|
Case "XLS" : oFormat = Spreadsheet.DocumentFormat.Xls
|
||||||
|
Case "CSV" : oFormat = Spreadsheet.DocumentFormat.Csv
|
||||||
|
End Select
|
||||||
|
|
||||||
|
Return oFormat
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Private Function GetDocumentFormat(Extension)
|
||||||
|
Dim oFormat As XtraRichEdit.DocumentFormat = XtraRichEdit.DocumentFormat.Undefined
|
||||||
|
|
||||||
|
Select Case Extension.ToUpper
|
||||||
|
Case ".EML" : oFormat = XtraRichEdit.DocumentFormat.Mht
|
||||||
|
Case ".DOC" : oFormat = XtraRichEdit.DocumentFormat.Doc
|
||||||
|
Case ".DOCX" : oFormat = XtraRichEdit.DocumentFormat.OpenXml
|
||||||
|
Case ".ODT" : oFormat = XtraRichEdit.DocumentFormat.OpenDocument
|
||||||
|
Case ".RTF" : oFormat = XtraRichEdit.DocumentFormat.Rtf
|
||||||
|
Case ".TXT" : oFormat = XtraRichEdit.DocumentFormat.PlainText
|
||||||
|
End Select
|
||||||
|
|
||||||
|
Return oFormat
|
||||||
|
End Function
|
||||||
|
|
||||||
|
|
||||||
Private Sub btnOpen_Click(sender As Object, e As EventArgs)
|
Private Sub btnOpen_Click(sender As Object, e As EventArgs)
|
||||||
GdViewer.ZoomMode = ViewerZoomMode.ZoomModeWidthViewer
|
GdViewer.ZoomMode = ViewerZoomMode.ZoomModeWidthViewer
|
||||||
GdViewer.DocumentAlignment = ViewerDocumentAlignment.DocumentAlignmentTopCenter
|
GdViewer.DocumentAlignment = ViewerDocumentAlignment.DocumentAlignmentTopCenter
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user