Click here to Skip to main content
15,896,348 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi,
I'm trying to write a simple hello world application in C++/CLI to create a Word document which I've posted below
int main(array<String^>^ args)
{
    String^ documentFileName=L"Hello4.docx";
    WordprocessingDocument ^myDoc = WordprocessingDocument::Create(documentFileName, WordprocessingDocumentType::Document);
    MainDocumentPart^ mainPart = myDoc->AddMainDocumentPart();
    mainPart->Document  = gcnew Document();
    Body^ body = gcnew Body();
    Paragraph^ paragraph = gcnew Paragraph();
    Run^ run_paragraph = gcnew Run();
    DocumentFormat::OpenXml::Wordprocessing::Text^ text_paragraph = gcnew DocumentFormat::OpenXml::Wordprocessing::Text(L"Hello ..asdks");
    run_paragraph->Append(text_paragraph);
    paragraph->Append(run_paragraph);
    body->Append(paragraph);
    mainPart->Document->Append(body);
    mainPart->Document->Save();
    return 0;
}


The above program creates hello.docx file but I'm not able to open the created file as it is corrupt.Can you please help me with this
Thanks in advance
Posted
Updated 5-May-11 23:20pm
v3
Comments
Sergey Alexandrovich Kryukov 6-May-11 2:57am    
It needs exact error diagnostics. What's the error?
--SA
Member 7900954 6-May-11 4:14am    
@SAKryukov - I'm not getting any error in that line,But if I run the above code the Hello.docx file is being created but im not able to open the file.it says "the file is corrupt and it cannot be opened"
Sergey Alexandrovich Kryukov 6-May-11 11:17am    
And the file is opened OK with Word? Can be just a version issue...
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900