-
Notifications
You must be signed in to change notification settings - Fork 1
打开并显示简历
03xiaoyuhe edited this page Dec 5, 2024
·
3 revisions
该部分以用户控件库的模式实现
简历显示控件提供两种展示函数:
-
Show(sting )- 传入参数:
- 文件路径
string
- 文件路径
- 传入参数:
-
Show(ResumeFile )- 传入参数:
- 文件对象
ResumeFile
- 文件对象
- 传入参数:
使用Aspose.Words库提取简历文件信息,并通过富文本显示控件RichTextBox,将word文件显示在自定义渲染控件中。
using Aspose.Words;
using System.IO;
using System.Windows.Documents;
public void OpenWord(string fileName, RichTextBox richTextBox)
{
try
{
// 加载 Word 文档
Document doc = new Document(fileName);
// 将文档保存为 XAML 流
using (MemoryStream xamlStream = new MemoryStream())
{
doc.Save(xamlStream, SaveFormat.XamlFlow);
xamlStream.Position = 0;
// 将 XAML 流加载到 FlowDocument
FlowDocument flowDocument = System.Windows.Markup.XamlReader.Load(xamlStream) as FlowDocument;
// 设置到 RichTextBox
richTextBox.Document = flowDocument;
}
}
catch (IOException ioEx)
{
MessageBox.Show($"无法打开文件: {ioEx.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
}
catch (Exception ex)
{
MessageBox.Show($"发生错误: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
}
}