【问题标题】:How to get plain text from Appointment.Details?如何从 Appointment.Details 中获取纯文本?
【发布时间】:2018-01-29 15:26:14
【问题描述】:

我尝试从 Appointment.Details 获取纯文本,而不是 html 文档。

我发现事件是否由 Microsoft 日历供应商创建,例如hotmail,它们的详细信息将显示在 html 文档中,而不是纯文本(顺便说一句,如果事件是由 Gmail 创建的,它们的详细信息是纯文本)。我尝试通过以下方式获取纯文本,但它不起作用。

var appointmentStore = await AppointmentManager.RequestStoreAsync(AppointmentStoreAccessType.AllCalendarsReadWrite);

FindAppointmentsOptions options = new FindAppointmentsOptions { MaxCount = 100 };
options.FetchProperties.Add(AppointmentProperties.Subject);
options.FetchProperties.Add(AppointmentProperties.Details);
options.FetchProperties.Add(AppointmentProperties.DetailsKind);

DateTimeOffset startTime = new DateTimeOffset(new DateTime(2018, 2, 1));
// The UWP api gets the events from the Calendar app of Windows 10 OS.
List<Appointment> evtList = 
    (await appointmentStore.FindAppointmentsAsync(startTime, new TimeSpan(30, 0, 0, 0), options)).ToList();

foreach (var evt in evtList) {

    Debug.WriteLine(evt.Subject);

    // I've found if the events were created in Microsoft calendar supplier, e.g. hotmail,
    // the details of them would be the html document instead of the plain text.
    // I've tried to make the evt.Details presented in the plain text 
    // instead of the html document, but this way doesn't work.
    evt.DetailsKind = AppointmentDetailsKind.PlainText;

    Debug.WriteLine(evt.Details);
}

实际上我在 C++ 环境中工作,它也可以使用 UWP API。我习惯测试 并首先验证 C# 中的 API。

另外,遗憾的是,UWP api HtmlUtilities.ConvertToText() 无法满足我的需求。在我的 C++ 项目中,调用HtmlUtilities.ConvertToText() 会导致Static Buffer Overruns

【问题讨论】:

    标签: c# uwp


    【解决方案1】:

    我发现事件是否由 Microsoft 日历供应商创建,例如hotmail,它们的详细信息将显示在 html 文档中,而不是纯文本(顺便说一句,如果事件是由 Gmail 创建的,它们的详细信息是纯文本)。

    是的,这是日历商店应用程序中“Microsoft 日历供应商”的特殊功能。您可以使用它来编辑带有格式的详细约会。

    如果要将详细信息转换为纯文本,可以使用HtmlAgilityPack.NetCore 解析html,如下所示。

    if (evt.DetailsKind == AppointmentDetailsKind.Html)
    {
        HtmlDocument doc = new HtmlDocument();
        doc.LoadHtml(evt.Details);
    
        var nodes = doc.DocumentNode.SelectNodes("//p[@class='MsoNormal']");
        foreach (var node in nodes)
        {
            var text = node.InnerText;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-26
      • 2015-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多