none
DocumentFormat::OpenXml for C++/CLR RRS feed

  • Question

  • Can the Open XML SDK be used with C++ / CLR?

    The sample code is in C#, but it looks like it could be used with C++/CLR.

    compile error C3767, however, when i try the following code:

    using namespace System; using namespace System::ComponentModel; using namespace System::Windows::Forms; using namespace System::IO; using namespace System::Text; using namespace System::Collections::Generic; //test excel #using <WindowsBase.dll> using namespace System::IO::Packaging; using namespace DocumentFormat::OpenXml; using namespace DocumentFormat::OpenXml::Packaging; using namespace DocumentFormat::OpenXml::Spreadsheet; DocumentFormat::OpenXml::Packaging::SpreadsheetDocument doc;

    I did add a reference to DocumentOpen.Xml

    Thanks,


    • Moved by Jesse Jiang Friday, June 8, 2012 4:20 AM (From:Visual C++ General)
    Thursday, June 7, 2012 10:02 PM

Answers

  • Hi  kaymcc,

    Thanks for posting in the MSDN Forum.

    This is a sample. I hope you love it.

    // OpenXmlC.cpp : main project file.
    
    #include "stdafx.h"
    
    using namespace System;
    using namespace System::Collections::Generic;
    using namespace System::Linq;  
    using namespace DocumentFormat::OpenXml::Packaging;
    using namespace DocumentFormat::OpenXml::Spreadsheet;
    
    
    int main(array<System::String ^> ^args)
    {
    	SpreadsheetDocument^ ssd = SpreadsheetDocument::Open("C:\\******\\ExcelTemplate11.xlsx",false);
    	WorkbookPart^ wbp = ssd->WorkbookPart;
    	Workbook^ wb = wbp->Workbook;
    	Sheet^ sheet = Enumerable::FirstOrDefault(wb->Descendants<Sheet^>());
    
    	Console::WriteLine(sheet->Name);
    	Console::ReadKey();
    	return 0;
    }

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us


    Friday, June 8, 2012 7:14 AM
    Moderator

All replies

  • Hi ,

     

    I think your issue should be raised in the OpenXML forum. I believe they will know more information of this issue than us, and I will move this one to that forum.

     

    Thanks for your understanding,

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Friday, June 8, 2012 4:18 AM
  • Hi  kaymcc,

    Thanks for posting in the MSDN Forum.

    This is a sample. I hope you love it.

    // OpenXmlC.cpp : main project file.
    
    #include "stdafx.h"
    
    using namespace System;
    using namespace System::Collections::Generic;
    using namespace System::Linq;  
    using namespace DocumentFormat::OpenXml::Packaging;
    using namespace DocumentFormat::OpenXml::Spreadsheet;
    
    
    int main(array<System::String ^> ^args)
    {
    	SpreadsheetDocument^ ssd = SpreadsheetDocument::Open("C:\\******\\ExcelTemplate11.xlsx",false);
    	WorkbookPart^ wbp = ssd->WorkbookPart;
    	Workbook^ wb = wbp->Workbook;
    	Sheet^ sheet = Enumerable::FirstOrDefault(wb->Descendants<Sheet^>());
    
    	Console::WriteLine(sheet->Name);
    	Console::ReadKey();
    	return 0;
    }

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us


    Friday, June 8, 2012 7:14 AM
    Moderator
  • Its perfect, Tom.

    Exactly what I needed, thanks so much.

    :)

    Friday, June 8, 2012 3:04 PM