将UWP中的数据读入excel或txt文件

将UWP中的数据读入excel或txt文件

本文介绍了[UWP]将UWP中的数据读入excel或txt文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我正在运行微软的蓝牙低功耗样本。

I am running a Bluetooth low energy sample by Microsoft.

我正在使用这个样本来获取心脏使用极地设备的费率。 

I am using this sample to get the heart rates with polar device. 

输出如下::  https://ibb.co/qWmKNNS

Output looks like this::  https://ibb.co/qWmKNNS

现在,我想将这些数据(标记为黄色和红色)读入excel或文本文件。 

Now, I want to read those data (marked in yellow and red) into either excel or a text file. 

我应该对此做出哪些调整?以下是我认为可能有效的一个新程序,但如何使用此程序在文本文件上打印心率? 

What adjustments should I make to this? Below is one new program I thought might work, but how do I use this program to print the heart rates on the text file? 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace ConsoleProject
{
    class Program
    {
        static void Main(string[] args)
        {
            string strLogText = "Some details you want to log.";

            // Create a writer and open the file:
            StreamWriter log;

            if (!File.Exists("logfile.txt"))
            {
                log = new StreamWriter("logfile.txt");
            }
            else
            {
                log = File.AppendText("logfile.txt");
            }

            // Write to the file:
            log.WriteLine(DateTime.Now);

            log.WriteLine(strLogText);
            log.WriteLine();

            // Close the stream:
            log.Close();


        }
    }
}

以下是来自BLE的一种有数据的方法我想在txt文件上。 

And below is a one method from the BLE that has the data I want on the txt file. 

private async void Characteristic_ValueChanged(GattCharacteristic sender, GattValueChangedEventArgs args)
        {
            var newValue = FormatValueByPresentation(args.CharacteristicValue, presentationFormat);
            double mean = intervals.Average();
            double sumOfSquareDiff = intervals.Select(val => (val - mean) * (val - mean)).Sum();
            object vrHR = Math.Sqrt(sumOfSquareDiff / intervals.Count);

            var message = $"Value at {DateTime . Now : hh : mm : ss . FFF}  :  {newValue}  :::  Heart Rate Variability : " + vrHR.ToString(); // Data I would like to get printed on txt file.


            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
             () => CharacteristicLatestValue.Text = message);

        }




 




推荐答案

将数据写入txt文件并不复杂,因为你已经得到了字符串值。您可以使用
来将txt文件保存在您想要的位置。然后,您可以使用 方法将数据写入txt文件。

It not complex to write data into txt file as you had already get the string value. You could use aFileSavePicker to save the txt file in a place you want. Then you could use WriteTextAsync method to write data into that txt file.

 FileSavePicker savePicker = new FileSavePicker();
            savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            // Dropdown of file types the user can save the file as
            savePicker.FileTypeChoices.Add("Plain Text", new List<string>() { ".txt" });
            // Default file name if the user does not type one in or select a file to replace
            savePicker.SuggestedFileName = "New Document";

            StorageFile file = await savePicker.PickSaveFileAsync();
            if (file != null)
            {

                await FileIO.WriteTextAsync("message string you get", file.Name);
            }
            else
            {

            }

最佳问候,

Roy


这篇关于[UWP]将UWP中的数据读入excel或txt文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 19:30