2017-04-04 32 views
1

我有一個文本區域,它將有多行文本,我需要輸出以保持輸入到文本區域的所有格式。如何才能做到這一點?這裏是我正在創建文本區域:我有一個文本區域,將有多行文本

<table border="0" cellpadding="5" cellspacing="5" width="95%">    
<tr> 
<td colspan="2"> 
<b>Status: </b> 
<textarea name="Text2" id="styled"></textarea> 
</td> 
</tr> 
</table> 
+0

什麼輸出?什麼格式? –

+0

我正在使用輸入到該textarea的文本爲使用CDO.Message發送的電子郵件創建文本輸出。 – Jason

回答

0

這是不可能維持的文本格式<textarea>按照您的要求。

如果文本中存在某些內容,則可以實現維護新行(基本上是包裝文本)。 你必須使用「wrap=Hard」。

https://www.w3schools.com/tags/att_textarea_wrap.asp

也可參考在<textarea>

HTML : How to retain formatting in textarea?

how to preserve formatting of html textarea

+0

最重要的部分就是維護換行符。 – Jason

+0

太好了。我將刪除「幾乎」一詞......謝謝。 – Naidu

0

計算器的答案,其中有更多的解釋(看看評論還)要留住從文本格式我能圖瞭解如何通過將文本區域導出爲文本文件,附加數據,然後使用導入它fso.OpenTextFile(「C:\ file.txt」,ForReading).ReadAll並使用 (html body pre) 進行格式化。這樣做,我能夠保留我的換行符,然後使用CDO.Message發送信息。

Const FOR_APPENDING = 8 
Set objFSO = CreateObject("Scripting.FileSystemObject") 
Set objTSO = objFSO.OpenTextFile("C:File.txt", FOR_APPENDING) 
objTSO.WriteLine strDT & ":" & vbCrLf & Text2.value & vbCrLf 
objTSO.Close() 



Sub SendEmail(strSubject, strBody, strBody8, strFrom) 

Const ForReading = 1 
Dim fso, BodyText 
Set fso = CreateObject("Scripting.FileSystemObject") 

strMailbox = "Address<[email protected]>"          
' E-Mail address being sent to 
strSMTPServer = "SMTP Server"           
' Primary SMTP relay server name  
strSMTPPort = 25                
' SMTP Port Number 

Set objEmail = CreateObject("CDO.Message") 
BodyText = fso.OpenTextFile("C:\file.txt",ForReading).ReadAll 
With objEmail 
.From  = strFrom 
.To  = strMailbox 
.Subject = strSubject 
.HTMLBody = "<html><body><pre>" & strBody & "<BR>" & BodyText & "<BR>" & 
strBody8 & "</pre></body></html>" 

With .Configuration.Fields 
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing"  ) = 2 
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver" ) = 
strSMTPServer 
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 
strSMTPPort 
.Update 
End With 
.Send            ' Send the message! 
End With 
Set objEmail = Nothing 
相關問題