TEXTBOX PARA HTML

CARLOSCOUTO 29/05/2013 15:04:22
#424207
Boas ,
estoy a fazer um ficheiro de regitos em excell vba , precisava de enviar um email com texto em html, a minha duvida é como pego o formato de um Richtextbox para uma string tipo [Ô]<Html>.....</Html>[Ô]

abraço
CRACKER 29/05/2013 17:14:08
#424215
Resposta escolhida
Tenta esta função:

Public Shared Function FromRtf(ByVal rtf As RichTextBox) As String
Dim b, i, u As Boolean
b = False : i = False : u = False
Dim fontfamily As String = [Ô]Arial[Ô]
. Dim fontsize As Integer = 12
Dim htmlstr As String = String.Format([Ô]<html>{0}<body>{0}<div style=[Ô][Ô]text-align: left;[Ô][Ô]><span style=[Ô][Ô]font-family: Arial; font-size: 12pt;[Ô][Ô]>[Ô], vbCrLf)
Dim x As Integer = 0
While x < rtf.Text.Length
rtf.Select(x, 1)
If rtf.SelectionFont.Bold AndAlso (Not b) Then
htmlstr &= [Ô]<b>[Ô]
b = True
ElseIf (Not rtf.SelectionFont.Bold) AndAlso b Then
htmlstr &= [Ô]</b>[Ô]
b = False
End If
If rtf.SelectionFont.Italic AndAlso (Not i) Then
htmlstr &= [Ô]<i>[Ô]
i = True
ElseIf (Not rtf.SelectionFont.Italic) AndAlso i Then
htmlstr &= [Ô]</i>[Ô]
i = False
End If
If rtf.SelectionFont.Underline AndAlso (Not u) Then
htmlstr &= [Ô]<u>[Ô]
u = True
ElseIf (Not rtf.SelectionFont.Underline) AndAlso u Then
htmlstr &= [Ô]</u>[Ô]
u = False
End If
If fontfamily <> rtf.SelectionFont.FontFamily.Name Then
htmlstr &= String.Format([Ô]</span><span style=[Ô][Ô]font-family: {0}; font-size: {0}pt;[Ô][Ô]>[Ô], rtf.SelectionFont.FontFamily.Name, fontsize)
fontfamily = rtf.SelectionFont.FontFamily.Name
End If
If fontsize <> rtf.SelectionFont.SizeInPoints Then
htmlstr &= String.Format([Ô]</span><span style=[Ô][Ô]font-family: {0}; font-size: {0}pt;[Ô][Ô]>[Ô], fontfamily, rtf.SelectionFont.SizeInPoints)
fontsize = rtf.SelectionFont.SizeInPoints
End If
Dim curchar As String = rtf.SelectedText
Select Case curchar
Case vbCr, vbLf : curchar = [Ô]<br />[Ô]
Case [Ô]&[Ô] : curchar = [Ô]&[Ô] : x += [Ô]&[Ô].Length - 1
Case [Ô]<[Ô] : curchar = [Ô]<[Ô] : x += [Ô]<[Ô].Length - 1
Case [Ô]>[Ô] : curchar = [Ô]>[Ô] : x += [Ô]>[Ô].Length - 1
Case [Ô] [Ô] : curchar = [Ô] [Ô] : x += [Ô] [Ô].Length - 1
End Select
rtf.SelectedText = curchar
x += 1
End While
Return htmlstr & String.Format([Ô]</span>{0}</body>{0}</html>[Ô], vbCrLf)
End Function
Tópico encerrado , respostas não são mais permitidas