با استفاده از کتابخانه Java DOC را بسازید

کتابخانه قدرتمند Java ما به توسعه دهندگان اجازه می دهد تا به صورت برنامه نویسی DOC را تنها در چند مرحله ایجاد کنند

توسعه دهندگان Java می توانند به راحتی DOC را تنها با استفاده از API محصول قدرتمند ما ایجاد کنند. این بدان معناست که راه حل ما هر آنچه را که برای ایجاد DOC در Java نیاز دارند در اختیار برنامه نویسان قرار می دهد.

مشاهده قطعه کد

DOC را در Java به صورت برنامه نویسی کنید

توسعه دهندگان کتابخانه Java ما می توانند به راحتی DOC را از ابتدا بسازند. برای انجام این کار، توسعه دهندگان Java باید فقط چند مرحله را انجام دهند:

  1. نام فایل را اضافه کنید
  2. شروع به ایجاد یک سند DOC با استفاده از Java
  3. فایل خروجی DOC را ذخیره کنید

شایان ذکر است که یک سند خالی از نظر فنی باید شامل یک پاراگراف باشد، بنابراین وقتی یک سند DOC را به صورت برنامه‌نویسی ایجاد می‌کنید، دقیقاً همان ساختار سند اولیه را دریافت خواهید کرد.

توجه داشته باشید که می‌توانید فوراً محتوا را به فایل جدید DOC کنید. بنابراین، شما نه تنها یک سند خالی، بلکه یک سند حاوی محتوای لازم را دریافت خواهید کرد. برای اطلاعات بیشتر در مورد نحوه ویرایش یک سند، به صفحه ویرایش مراجعه کنید.

DOC در Java

این کتابخانه Java به شما امکان می دهد اسناد DOC را به صورت برنامه نویسی ایجاد کنید. عملکرد قدرتمند ما را امتحان کنید و نحوه ایجاد DOC را با استفاده از مثال زیر در برخی از قالب‌ها ببینید:

با استفاده از Java یک DOC جدید بسازید
قالب مورد نظر را از لیست انتخاب کنید
کد را اجرا کنید
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"); // اگر NextSibling تهی باشد، به احتمال زیاد این آخرین Run در پاراگراف است. 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"); // اگر NextSibling تهی باشد، به احتمال زیاد این آخرین Run در پاراگراف است. 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"); // اگر NextSibling تهی باشد، به احتمال زیاد این آخرین Run در پاراگراف است. 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"); // اگر NextSibling تهی باشد، به احتمال زیاد این آخرین Run در پاراگراف است. 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");
// اگر NextSibling تهی باشد، به احتمال زیاد این آخرین Run در پاراگراف است.
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"); // اگر NextSibling تهی باشد، به احتمال زیاد این آخرین Run در پاراگراف است. 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"); // اگر NextSibling تهی باشد، به احتمال زیاد این آخرین Run در پاراگراف است. 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"); // اگر NextSibling تهی باشد، به احتمال زیاد این آخرین Run در پاراگراف است. 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"); // اگر NextSibling تهی باشد، به احتمال زیاد این آخرین Run در پاراگراف است. 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);
کد را اجرا کنید

نحوه ساخت DOC در Java

  1. Aspose.Words for Java نصب کنید
  2. یک مرجع کتابخانه (وارد کردن کتابخانه) به پروژه Java خود اضافه کنید
  3. یک سند DOC جدید ایجاد کنید
  4. با ارسال نام فایل، روش "save()" را فراخوانی کنید
  5. نتیجه را در یک فایل جداگانه دریافت کنید

کتابخانه Java برای ایجاد DOC

ما بسته های Java خود را در مخازن Maven میزبانی می کنیم. 'Aspose.Words برای Java' یک JAR رایج حاوی کد بایت است. لطفاً دستورالعمل های گام به گام نحوه نصب آن را در محیط توسعه دهنده جاوا خود دنبال کنید.

سیستم مورد نیاز

Java SE 7 و Java پشتیبانی می شوند. ما همچنین یک بسته جداگانه برای Java SE 6 در صورتی که شما مجبور به استفاده از این JRE قدیمی هستید.

Java ما چند پلتفرم است و بر روی تمام سیستم عامل های با JVM اجرا می شود، از جمله Microsoft Windows، Linux، macOS، Android و iOS.

برای اطلاع از وابستگی های بسته اختیاری، مانند JogAmp JOGL، موتور قلم Harfbuzz Java Advanced Imaging JAI، لطفاً به مستندات محصول مراجعه کنید.

سایر فرمت های فایل پشتیبانی شده

می توانید اسناد را در فرمت های فایل دیگر ایجاد کنید:

5%

در به‌روزرسانی‌های محصول Aspose مشترک شوید

خبرنامه ها و پیشنهادات ماهانه را مستقیماً به صندوق پستی خود تحویل بگیرید.

© Aspose Pty Ltd 2001-2024. تمامی حقوق محفوظ است.