我不知道使用Richtextbox控件会很困难。我正在尝试获取剪贴板数据并尝试在RichTextBox中设置。
RichTextBox rtb = new RichTextBox();
rtb.Rtf = Clipboard.GetText(TextDataFormat.Rtf);
如何迭代 表集合 或Indivisual表?我们可以从RichTextBox中找到表计数吗?
我的目标是查找剪贴板RTF数据中是否有任何表格,如果是,则检查其中的数据。
答案 0 :(得分:0)
虽然回答这个问题有点太晚了。我也遇到了同样的要求。这样我继续说道:
private static void findTableinRtf(string rtf)
{
var flowDocument = new FlowDocument();
var textRange = new TextRange(flowDocument.ContentStart, flowDocument.ContentEnd);
using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(rtf)))
{
textRange.Load(ms, DataFormats.Rtf);
}
var blocks = flowDocument.Blocks;
foreach (var block in flowDocument.Blocks)
{
switch (block)
{
case List list:
//implement List;
break;
case Table table:
workWithTable(table);
break;
case Paragraph paragraph:
convertParagraph(paragraph);
break;
case Section section:
convertSection(section);
break;
}
}
}
private static void workWithTable(Table rtfTable)
{
TableColumnCollection columns = rtfTable.Columns;
TableRowGroupCollection rowGroups = rtfTable.RowGroups;
foreach (var row in rowGroups[0].Rows)
{
//access cells
// row row.Cells[i];
}
}