Utwórz DOCX za pomocą Java biblioteki

Nasza potężna Java biblioteka umożliwia programistom programowe tworzenie DOCX w zaledwie kilku krokach

Programiści Java mogą łatwo tworzyć DOCX, korzystając tylko z naszego zaawansowanego interfejsu API produktu. Oznacza to, że nasze rozwiązanie zapewni programistom wszystko, czego potrzebują do tworzenia DOCX w Java.

Zobacz fragment kodu

Twórz program DOCX w Java

Dzięki naszej Java bibliotece programiści mogą łatwo tworzyć DOCX od podstaw. Aby to zrobić, programiści Java muszą wykonać tylko kilka kroków:

  1. Dodaj nazwę pliku
  2. Zacznij tworzyć DOCX dokument za pomocą Java
  3. Zapisz wyjściowy DOCX plik

Warto zauważyć, że technicznie pusty dokument powinien zawierać jeden akapit, więc gdy programowo utworzysz DOCX dokument, otrzymasz dokładnie taką podstawową strukturę dokumentu.

Pamiętaj, że możesz natychmiast dodać zawartość do nowo utworzonego DOCX pliku. W ten sposób otrzymasz nie tylko pusty dokument, ale dokument zawierający niezbędną treść. Aby uzyskać więcej informacji na temat edycji dokumentu, zobacz stronę Edycja.

Twórz DOCX w Java

Ta Java biblioteka umożliwia programowe tworzenie DOCX dokumentów. Wypróbuj naszą zaawansowaną funkcjonalność i zobacz, jak tworzyć DOCX w niektórych formatach, korzystając z następującego przykładu:

Utwórz nowy DOCX za pomocą Java
Wybierz format docelowy z listy
Uruchom kod
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.docx");
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"); // Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie. if (secondRun.getNextSibling() != null) builder.moveTo(secondRun.getNextSibling()); else builder.moveTo(secondRun.getParentParagraph()); builder.endBookmark("Aspose bookmark"); doc.save("Output.docx"); 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"); // Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie. 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.docx", 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.docx");
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"); // Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie. if (secondRun.getNextSibling() != null) builder.moveTo(secondRun.getNextSibling()); else builder.moveTo(secondRun.getParentParagraph()); builder.endBookmark("Aspose bookmark"); doc.save("Output.docx"); 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"); // Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie. 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.docx", 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");
// Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie.
if (secondRun.getNextSibling() != null)
    builder.moveTo(secondRun.getNextSibling());
else
    builder.moveTo(secondRun.getParentParagraph());
builder.endBookmark("Aspose bookmark");

doc.save("Output.docx");
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"); // Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie. if (secondRun.getNextSibling() != null) builder.moveTo(secondRun.getNextSibling()); else builder.moveTo(secondRun.getParentParagraph()); builder.endBookmark("Aspose bookmark"); doc.save("Output.docx"); 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"); // Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie. 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.docx", 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.docx");
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"); // Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie. if (secondRun.getNextSibling() != null) builder.moveTo(secondRun.getNextSibling()); else builder.moveTo(secondRun.getParentParagraph()); builder.endBookmark("Aspose bookmark"); doc.save("Output.docx"); 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"); // Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie. 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.docx", saveOptions);
Uruchom kod

Jak zrobić DOCX w Java

  1. Zainstaluj Aspose.Words for Java
  2. Dodaj odniesienie do biblioteki (zaimportuj bibliotekę) do swojego Java projektu
  3. Utwórz nowy DOCX dokument
  4. Wywołaj metodę "save()", przekazując nazwę pliku
  5. Uzyskaj wynik jako osobny plik

Java biblioteka do utworzenia DOCX

Nasze Java hostujemy w repozytoriach Maven. 'Aspose.Words for Java' to wspólny JAR zawierający kod bajtowy. Postępuj zgodnie z instrukcjami krok po kroku, jak zainstalować go w swoim środowisku programisty Java.

wymagania systemowe

Obsługiwana jest Java SE 7 i nowsze Java Udostępniamy również osobny pakiet dla Java SE 6 na wypadek, gdybyś musiał używać tego przestarzałego JRE.

Nasz Java jest wieloplatformowy i działa na wszystkich systemach operacyjnych z JVM, w tym Microsoft Windows, Linux, macOS, Android i iOS.

Aby uzyskać informacje na temat dodatkowych zależności między pakietami, takich jak JogAmp JOGL, Harfbuzz silnika czcionki, Java Zaawansowane obrazowanie JAI, zapoznaj się z dokumentacją produktu.

Inne obsługiwane formaty plików

Możesz tworzyć dokumenty w innych formatach plików:

5%

Subskrybuj aktualizacje produktów Aspose

Otrzymuj comiesięczne biuletyny i oferty dostarczane bezpośrednio do Twojej skrzynki pocztowej.

© Aspose Pty Ltd 2001-2024. Wszelkie prawa zastrzeżone.