Using Existing Excel Templates .xltm

Hi,

I am using Aspose.Cells component to build excel sheets dynamically in ASPX page. I am stuck up with 2 issues Please provide your guidance:

1) is it possible or not to create a excel sheet from a pre-existing template .xltm? When I checked the same the feasilbilty is there using LoadFormat & Load Options. But the Enum LoadFormat doesnt have .xltm extension as provided in the link : http://www.aspose.com/docs/display/cellsnet/Opening+Files

So please suggest how to use .xltm file (which has macros) to create a new workbook.

2) The template .xltm to be used can be used by any number of users in real time to create the new excel sheets they want. I mean to say same template typed excels can be requested to be created in run time when application is used. So if a template is opened in file mode Open (using file stream construction of Workbook.Open) wouldnt it result in File locks & cause exceptions. Please suggest.

Regards,

dmuruga

Hi,


Thank you for using Aspose.Cells.

Regarding your query of loading a pre-existing template .xltm file, you can use the following line of code to achieve this:

Workbook workbook = new Workbook("Template.xltm");

For your second query, I think if it is a read only operation by multiple users at the same time, there should be no issue. When a .xltm template is loaded as shown above, a copy of the workbook is loaded in the object and this object can be used to generate new workbooks based on the template data.

Also please note that Workbook.Open() is no more supported, and you may refer to the section "opening through stream" of this document for loading a file through stream. Please download and use this latest fix: Aspose.Cells for .NET v7.2.1.7 .





Hi,


1) XLSX and XLTM are approximately similar formats (Excel 2007/2010 formats), so you don’t really have to specify the LoadFormat or even use Auto member for it while loading the file. For example you may try:
string filename = @“E:\test2\Template zip\MasterTemplate.xltm”;
Workbook _wb = new Workbook(filename, new LoadOptions(LoadFormat.Auto));
//…Your code goes here.
_wb.Save(@“E:\test2\Template zip\MyFile.xltm”, SaveFormat.Xltm);

2) This will work OK as long as you re-save the template file to similar/other formats specifying names for the files by your different users. Also, Once you open/save the file (by Aspose.Cells APIs) from streams, you may close the stream as accordingly.

Thank you.