回复 1楼774828727的帖子
你好,
该问题需要通过自定义单元格类型来处理,详细请参考代码:
- private void Form1_Load(object sender, EventArgs e)
- {
- FarPoint.Win.Spread.SheetView sv = this.fpSpread1.Sheets[0];
- MyRIFCellType rtb;
- rtb = new MyRIFCellType();
- rtb.MaxLength = 10;
- rtb.Multiline = true;
- System.IO.StreamReader reader = new System.IO.StreamReader("test.rtf");
- string text = reader.ReadToEnd();
- sv.Cells[0, 0].CellType = rtb;
- sv.Cells[0, 0].Value = text;
- sv.Rows[0].Height = 200;
- sv.Columns[0].Width = 200;
- this.fpSpread1.EditModeOn += new EventHandler(fpSpread1_EditModeOn);
- }
- void fpSpread1_EditModeOn(object sender, EventArgs e)
- {
- RichTextBox test = this.fpSpread1.EditingControl as RichTextBox;
- test.SelectionChanged += new EventHandler(test_SelectionChanged);
- }
- void test_SelectionChanged(object sender, EventArgs e)
- {
- RichTextBox rtf = sender as RichTextBox;
- rtf.SelectionColor = Color.Yellow;
- }
- }
- class MyRIFCellType : FarPoint.Win.Spread.CellType.RichTextCellType
- {
- RichTextBox rtfEditor;
- public override Control GetEditorControl(Control parent, FarPoint.Win.Spread.Appearance appearance, float zoomFactor)
- {
- rtfEditor = new RichTextBox();
- return rtfEditor;
- }
- public override void SetEditorValue(object value)
- {
- rtfEditor.Rtf = value.ToString();
- }
- public override object GetEditorValue()
- {
- return rtfEditor.Rtf;
- }
- }
复制代码 |