Java pangembang bisa gampang nggawe DOC mung nggunakake API produk sing kuat. Tegese solusi kita bakal nyedhiyakake programer kabeh sing dibutuhake kanggo nggawe DOC ing Java.
Kanthi pangembang perpustakaan Java kita bisa nggawe DOC saka awal. Kanggo nindakake iki, pangembang Java mung kudu nindakake sawetara langkah:
Wigati dicathet yen dokumen kosong sacara teknis mesthine ngemot siji paragraf, dadi nalika sampeyan nggawe DOC dokumen kanthi program, sampeyan bakal entuk struktur dokumen dhasar kasebut.
Elinga yen sampeyan bisa langsung nambah konten menyang DOC file sing mentas digawe. Mangkono, sampeyan bakal entuk ora mung dokumen kosong, nanging dokumen sing ngemot konten sing dibutuhake. Kanggo informasi luwih lengkap babagan cara ngowahi dokumen, deleng kaca Editing.
Pustaka Java iki ngidini sampeyan nggawe DOC dokumen kanthi program. Coba fungsi sing kuat lan deleng carane nggawe DOC ing sawetara format nggunakake conto ing ngisor iki:
// Repository path: https://releases.aspose.com/java/repo/
// Maven, where 'ver' - Aspose.Words version number, for example, 24.4.
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
<version>ver</version>
<classifier>jdk17</classifier>
</dependency>
Nyalin
// Repository path: https://releases.aspose.com/java/repo/
// Gradle, where 'ver' - Aspose.Words version number, for example, 24.4.
compile(group: 'com.aspose', name: 'aspose-words', version: 'ver', classifier: 'jdk17')
Nyalin
// Repository path: https://releases.aspose.com/java/repo/
// Ivy, where 'ver' - Aspose.Words version number, for example, 24.4.
<dependency org="com.aspose" name="aspose-words" rev="ver">
<artifact name="aspose-words" m:classifier="jdk17" ext="jar"/>
</dependency>
Nyalin
// Repository path: https://releases.aspose.com/java/repo/
// Sbt, where 'ver' - Aspose.Words version number, for example, 24.4.
libraryDependencies += "com.aspose" % "aspose-words" % "ver"
Nyalin
import com.aspose.words.*;
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Font font = builder.getFont();
font.setName("Courier New");
font.setColor(Color.BLUE);
font.setSize(36);
font.setHighlightColor(Color.YELLOW);
builder.write("Morbi enim nunc faucibus a.");
doc.save("Output.doc");
import com.aspose.words.*;
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. ");
Run secondRun = new Run(doc, "Morbi enim nunc faucibus a.");
doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun);
doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun);
builder.moveTo(secondRun);
builder.startBookmark("Aspose bookmark");
// Yen NextSibling null, banjur paling kamungkinan iki Run pungkasan ing Paragraf.
if (secondRun.getNextSibling() != null)
builder.moveTo(secondRun.getNextSibling());
else
builder.moveTo(secondRun.getParentParagraph());
builder.endBookmark("Aspose bookmark");
doc.save("Output.doc");
import com.aspose.words.*;
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. ");
Run secondRun = new Run(doc, "Morbi enim nunc faucibus a.");
doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun);
doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun);
builder.moveTo(secondRun);
builder.startBookmark("Aspose bookmark");
// Yen NextSibling null, banjur paling kamungkinan iki Run pungkasan ing Paragraf.
if (secondRun.getNextSibling() != null)
builder.moveTo(secondRun.getNextSibling());
else
builder.moveTo(secondRun.getParentParagraph());
builder.endBookmark("Aspose bookmark");
PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.getOutlineOptions().getBookmarksOutlineLevels().add("Aspose bookmark", 1);
doc.save("Output.doc", saveOptions);
import com.aspose.words.*;
Document doc = new Document();
Run run = new Run(doc, "Proin eros metus, sagittis sed.");
Paragraph para = doc.getFirstSection().getBody().getFirstParagraph();
para.appendChild(run);
Comment comment = new Comment(doc);
comment.setAuthor("John Doe");
comment.setInitial("JD");
comment.setDateTime(new Date());
comment.setText("Quisque fringilla leo.");
CommentRangeStart commentRangeStart = new CommentRangeStart(doc, comment.getId());
CommentRangeEnd commentRangeEnd = new CommentRangeEnd(doc, comment.getId());
run.getParentNode().insertBefore(commentRangeStart, run);
run.getParentNode().insertAfter(commentRangeEnd, run);
commentRangeEnd.getParentNode().insertAfter(comment, commentRangeEnd);
comment.addReply("Jane Doe", "JD", new Date(), "Pellentesque vel sapien justo.");
doc.save("Output.doc");
import com.aspose.words.*;
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. ");
Run secondRun = new Run(doc, "Morbi enim nunc faucibus a.");
doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun);
doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun);
builder.moveTo(secondRun);
builder.startBookmark("Aspose bookmark");
// Yen NextSibling null, banjur paling kamungkinan iki Run pungkasan ing Paragraf.
if (secondRun.getNextSibling() != null)
builder.moveTo(secondRun.getNextSibling());
else
builder.moveTo(secondRun.getParentParagraph());
builder.endBookmark("Aspose bookmark");
doc.save("Output.doc");
import com.aspose.words.*;
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. ");
Run secondRun = new Run(doc, "Morbi enim nunc faucibus a.");
doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun);
doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun);
builder.moveTo(secondRun);
builder.startBookmark("Aspose bookmark");
// Yen NextSibling null, banjur paling kamungkinan iki Run pungkasan ing Paragraf.
if (secondRun.getNextSibling() != null)
builder.moveTo(secondRun.getNextSibling());
else
builder.moveTo(secondRun.getParentParagraph());
builder.endBookmark("Aspose bookmark");
PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.getOutlineOptions().getBookmarksOutlineLevels().add("Aspose bookmark", 1);
doc.save("Output.doc", saveOptions);
import com.aspose.words.*;
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. ");
Run secondRun = new Run(doc, "Morbi enim nunc faucibus a.");
doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun);
doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun);
builder.moveTo(secondRun);
builder.startBookmark("Aspose bookmark");
// Yen NextSibling null, banjur paling kamungkinan iki Run pungkasan ing Paragraf.
if (secondRun.getNextSibling() != null)
builder.moveTo(secondRun.getNextSibling());
else
builder.moveTo(secondRun.getParentParagraph());
builder.endBookmark("Aspose bookmark");
doc.save("Output.doc");
import com.aspose.words.*;
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. ");
Run secondRun = new Run(doc, "Morbi enim nunc faucibus a.");
doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun);
doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun);
builder.moveTo(secondRun);
builder.startBookmark("Aspose bookmark");
// Yen NextSibling null, banjur paling kamungkinan iki Run pungkasan ing Paragraf.
if (secondRun.getNextSibling() != null)
builder.moveTo(secondRun.getNextSibling());
else
builder.moveTo(secondRun.getParentParagraph());
builder.endBookmark("Aspose bookmark");
doc.save("Output.doc");
import com.aspose.words.*;
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. ");
Run secondRun = new Run(doc, "Morbi enim nunc faucibus a.");
doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun);
doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun);
builder.moveTo(secondRun);
builder.startBookmark("Aspose bookmark");
// Yen NextSibling null, banjur paling kamungkinan iki Run pungkasan ing Paragraf.
if (secondRun.getNextSibling() != null)
builder.moveTo(secondRun.getNextSibling());
else
builder.moveTo(secondRun.getParentParagraph());
builder.endBookmark("Aspose bookmark");
PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.getOutlineOptions().getBookmarksOutlineLevels().add("Aspose bookmark", 1);
doc.save("Output.doc", saveOptions);
import com.aspose.words.*;
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.PIE, 432, 252);
Chart chart = shape.getChart();
chart.getTitle().setText("Demo Chart");
chart.getSeries().clear();
chart.getSeries().add("Series 1",
new String[] { "Category1", "Category2", "Category3" },
new double[] { 2.7, 3.2, 0.8 });
doc.save("Output.doc");
import com.aspose.words.*;
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. ");
Run secondRun = new Run(doc, "Morbi enim nunc faucibus a.");
doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun);
doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun);
builder.moveTo(secondRun);
builder.startBookmark("Aspose bookmark");
// Yen NextSibling null, banjur paling kamungkinan iki Run pungkasan ing Paragraf.
if (secondRun.getNextSibling() != null)
builder.moveTo(secondRun.getNextSibling());
else
builder.moveTo(secondRun.getParentParagraph());
builder.endBookmark("Aspose bookmark");
doc.save("Output.doc");
import com.aspose.words.*;
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. ");
Run secondRun = new Run(doc, "Morbi enim nunc faucibus a.");
doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun);
doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun);
builder.moveTo(secondRun);
builder.startBookmark("Aspose bookmark");
// Yen NextSibling null, banjur paling kamungkinan iki Run pungkasan ing Paragraf.
if (secondRun.getNextSibling() != null)
builder.moveTo(secondRun.getNextSibling());
else
builder.moveTo(secondRun.getParentParagraph());
builder.endBookmark("Aspose bookmark");
PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.getOutlineOptions().getBookmarksOutlineLevels().add("Aspose bookmark", 1);
doc.save("Output.doc", saveOptions);
Kita dadi tuan rumah paket Java ing repositori Maven. 'Aspose.Words kanggo Java' JAR umum sing ngemot kode byte. Tututi pandhuan langkah demi langkah babagan carane nginstal ing lingkungan pangembang Java.
Java SE 7 Java sing luwih anyar didhukung. Kita uga nyedhiyakake paket kapisah kanggo Java SE 6 yen sampeyan wajib nggunakake JRE ketinggalan jaman iki.
Java kita lintas platform lan mbukak kabeh sistem operasi kanthi JVM, kalebu Microsoft Windows, Linux, macOS, Android lan iOS.
Kanggo informasi babagan katergantungan paket opsional, kayata JogAmp JOGL, Harfbuzz font Java Advanced Imaging JAI, waca Dokumentasi Produk.