Link to home
Create AccountLog in
Avatar of dantheanswerman
dantheanswermanFlag for United States of America

asked on

OPEN XML (ExtremeML) How can I Copy a Workbook

I am trying to copy a workbook in openxml and create a new workbook.

Tried to follow the documentation, but I can't seem to make this work.

Can anyone tell me how to do this... in the code below "TemplateResource" is not recognized and I can't figure out what to use. I tried a file name, and the code runs, but the "input" var is null after its execution.
public static void CustomizeTemplateToStream()
    using (var input = Assembly.GetExecutingAssembly().GetManifestResourceStream(TemplateResource))
    using (var output = new FileStream("MyWorkbook.xlsx", FileMode.Create, FileAccess.Write))
    using (var package = SpreadsheetDocumentWrapper.Open(input, output))
        // Code here to customize the template workbook

Open in new window

Avatar of existenz2
Flag of Netherlands image

TemplateResource is a constant which holds the fully qualified name of the embedded template in the assembly.

So for example: MyAssembly.Templates.MyFirsTemplate.xslx
Avatar of Tim85

You don't need to use Excel templates that are embedded in the assembly as resources. You could equally assign any valid System.IO.Stream object to the "input" variable, for example a FileStream that is constructed using the path to file containing your template.
Avatar of dantheanswerman


OK.. I kind of understand where you're going with this, but am struggling to put it into C# code.

Could you give me some sample code on how to get this done?

Thanks so much... struggling with this.
Avatar of Tim85

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Thank you very much.