none
How do I generate excel file using openxml-SDK v2.0 supporting to msoffice 2007 RRS feed

  • Question

  • Hi,

    I am trying to open excel file(.xls/.xlsx) in ms-office2007 which is generated by using openxml sdk Version 2.0, but it didn't get open.

    What i did: I was generated a excel file using Openxmlsdk dll(DocumentFormat.OpenXml-2.6.0.0) and (System.IO.Packaging-1.0.0.0)
    but i am not able to open formatted/Normal files of excels are opened in ms-office2007.

    Note : Is there any code change or dll change please give me the reference also.
    Please help me out on this.
    • Moved by Sabah ShariqMVP Wednesday, November 16, 2016 8:44 AM Related to Microsoft Excel
    Wednesday, November 16, 2016 7:14 AM

All replies

  • Hi Raja-Mytestdata,

    use the code mentioned below.

     static void Main(string[] args)
            {
                CreateSpreadsheetWorkbook(@"C:\Users\v-padee\Desktop\exxml.xlsx");
                Console.Write("File created Successfully");
            }
            public static void CreateSpreadsheetWorkbook(string filepath)
            {
                // Create a spreadsheet document by supplying the filepath.
                // By default, AutoSave = true, Editable = true, and Type = xlsx.
                SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create(filepath, SpreadsheetDocumentType.Workbook);
    
                // Add a WorkbookPart to the document.
                WorkbookPart workbookpart = spreadsheetDocument.AddWorkbookPart();
                workbookpart.Workbook = new Workbook();
    
                // Add a WorksheetPart to the WorkbookPart.
                WorksheetPart worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
                worksheetPart.Worksheet = new Worksheet(new SheetData());
    
                // Add Sheets to the Workbook.
                Sheets sheets = spreadsheetDocument.WorkbookPart.Workbook.
                    AppendChild<Sheets>(new Sheets());
    
                // Append a new worksheet and associate it with the workbook.
                Sheet sheet = new Sheet()
                {
                    Id = spreadsheetDocument.WorkbookPart.
                    GetIdOfPart(worksheetPart),
                    SheetId = 1,
                    Name = "mySheet"
                };
                sheets.Append(sheet);
    
                workbookpart.Workbook.Save();
    
                // Close the document.
                spreadsheetDocument.Close();
            }
    
    

    Reference:

    How to: Create a spreadsheet document by providing a file name (Open XML SDK)

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, November 17, 2016 4:13 AM
    Moderator