Belge Oluşturma veya Yükleme

Aspose.Words ile gerçekleştirmek istediğiniz hemen hemen her görev, bir belgenin yüklenmesini içerir. Document sınıfı belleğe yüklenen bir belgeyi temsil eder. Belge, boş bir belge oluşturmanıza veya bir dosyadan veya akıştan yüklemenize izin veren aşırı yüklenmiş birkaç kurucuya sahiptir. Belge, Aspose.Words tarafından desteklenen herhangi bir yükleme biçiminde yüklenebilir. Desteklenen tüm yükleme biçimlerinin listesi için LoadFormat numaralandırmasına bakın.

Yeni Bir Belge Oluştur

Yeni bir boş belge oluşturmak için Document yapıcısını parametresiz olarak çağıracağız. Programlı olarak bir belge oluşturmak istiyorsanız, en basit yol belge içeriği eklemek için DocumentBuilder sınıfını kullanmaktır.

Aşağıdaki kod örneği, belge oluşturucuyu kullanarak bir belgenin nasıl oluşturulacağını gösterir:

For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C
// The path to the documents directory.
System::String outputDataDir = GetOutputDataDir_LoadingAndSaving();
// Initialize a Document.
System::SharedPtr<Document> doc = System::MakeObject<Document>();
// Use a document builder to add content to the document.
System::SharedPtr<DocumentBuilder> builder = System::MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Hello World!");
System::String outputPath = outputDataDir + u"CreateDocument.docx";
// Save the document to disk.
doc->Save(outputPath);

Belge Yükleme

Varolan bir belgeyi LoadFormat biçimlerinden herhangi birine yüklemek için dosya adını veya akışı Belge oluşturucularından birine geçirin. Yüklenen belgenin biçimi, uzantısı tarafından otomatik olarak belirlenir.

Bir Dosyadan Yükleme

Varolan bir belgeyi bir dosyadan açmak için Belge oluşturucusuna bir dosya adını dize olarak iletin.

Aşağıdaki kod örneği, bir dosyadan bir belgenin nasıl açılacağını gösterir:

For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C
// The path to the documents directories.
System::String inputDataDir = GetInputDataDir_LoadingAndSaving();
System::String outputDataDir = GetOutputDataDir_LoadingAndSaving();
// Load the document from the absolute path on disk.
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"Document.docx");

Bu örneğin şablon dosyasını şu adresten indirebilirsiniz: Aspose.Words GitHub.

Bir Akıştan Yükleme

Bir akıştan belge açmak için, belgeyi içeren bir akış nesnesini Belge oluşturucusuna geçirmeniz yeterlidir.

Aşağıdaki kod örneği, bir akıştan bir belgenin nasıl açılacağını gösterir:

For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C
// The path to the documents directories.
System::String inputDataDir = GetInputDataDir_LoadingAndSaving();
System::String outputDataDir = GetOutputDataDir_LoadingAndSaving();
// Open the stream. Read only access is enough for Aspose.Words to load a document.
System::SharedPtr<System::IO::Stream> stream = System::IO::File::OpenRead(inputDataDir + u"Document.docx");
// Load the entire document into memory.
System::SharedPtr<Document> doc = System::MakeObject<Document>(stream);
// You can close the stream now, it is no longer needed because the document is in memory.
stream->Close();