+ Reply to Thread
Results 1 to 4 of 4

How do I create an excel template 2007 (.xltx) programatically in C# using automation

  1. #1
    Registered User
    Join Date
    05-30-2009
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    2

    How do I create an excel template 2007 (.xltx) programatically in C# using automation

    I need to create an excel template with extension .xltx.

    The following code creates an xltx file. But when I open, I get an empty excel application with an error message "Excel cannot open the file 'NewTemplate.xltx' because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file."

    code:
    /////////////////
    workbook = workbooks.Add(System.Reflection, Missing.Value);

    workbook.SaveAs("D:\\NewTemplate.xltx", office2007.XlFileFormat.xlTemplate8, System.Reflection.Missing.Value, System.Reflection.Missing.Value, false, false, office2007.XlSaveAsAccessMode.xlNoChange, System.Reflection.Missing.Value, false, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value);

    workbooks.Close();
    excelApplication.Quit();
    /////////////////////////

    What is wrong with this code?
    Any help is very much appreciated.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: How do I create an excel template 2007 (.xltx) programatically in C# using automa

    You might want to try a C# forum -- we do VBA here.

    Please take a few minutes to read the forum rules, and then edit your post to add code tags.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Expert contaminated's Avatar
    Join Date
    05-07-2009
    Location
    Baku, Azerbaijan
    MS-Off Ver
    Excel 2013
    Posts
    1,430

    Re: How do I create an excel template 2007 (.xltx) programatically in C# using automa

    can it be done
    Last edited by contaminated; 05-30-2009 at 11:50 AM.
    Люди, питающие благие намерения, как раз и становятся чудовищами.

    Regards, ?Born in USSR?
    Vusal M Dadashev

    Baku, Azerbaijan

  4. #4
    Registered User
    Join Date
    05-30-2009
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: How do I create an excel template 2007 (.xltx) programatically in C# using automa

    Hi guys,

    The issue could be solved by replacing

    XlFileFormat.Template8
    with
    XlFileFormat.xlOpenXMLTemplate
    in workbook.SaveAs().

    with regards
    renkumari

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1