1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| Public Function PrintDoc(ByVal TemplateName As String, ByVal DataSource As DataSet, Optional ByVal Codage As TypeCodage = TypeCodage.NoCodage) As String 'ByVal CreateFile As String, Optional ByVal AskIfExist As Boolean = True,
Dim StringPrintDoc As String
Dim StringToBase64 As String
Dim HashTable As New Hashtable()
Dim StreamDocument As Stream
HashTable = Me.ConversionHashTable(DataSource)
Try
Dim MS As New MemoryStream
Dim wordDocument As WordprocessingDocument = WordprocessingDocument.Create(MS, WordprocessingDocumentType.Document)
Dim mainPart As MainDocumentPart = wordDocument.AddMainDocumentPart()
mainPart.Document = New Document()
Dim body As Body = mainPart.Document.AppendChild(New Body())
Dim para As Paragraph = body.AppendChild(New Paragraph())
Dim run As Run = para.AppendChild(New Run())
run.AppendChild(New Text("Ca fonctionne :)"))
StreamDocument = mainPart.GetStream()
StringToBase64 = StreamDocument.ToString()
StringPrintDoc = EncodeTo64(StringToBase64)
TextBox1.Text = StringToBase64
TextBox2.Text = StringPrintDoc
Catch ex As NullReferenceException
Console.WriteLine(Err.Description)
Catch ex As ArgumentException
End Try
Return StringPrintDoc
End Function |
Partager