TOP Format XML .NET

Open XML は ISO/IEC 29500 で標準化されているファイル フォーマット

ECMA International Standard

ECMA-376Office Open XML File Formats

class ref

namespaceclassdll
DocumentFormat.OpenXml.PackagingWordprocessingDocumentDocumentFormat.OpenXml.dll
DocumentFormat.OpenXml.PackagingMainDocumentPartDocumentFormat.OpenXml.dll
DocumentFormat.OpenXml.PackagingImagePartDocumentFormat.OpenXml.dll
DocumentFormat.OpenXml.WordprocessingDocumentDocumentFormat.OpenXml.dll
DocumentFormat.OpenXml.WordprocessingBodyDocumentFormat.OpenXml.dll
DocumentFormat.OpenXml.WordprocessingParagraphDocumentFormat.OpenXml.dll
DocumentFormat.OpenXml.WordprocessingRunDocumentFormat.OpenXml.dll
DocumentFormat.OpenXml.WordprocessingTextDocumentFormat.OpenXml.dll
DocumentFormat.OpenXml.WordprocessingRunPropertiesDocumentFormat.OpenXml.dll
DocumentFormat.OpenXml.WordprocessingRunFontsDocumentFormat.OpenXml.dll
DocumentFormat.OpenXmlOpenXmlElementListDocumentFormat.OpenXml.dll
DocumentFormat.OpenXmlOpenXmlElementDocumentFormat.OpenXml.dll
DocumentFormat.OpenXmlOpenXmlLeafElementDocumentFormat.OpenXml.dll
DocumentFormat.OpenXmlOpenXmlContextDocumentFormat.OpenXml.dll
DocumentFormat.OpenXml.Drawing.WordprocessingExtentDocumentFormat.OpenXml.dll
DocumentFormat.OpenXml.Drawing.WordprocessingEffectExtentDocumentFormat.OpenXml.dll
DocumentFormat.OpenXml.Drawing.WordprocessingDocPropertiesDocumentFormat.OpenXml.dll
DocumentFormat.OpenXml.DrawingGraphicFrameLocksDocumentFormat.OpenXml.dll
DocumentFormat.OpenXml.Drawing.PicturesNonVisualDrawingPropertiesDocumentFormat.OpenXml.dll

reference

CSC++
REFERENCES+= /r:"C:\Program Files\Open XML SDK\V2.0\lib\DocumentFormat.OpenXml.dll"
REFERENCES+= /r:"c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\WindowsBase.dll"

tool

unzip:
    if [ ! -e DOCX ] ; then mkdir DOCX ; fi
    cd DOCX; unzip ../test.docx

sdktool:
    /cygdrive/c/Program\ Files/Open\ XML\ SDK/V2.0/tool/OpenXmlSdkTool.exe &

Word Viewer の入手方法

最新の Word Viewer の入手方法
Word/Excel/PowerPoint 用 Microsoft Office 互換機能パック ... Microsoft Office 2007 の Word 、Excel、および PowerPoint で導入され、Office 2010 でも引き続き同様のアプリケーションで採用されている Open XML ファイル形式の文書、ブック、およびプレゼンテーションを開いたり、編集、保存を行うことができます。

C++ HelloWorld

hello.cpp

#using <mscorlib.dll>
#using <System.dll>
#using <DocumentFormat.OpenXml.dll>
#using <WindowsBase.dll> // for ZIP files - System.IO.Packaging.Package class
using namespace System;
//using namespace DocumentFormat::OpenXml;
//using namespace DocumentFormat::OpenXml::Packaging;
//using namespace DocumentFormat::OpenXml::Wordprocessing;;
//using System.IO.Packaging;

int main(array<System::String ^> ^args){
	DocumentFormat::OpenXml::Packaging::WordprocessingDocument^ package = 
		DocumentFormat::OpenXml::Packaging::WordprocessingDocument::Create( 
			"test.docx", 
			DocumentFormat::OpenXml::WordprocessingDocumentType::Document);

	DocumentFormat::OpenXml::Packaging::MainDocumentPart^ mainDocumentPart1 = 
		package->AddMainDocumentPart();

	mainDocumentPart1->Document = gcnew DocumentFormat::OpenXml::Wordprocessing::Document();
	DocumentFormat::OpenXml::Wordprocessing::Text^ textFirstLine = gcnew DocumentFormat::OpenXml::Wordprocessing::Text("Hello World");

	DocumentFormat::OpenXml::Wordprocessing::Run^ run = gcnew DocumentFormat::OpenXml::Wordprocessing::Run();
	run->AppendChild<DocumentFormat::OpenXml::Wordprocessing::Text^>(textFirstLine);
	DocumentFormat::OpenXml::Wordprocessing::Paragraph^ para = gcnew DocumentFormat::OpenXml::Wordprocessing::Paragraph();
	para->AppendChild<DocumentFormat::OpenXml::Wordprocessing::Run^>(run);
	DocumentFormat::OpenXml::Wordprocessing::Body^ body = gcnew DocumentFormat::OpenXml::Wordprocessing::Body();
	body->AppendChild<DocumentFormat::OpenXml::Wordprocessing::Paragraph^>(para);
	mainDocumentPart1->Document->AppendChild<DocumentFormat::OpenXml::Wordprocessing::Body^>(body);

	mainDocumentPart1->Document->Save();
	package->Close();

	return EXIT_SUCCESS;
}

makefile

.PHONY: all test
.SUFFIXES: .exe .obj
TARGET=hello
all: $(TARGET).exe
clear_screen:
	clear
CLRIMAGETYPE=pure
LOPT=-clrimagetype:$(CLRIMAGETYPE)
COPT=-c -Wall -Od -clr:$(CLRIMAGETYPE)
OBJS=$(TARGET).obj
$(TARGET).obj: $(TARGET).cpp
$(TARGET).exe: $(OBJS)
	link $(OBJS) /out:$@ $(LOPT) 

AI_PATH=/AI"c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0"
AI_PATH+= /AI"C:\Program Files\Open XML SDK\V2.0\lib"

.cpp.obj:
	cl $(COPT) $< $(AI_PATH)
	@echo
test: test.docx
	cygstart $<	
test.docx: $(TARGET).exe
	if [ -e $@ ]; then rm $@ ; fi
	./$(TARGET).exe 
unzip:
	if [ ! -e DOCX ] ; then mkdir DOCX ; fi
	cd DOCX; unzip ../test.docx
sdktool:
	/cygdrive/c/Program\ Files/Open\ XML\ SDK/V2.0/tool/OpenXmlSdkTool.exe &

Error Messages

Cannot insert the OpenXmlElement "newChild" because it is part of a tree

This means inserting an element that belongs to another part. Do clone the element and insert it.
(some cast) element->CloneNode(true);

管理人/副管理人のみ編集できます