讀 WordPad 文件

最近想了一個問題

我們已經可以讀取或寫入Excel, 筆記本, Word...等等的檔案

但對於 WordPad(.rtf) 好像沒有專門的 subVI 或 Toolkit 可使用

所以請教各位先進們

如何寫一讀取(或寫入) WordPad 文件的 vi 呢?

p.s 原本我以為我完成了(wordpad01.vi), 但回家又run了一遍, 結果出現亂碼? 真是奇怪

你這程式是讀文字檔的,與Notepad開啟.rtf或不是文字檔格式的檔案一樣是亂碼.

你若用這寫文字檔的方式存成.rtf甚至.xls的檔案一樣可直接用Wordpad或Excle開啟不會是亂碼因為它們可接受文字檔,但是只要用Wodpad或Excle再存檔後就不是文字檔了,用文字檔方式開就變亂碼了,我想你的問題這樣造成的.

ㄜ~~  不太了解您的意思ㄝ

"但是只要用Wodpad或Excle再存檔後就不是文字檔了,用文字檔方式開就變亂碼了,我想你的問題這樣造成的."  這句話的意思是說如果我在 .txt 複製裡面的資料, 貼在 .rtf 或 .xls 上, 讀出來會變亂碼.   ----> 是這樣嗎?!

p.s 如果是這樣的話, 該如何解決?

pfrhsd951234640477.6961458333

<span =“apple-style-span” style="font-family: arial, helvetica, sans-serif; font-size: 14px; ">

How Do I Use Text from a Rich Text File?

Primary Software: LabVIEW Development Systems>>LabVIEW Full Development System
Primary Software Version: 8.6
Primary Software Fixed Version: N/A
Secondary Software: N/A
<td valign=“bottom” colspan=“50” =“linebuffer” style="font-family: arial, helvetica, sans-serif; font-size: 12px; : rgb(255, 255, 255); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">
<td =“tablegbg” style="font-family: arial, helvetica, sans-serif; font-size: 12px; : rgb(204, 204, 204); ">

Problem: 
LabVIEW does not have native support for the Rich Text File format. How can I use data contained within a .rtf file in LabVIEW?

Solution: 
If data is contained within a Rich Text File, it can be used by implementing a Rich Text Box and then using the Text property of that control. To do this:
  1. Open the Controls palette.
  2. Select .NET & ActiveX?RichTextBox and place it on the Front Panel.
  3. Select Modern?String & Path?String Indicator and place it on the Front Panel.
  4. Switch to the Block Diagram.
  5. Right click the RichTextBox and select Create?Method for System.Windows.Forms.RichText Box Class?LoadFile(String path) and place it on the Block Diagram.
  6. Right click the RichTextBox and select Create?Property for System.Windows.Forms.RichTextBox Class?Text and place it on the Block Diagram.
  7. Open the Functions palette and select Connectvivity?.NET?Close Reference and place on the Block Diagram.
  8. Open the Functions palette
  9. Select Programming?Dialog & User Interface?Simple Error Handler and place on the Block Diagram.
  10. Select Programming?File I/O?Adv File Functions?File Dialog and place on the Block Diagram.
  11. Select Programming?File I/O?Adv File Functions?Path to String and place on the Block Diagram.
  12. Wire everything together as pictured below.

也可以參考這個網頁說明:http://decibel.ni.com/content/docs/DOC-5532


他有提供一個範例:RichText_LV86.vi

我的意思是說你的程式讀的是文字檔,就像用Notepad(記事本)開啟檔案,文字檔中的換欄(\t)及換列(\r)規則我們可將字串轉矩陣.rtf檔不是文字檔,要用版大提供的方式來讀取.

下面就是rtf檔用Wordpad與Notepad開啟的比較.

![](upload://hboHuatulEv0thC94d9RImRDBxI.jpeg)

![](upload://Rxmjc9Hk0hJ15x5Z2rBIBNSDKV.jpeg)

rtf格式可說是一種跨平台的格式。


其實在實用上,他的普及度不會比word差。


比如說,windows系統跟linux系統都看得懂*.html檔。因為它們都認得相同的格式。

同樣的,不同的作業系統內建的讀文件程式看得懂rtf格式,所以我才說,rtf格式的普及度不會比word差。

喔喔, 原來如此

想不到文件格式的讀取, 也有這麼大的學問

謝謝各位指導

我再補充一點給你參考,副檔名只是為了讓作業系統 選擇直接用哪個程式開啟.

下面範例我用Notepad寫了個文字檔,副檔名我給為.rtf(假的RTF.rtf),然後再用Wordpad開啟另存為RTF格式(真的RTF.rtf),它們檔案大小有差異,用Wordpad開啟時幾乎一樣,只是左上角1個顯示為文字檔圖示,另1個顯示為RTF檔圖示.

真假RTF.rar

![](upload://9OEXxYNvA4BSMUjlAn1ZPDWgaIw.jpeg)

![](upload://cSmkfXI8mZM2VaMiTy5rBbdZmP3.jpeg)

DonWang40478.3837268519