I'm working with DocumentFormat.OpenXml.SpreadsheetDocument and opening a template of an Excel document, writing to it and saving it.
It works like charm from a normal File stream:
using (var documentStream = System.IO.File.Open("--somePath--", FileMode.Open, FileAccess.ReadWrite))
{
using (var document = SpreadsheetDocument.Open(documentStream, true))
{
// do something
}
}
Notice the SpreadsheetDocument.Open
Now, I'm rewriting this application to Azure, and using Azure storage and it's .NET File library in "WindowsAzure.Storage" package.
It works like a charm, all up to a point where I want to fill the same excel files in Azure.
using (var documentStream = _GetRootDirectoryOfAccount().GetFileReference("--someRelativePath--").OpenWrite(null))
{
using (var document = SpreadsheetDocument.Open(documentStream, true))
{
// do something
}
}
The first part "_GetRootDirectoryOfAccount().GetFileReference" works 100%, then OpenWrite(null) really opens a Stream.
However, when that Stream is pushed towards the Spreadsheet:
SpreadsheetDocument.Open(documentStream, true)
It breaks with:
System.IO.IOException: 'Cannot open package because FileMode or FileAccess value is not valid for the stream.'
And it is because on the Stream the settings are not set:
System.IO.File.Open("--somePath--", FileMode.Open, FileAccess.ReadWrite)
Does anyone know how to get around this? Or a solution?
Please :)