Bir Belge Oluşturun veya Yükleyin

Çok az görev Aspose.Words ile gerçekleştirmek istediğiniz bir belge yüklemenizi içerir. Document sınıfı bellekte yüklenen bir belgeyi temsil eder. Belge birkaç aşırı yüklenmiş oluşturucuya sahiptir ve bu da boş bir belge oluşturmanıza veya bir dosyadan veya akıştan yüklemenize olanak tanır. Belge, Aspose.Words tarafından desteklenen herhangi bir yükleme formatında yüklenebilir. Tüm desteklenen yükleme formatlarının listesi için LoadFormat numaralandırmasına bakın.

Yeni Belge Oluştur

Yeni boş bir belge oluşturmak için parametre içermeyen Document oluşturucusunu çağırabiliriz. Belgesi programatik olarak oluşturmak istiyorsanız, bunu yapmak için en basit yol DocumentBuilder sınıfını kullanarak belgenin içeriğini eklemektir.

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

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CreateDocument.class);
// Load the document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.write("hello world");
doc.save(dataDir + "output.docx");

Bir belge yükle

Mevcut bir belgeyi herhangi bir LoadFormat biçimde yüklemek için, dosya adını veya akışını bir Belge oluşturucusuna geçirin. Yüklenen belgenin biçimi uzantısına göre otomatik olarak belirlenir.

Bir Dosyadan Yükle

Bir dosya adının bir dizge olarak Belge oluşturucusuna geçirin, mevcut bir belgeyi bir dosyadan açmak için.

Aşağıdaki kod örneği bir dosyadan bir belgeyi nasıl açacağınızı gösterir:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java
// For complete examples and data files, please go to
// https://github.com/aspose-words/Aspose.Words-for-Java
String fileName = "Document.docx";
// Load the document from the absolute path on disk.
Document doc = new Document(dataDir + fileName);

Bu örnek için şablon dosyasını Aspose.Words GitHub‘dan indirip kaydedebilirsiniz.

Bir Akıdan Yükle

Bir belgeyi bir akıştan açmak için belgeyi içeren bir akış nesnesini Belge oluşturucusuna geçirin basitçe.

Aşağıdaki kod örneği bir akıştan belgeyi nasıl açacağınızı gösterir:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java
// For complete examples and data files, please go to
// https://github.com/aspose-words/Aspose.Words-for-Java
String filename = "Document.docx";
// Open the stream. Read only access is enough for Aspose.Words to load a
// document.
InputStream in = new FileInputStream(dataDir + filename);
// Load the entire document into memory.
Document doc = new Document(in);
System.out.println("Document opened. Total pages are " + doc.getPageCount());
// You can close the stream now, it is no longer needed because the document is
// in memory.
in.close();