C#Azure文件存储CloudFile.OpenWrite与OpenXml.SpreadsheetDocument的问题…需要文件模式和文件访问选项吗?
我正在使用DocumentFormat.OpenXml.SpreadsheetDocument,打开Excel文档的模板,写入并保存它 它的工作原理类似于普通文件流中的魅力:C#Azure文件存储CloudFile.OpenWrite与OpenXml.SpreadsheetDocument的问题…需要文件模式和文件访问选项吗?,c#,excel,azure,openxml-sdk,azure-storage-files,C#,Excel,Azure,Openxml Sdk,Azure Storage Files,我正在使用DocumentFormat.OpenXml.SpreadsheetDocument,打开Excel文档的模板,写入并保存它 它的工作原理类似于普通文件流中的魅力: using (var documentStream = System.IO.File.Open("--somePath--", FileMode.Open, FileAccess.ReadWrite)) { using (var document = SpreadsheetDocument.Open(documen
using (var documentStream = System.IO.File.Open("--somePath--", FileMode.Open, FileAccess.ReadWrite))
{
using (var document = SpreadsheetDocument.Open(documentStream, true))
{
// do something
}
}
请注意电子表格文档。打开
现在,我正在将此应用程序重写到Azure,并在“WindowsAzure.storage”包中使用Azure存储及其.NET文件库
它就像一个符咒,我想在Azure中填充相同的excel文件
using (var documentStream = _GetRootDirectoryOfAccount().GetFileReference("--someRelativePath--").OpenWrite(null))
{
using (var document = SpreadsheetDocument.Open(documentStream, true))
{
// do something
}
}
第一部分“\u getRootDirectoryOfcount().GetFileReference”可以100%工作,然后OpenWrite(null)确实打开了一个流
但是,当该流被推向电子表格时:
SpreadsheetDocument.Open(documentStream, true)
它与:
System.IO.IOException:'无法打开包,因为文件模式或
FileAccess值对流无效。“
这是因为在流上未设置设置:
System.IO.File.Open(“--somePath--”,FileMode.Open,FileAccess.ReadWrite)
有人知道怎么避开这件事吗?还是一个解决方案
请:)
有人知道怎么避开这件事吗?还是一个解决方案
“\ucode>GetRootDirectoryOfcount().GetFileReference(“--someRelativePath-->”).OpenWrite(null))的返回类型是CloudFileStream
`
似乎不支持CloudFileStream
请尝试使用下面的代码,它在我这边正常工作。更新内容后,我们可以使用file.UploadFromFile()或file.UploadFromStream()上传文件
var file = _GetRootDirectoryOfAccount().GetFileReference("--someRelativePath--");
var memoryStream = new MemoryStream();
file.DownloadToStream(memoryStream);
using (var document = SpreadsheetDocument.Open(memoryStream, true))
{
// do something
}
下面是我的演示代码
var connectionString = "DefaultEndpointsProtocol=https;AccountName=accountName;AccountKey=xxxxx;EndpointSuffix=core.windows.net";
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
CloudFileClient fileClient = storageAccount.CreateCloudFileClient();
// Get a reference to the file share we created previously.
CloudFileShare share = fileClient.GetShareReference("test"); //share name
if (share.Exists())
{
// Get a reference to the root directory for the share.
CloudFileDirectory rootDir = share.GetRootDirectoryReference();
// Get a reference to the directory we created previously.
CloudFileDirectory sampleDir = rootDir.GetDirectoryReference("custom");
// Ensure that the directory exists.
if (sampleDir.Exists())
{
// Get a reference to the file we created previously.
var file = sampleDir.GetFileReference("OpenXMl.xlsx"); //file name
// Ensure that the file exists.
if (file.Exists())
{
// Write the contents of the file to the console window.
Console.WriteLine(file.DownloadTextAsync().Result);
var memoryStream = new MemoryStream();
file.DownloadToStream(memoryStream);
using (var document = SpreadsheetDocument.Open(memoryStream, true))
{
// do something
}
}
}
}
有人知道怎么避开这件事吗?还是一个解决方案
“\ucode>GetRootDirectoryOfcount().GetFileReference(“--someRelativePath-->”).OpenWrite(null))的返回类型是CloudFileStream
`
似乎不支持CloudFileStream
请尝试使用下面的代码,它在我这边正常工作。更新内容后,我们可以使用file.UploadFromFile()或file.UploadFromStream()上传文件
var file = _GetRootDirectoryOfAccount().GetFileReference("--someRelativePath--");
var memoryStream = new MemoryStream();
file.DownloadToStream(memoryStream);
using (var document = SpreadsheetDocument.Open(memoryStream, true))
{
// do something
}
下面是我的演示代码
var connectionString = "DefaultEndpointsProtocol=https;AccountName=accountName;AccountKey=xxxxx;EndpointSuffix=core.windows.net";
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
CloudFileClient fileClient = storageAccount.CreateCloudFileClient();
// Get a reference to the file share we created previously.
CloudFileShare share = fileClient.GetShareReference("test"); //share name
if (share.Exists())
{
// Get a reference to the root directory for the share.
CloudFileDirectory rootDir = share.GetRootDirectoryReference();
// Get a reference to the directory we created previously.
CloudFileDirectory sampleDir = rootDir.GetDirectoryReference("custom");
// Ensure that the directory exists.
if (sampleDir.Exists())
{
// Get a reference to the file we created previously.
var file = sampleDir.GetFileReference("OpenXMl.xlsx"); //file name
// Ensure that the file exists.
if (file.Exists())
{
// Write the contents of the file to the console window.
Console.WriteLine(file.DownloadTextAsync().Result);
var memoryStream = new MemoryStream();
file.DownloadToStream(memoryStream);
using (var document = SpreadsheetDocument.Open(memoryStream, true))
{
// do something
}
}
}
}