SPREAD for Windows Forms 8.0J サンプルコード集
リッチテキスト形式のデータを表示する

リッチテキスト型セル(RichTextCellTypeクラス)を定義したセルのValueプロパティにリッチテキスト形式の情報を設定します。次のサンプルでは、RichTextBoxコントロールを使用してRTFを設定しています。

【実行例】

リッチテキスト形式の表示

  • Excelファイルへのエクスポート時、リッチテキスト型セルではデータ(文字列)のみが出力されます。(各スタイルは反映されません)
  • リッチテキスト型セルの機能は基本的に標準の「リッチテキストボックスコントロール」と同等となります。
  • 表示スタイルはOS標準の「ワードパッド」と同等となるため、「Word」等の特有のスタイル情報には対応していません。

 private void Form1_Load(object sender, System.EventArgs e)
 {

  // リッチテキスト文字列の作成
  String rtfText = null;
  using (RichTextBox temp = new RichTextBox())
  {
   temp.Text = "ABC" + "\r\n" + "DEF" + "\r\n" + "GHI";
   temp.SelectionStart = 0;
   temp.SelectionLength = 3;
   temp.SelectionColor = Color.Red;
   temp.SelectionFont = new Font("MS UI Gothic", 9);
   temp.SelectionStart = 4;
   temp.SelectionLength = 3;
   temp.SelectionColor = Color.Blue;
   temp.SelectionFont = new Font("MS UI Gothic", 12);
   temp.SelectionStart = 8;
   temp.SelectionLength = 3;
   temp.SelectionColor = Color.Green;
   temp.SelectionFont = new Font("MS UI Gothic", 15);
   temp.SelectionStart = 0;
   temp.SelectionLength = 12;
   temp.SelectionAlignment = HorizontalAlignment.Center;
   rtfText = temp.Rtf;
  }

  // リッチテキスト型セルの定義
  FarPoint.Win.Spread.CellType.RichTextCellType rich = new FarPoint.Win.Spread.CellType.RichTextCellType();
  rich.Multiline = true;
  fpSpread1.ActiveSheet.Cells[0, 0].CellType = rich;
  fpSpread1.ActiveSheet.Cells[0, 0].Value = rtfText;

  fpSpread1.ActiveSheet.SetRowHeight(0, 80);

 }
 Private Sub CellType_10_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

  ' リッチテキスト文字列の作成
  Dim rtfText As String = String.Empty
  Using temp As New RichTextBox()
   temp.Text = "ABC" + vbCrLf + "DEF" + vbCrLf + "GHI"
   temp.SelectionStart = 0
   temp.SelectionLength = 3
   temp.SelectionColor = Color.Red
   temp.SelectionFont = New Font("MS UI Gothic", 9)
   temp.SelectionStart = 4
   temp.SelectionLength = 3
   temp.SelectionColor = Color.Blue
   temp.SelectionFont = New Font("MS UI Gothic", 12)
   temp.SelectionStart = 8
   temp.SelectionLength = 3
   temp.SelectionColor = Color.Green
   temp.SelectionFont = New Font("MS UI Gothic", 15)
   temp.SelectionStart = 0
   temp.SelectionLength = 12
   temp.SelectionAlignment = HorizontalAlignment.Center
   rtfText = temp.Rtf
  End Using

  'リッチテキスト型セルの定義
  Dim rich As New FarPoint.Win.Spread.CellType.RichTextCellType()
  rich.Multiline = True
  FpSpread1.ActiveSheet.Cells(0, 0).CellType = rich
  FpSpread1.ActiveSheet.Cells(0, 0).Value = rtfText

  FpSpread1.ActiveSheet.SetRowHeight(0, 80)

 End Sub

 

 


© 2004-2015, GrapeCity inc. All rights reserved.