How to work with package in MemoryStream

Feb 9, 2010 at 6:37 PM

First, let me just say how much I appreciate this incredible piece of work.  I'm a junior developer who just finished creating two very complex Excel exports using the OpenXML SDK.  I'm delighted to see your new API become available and imagine that I can rewrite everything in a short amount of time.

Again, I regret any noobie questions but need to do a reality check.  Can I use ExtremeML to work with packages in memory?  I'm building a server app and the users must decide where to store their docs.  If so, could you give me a hint?  I need to know for sure that I can do so before proceeding.  I think I've got everything else figured out but that.

Here's the code from my original solution:

        byte[] sourceBytes = File.ReadAllBytes(@"C:\path\ApproachTemplate.xlsx");
        MemoryStream stream = new MemoryStream();
        stream.Write(sourceBytes, 0, (int)sourceBytes.Length);


        using (myWorkbook = SpreadsheetDocument.Open(stream, true))
        {
  ...

Thanks tons.  All of my initial tests have worked without any problems whatsoever.  Great work and tons of thanks!

~Karuna

Coordinator
Feb 10, 2010 at 6:35 AM

Hello Karuna,

Many thanks for your kind words – positive feedback like that is always welcome.

As a general reply to your question, you can achieve with ExtremeML anything that can be achieved with the OpenXML SDK, because ExtremeML is simply a wrapper around the SDK.

However, in certain situations (and I suspect this is one of them), you might need to extend ExtremeML by modifying the source code.

To work with streams, you need to create an instance of SpreadsheetDocumentWrapper from a stream, in exactly the same way as your existing code creates a SpeadsheetDocument. But since the SpreadsheetDocumentWrapper factory methods do not currently include a stream overload, you will need to create one. If you look at the existing factory method code, you will see that they are very simple and adding a new overload requires just a few lines of code.

In fact, I am currently working on a premium edition of ExtremeML which will include full support for streaming functionality (as well as a whole range of other advanced features like images, worksheet comments, headers and footers and plenty more). I will be blogging about these upcoming features over the next few weeks, so it might be worthwhile subscribing at www.extrememl.com.

In the meantime, in order for you to experiment with the streaming functionality, I have created a custom runtime build that includes the streaming source code as it currently stands. You can download this runtime from www.extrememl.com/downloads/streaming-build.zip.

Here are a couple of code snippets showing how to use these overloads:

Creating a new Excel workbook with streamed output

using (var output = new FileStream("output_path", FileMode.Create, FileAccess.ReadWrite))
using (var package = SpreadsheetDocumentWrapper.Create(output))
{
      // Code to manipulate the empty package.
}

Opening a template workbook from an assembly resource and sending the output to a stream

using (var input = Assembly.GetExecutingAssembly().GetManifestResourceStream(TemplateResource))
using (var output = new FileStream("output_path", FileMode.Create, FileAccess.Write))
using (var package = SpreadsheetDocumentWrapper.Open(input, output))
{
      // Code to manipulate the template package.
}

As you can see, these method calls fit quite well with the code sample from your existing project, so you should find that you can achieve your goals reasonably easily.

However, I have to admit that I have not yet done much testing on these overloads, apart from a small set of units tests that prove that data is correctly streamed into and out of the package. I would recommend that you do some more serious testing before finally deciding whether this approach is suitable for you, as I have seen a number of forum threads in which SDK users are experiencing problems with streamed content, and I am a little worried that bugs in the SDK may have an effect of the way ExtremeML operates. Here is one example:

http://social.msdn.microsoft.com/Forums/en-US/oxmlsdk/thread/1f849681-b6d3-4c65-b84f-663f14244c55

Good luck with your project and don’t hesitate to ask if you need help with something.

Best regards,
Tim

Coordinator
Mar 24, 2010 at 8:46 AM

Hello Karuna,

I haven’t heard from you in a while – I hope your projects are progressing well.

I am writing today to tell you about a new stage in the lifecycle of ExtremeML – the introduction of a new edition.

Since its inception in late 2009, ExtremeML has evolved from being a seed of an idea into a stable framework that is already in use in a number of significant development projects.

During this period, I have received plenty of feedback, some of which has indicated that certain users have needs that go beyond what can be achieved through a pure community coding effort.

It is to meet these needs that we are in the process of creating the Premium Edition of ExtremeML, whose primary goals are as follows:

  • To deliver additional functionality that is not included in the Community Edition
  • To establish a formal relationship with our “pro” users, to enable us to offer priority support services
  • To eliminate the constraints of the GPL license, enabling users to deploy ExtremeML in proprietary applications

A tentative first step toward achieving these goals is the Premium Beta Programme, which officially launches today. You can read about it here.

If you are inspired by the idea of a richer feature set for ExtremeML, you might care to download the latest version of the User Guide, which includes 19 new tutorials, demonstrating the premium features available today. Alternatively, stand by for further posts in the coming days, in which some of these new features will be highlighted.

I hope to hear from you again soon.

Best regards,

Tim Coulter

From: khdeem [mailto:notifications@codeplex.com]
Sent: 09 February 2010 20:38
To: tim.coulter@online.fr
Subject: How to work with package in MemoryStream [extrememl:83794]

From: khdeem

First, let me just say how much I appreciate this incredible piece of work. I'm a junior developer who just finished creating two very complex Excel exports using the OpenXML SDK. I'm delighted to see your new API become available and imagine that I can rewrite everything in a short amount of time.

Again, I regret any noobie questions but need to do a reality check. Can I use ExtremeML to work with packages in memory? I'm building a server app and the users must decide where to store their docs. If so, could you give me a hint? I need to know for sure that I can do so before proceeding. I think I've got everything else figured out but that.

Here's the code from my original solution:

        byte[] sourceBytes = File.ReadAllBytes(@"C:\path\ApproachTemplate.xlsx");
        MemoryStream stream = new MemoryStream();
        stream.Write(sourceBytes, 0, (int)sourceBytes.Length);
 
 
        using (myWorkbook = SpreadsheetDocument.Open(stream, true))
        {
  ...

Thanks tons. All of my initial tests have worked without any problems whatsoever. Great work and tons of thanks!

~Karuna

Read the full discussion online.

To add a post to this discussion, reply to this email (extrememl@discussions.codeplex.com)

To start a new discussion for this project, email extrememl@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com