我有一个 UWP 应用程序。我从 SharePoint 驱动器中取出一个 excel 文件,将其更改为字节数组,然后将其保存到我的硬盘驱动器中。
编辑
所以我意识到此时我已经打开了文件,因此无需再次打开它。所以我做了一些修改(这次是全班):
class FileHelper
{
public static string saveLocation;
public static SpreadsheetDocument spreadsheetDoc;
public static async void GetFileAsync()
{
var (authResult, message) = await Authentication.AquireTokenAsync();
var httpClient = new HttpClient();
HttpResponseMessage response;
var request = new HttpRequestMessage(HttpMethod.Get, MainPage.fileurl);
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", authResult.AccessToken);
response = await httpClient.SendAsync(request);
byte[] fileBytes = await response.Content.ReadAsByteArrayAsync();
StorageLibrary videoLibrary = await StorageLibrary.GetLibraryAsync(KnownLibraryId.Videos);
string saveFolder = videoLibrary.SaveFolder.Path;
string saveFileName = App.Date + "-" + App.StartTime + "-" + App.IBX + "-" + App.Generator + ".xlsx";
saveLocation = saveFolder + "\\" + saveFileName;
using (MemoryStream stream = new MemoryStream())
{
stream.Write(fileBytes, 0, (int)fileBytes.Length);
using (spreadsheetDoc = SpreadsheetDocument.Open(stream, true))
{
UpdateCell(spreadsheetDoc, App.Date, 2, "D");
await Task.Run(() =>
{
File.WriteAllBytes(saveLocation, stream.ToArray());
});
}
}
}
写入文件,但不使用 UpdateCell() 调用的数据输入更新文件。
元芳怎么了
相关分类