4

かなり大きな Excel ファイルが与えられました。このファイルには、1 行に Oracle データベースからの clob ダンプが 1 つ含まれています。そのうちの 1 つが次のようになっている可能性があります。

{\rtf1\ansi\deff0\deftab708{\fonttbl{\f0\fnil\fcharset0 Courier New;}{\f1\fnil\fcharset0 Arial;}{\f2\fnil\fcharset0 MS Sans Serif;}{\f3\fnil\fcharset0 Times New Roman;}{\f4\fnil\fcharset238 Times New Roman CE;}{\f5\fnil\fcharset204 Times New Roman Cyr;}{\f6\fnil\fcharset161 Times New Roman Greek;}{\f7\fnil\fcharset162 Times New Roman Tur;}{\f8\fnil\fcharset186 Times New Roman Baltic;}}{\colortbl\red0\green0\blue0;\red255\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0;\red255\green0\blue255;\red128\green0\blue128;\red255\green255\blue0;\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;\red128\green128\blue0;\red128\green0\blue0;\red128\green128\blue128;\red255\green255\blue255;}\paperw11906\paperh16838\margl1417\margr1417\margt1417\margb1417{\*\pnseclvl1\pnucrm\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{.}}}{\*\pnseclvl2\pnucltr\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{.}}}{\*\pnseclvl3\pndec\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{.}}}{\*\pnseclvl4\pnlcltr\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{)}}}{\*\pnseclvl5\pndec\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}{\*\pnseclvl6\pnlcltr\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}{\*\pnseclvl7\pnlcrm\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}{\*\pnseclvl8\pnlcltr\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}{\*\pnseclvl9\pnlcrm\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}{\pard\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f3\fs24\cf0 FOO FOO FOO \'85\'85. \'85\'85..}}

さて、このデータを に入れ、その値を読み取ると、簡単System.Windows.Forms.RichTextBoxな変換が得られます。しかし、どういうわけかそれはその改行をもたらします。.Rtf.Text

私はそれらを削除しようとしました

rtf.Replace("\n", "").Replace("\r", "").Replace(Environment.NewLine, "")

しかし、それは役に立たないようです。

リッチテキスト形式を1行 のプレーンテキストに変換する方法を知っている人はいますか?

4

2 に答える 2

10

保存のために抽出されたコードのを見てください。

更新-- VB.NET プログラムからのコピー アンド ペースト エラー -- 申し訳ありません。

class ConvertFromRTF
{
    static void Main()
    {

        string path = @"test.rtf";

        //Create the RichTextBox. (Requires a reference to System.Windows.Forms.dll.)
        using(System.Windows.Forms.RichTextBox rtBox = new System.Windows.Forms.RichTextBox());
        {

            // Get the contents of the RTF file. Note that when it is 
           // stored in the string, it is encoded as UTF-16. 
            string s = System.IO.File.ReadAllText(path);

            // Convert the RTF to plain text.
            rtBox.Rtf = s;
            string plainText = rtBox.Text;

            // Now just remove the new line constants
            plainText = plainText.Replace("\r\n", ",");

            // Output plain text to file, encoded as UTF-8.
            System.IO.File.WriteAllText(@"output.txt", plainText);
        }
    }
}
于 2012-09-28T13:06:21.513 に答える
1

方法:RTFをプレーンテキストに変換する(C#プログラミングガイド)

.NET Frameworkでは、RichTextBoxコントロールを使用して、RTFをサポートし、ユーザーがWYSIWIG方式でテキストに書式を適用できるワードプロセッサを作成できます。

RichTextBoxコントロールを使用して、プログラムでRTFフォーマットコードをドキュメントから削除し、プレーンテキストに変換することもできます。この種の操作を実行するために、Windowsフォームにコントロールを埋め込む必要はありません。

于 2012-09-28T13:03:34.200 に答える