Gawe docx nggunakake Mail merge ing Java

Pustaka Java kacepetan dhuwur kanggo nglakokake operasi Mail merge kanggo cithakan docx lan data saka sumber data khusus

Solusi kita nyedhiyakake API independen platform sing kuat. Gunakake API dokumen Mail merge kanggo ngembangake piranti lunak tingkat dhuwur kanggo platform Java. Iki minangka solusi piranti lunak sing kuat kanggo nggabungake template ing Word format lan PDF lan data saka sumber data khusus lan luwih ngekspor asil menyang DOCX, PDF, HTML lan format populer liyane nggunakake Java.

Ndeleng potongan kode

Mail merge Word file lan Excel data ing Java

Pustaka Fast Java kanggo nglakokake gabungan Mail karo Excel data.

Mail Merge SDK ngidini sampeyan ngisi cithakan Word nganggo data saka Excel lembar. Adhedhasar Mail Merge API, sampeyan bisa nggawe solusi piranti lunak dhewe nggunakake Java, sing ngidini sampeyan ngotomatisasi email saka Excel lan ngasilake laporan nganggo Excel data.

Kanggo Mail merge saka Excel menyang Word, cukup nindakake operasi Mail merge ing Java lan ekspor asil menyang Word format sing didhukung.

Mail merge saka Excel menyang Word nggunakake Java

Kanthi Mail merge API sing kuat, sampeyan bisa nggawe dokumen pribadi ing Java mung nggunakake cithakan Word Merge lan data saka Excel.

Cara nggunakake Mail merge saka Excel:

  • Gawe template Word kanthi kolom gabungan khusus sing bakal dilebokake data saka Excel.
  • Ngonversi Excel dokumen menyang file CSV banjur menyang JSON file sing cocog kanggo parsing dening API kita.
  • Nindakake operasi Mail nggabungake cithakan Word lan data sing diowahi saka Excel dadi CSV banjur dadi JSON.

Mail merge karo Google Docs

Kanthi Mail merge API kasetyan dhuwur, sampeyan uga bisa nindakake operasi Mail merge nganggo Google Docs. Cukup download data sing dibutuhake ing Word format lan Excel, priksa manawa template Word ngemot kolom gabungan lan nindakake operasi gabungan Mail ing Java, padha karo algoritma sing diterangake ing bagean sadurunge.

Kanggo nyoba alat web Mail merge sing kuat iki, muat cithakan Word kanthi kolom gabungan khusus lan data saka Excel sing diowahi kaya sing kasebut ing ndhuwur. Sawise mbukak kode, ekspor asil menyang format apa wae nggunakake Java.

Conto ing ngisor iki nuduhake carane nindakake operasi Mail merge kanggo ngasilake Word dokumen ing Java:

Nglakokake operasi Mail merge nggunakake cithakan docx ing Java
Unggah cithakan Mail merge
Kode roto
Unggah data Mail merge
Pilih format target saka dhaptar
// 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.*;
import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;

Document doc = new Document("Input1.docx");
Workbook workbook = new Workbook("Input2.xlsx");
Worksheet worksheet = workbook.getWorksheets().get(0);
com.aspose.cells.Range dataRange = worksheet.getCells().getMaxDisplayRange();
Object dataTable[][] = worksheet.getCells().exportArray(
   0, 0, dataRange.getRowCount(), dataRange.getColumnCount());

doc.getMailMerge().execute(ObjectToDataTable(dataTable));
doc.save("Output.docx");

private static DataTable ObjectToDataTable(Object[][] data) {
    DataTable dataTable = new DataTable("CellsTable");
    for (int i = 0; i < data[0].length; i++)
        dataTable.getColumns().add(data[0][i].toString());
    for (int i = 1; i < data.length; i++)
        dataTable.getRows().add(data[i]);

    return dataTable;
}
Kode roto

Carane nggunakake Mail merge ing docx file

  1. Pasang Aspose.Words for Java.
  2. Tambah referensi perpustakaan (ngimpor perpustakaan) menyang proyek Java sampeyan.
  3. Gawe cithakan gabungan docx karo kolom gabungan.
  4. Bukak berkas cithakan ing Java.
  5. Telpon metode execute(), ngliwati kolom gabungan lan nilai-nilai kasebut ing kana.
  6. Nelpon metode Save(), ngliwati jeneng file output kanthi ekstensi sing dibutuhake.
  7. Entuk asil operasi Mail merge minangka Word file.

Pustaka Java kanggo nggunakake Mail merge ing docx

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.

Syarat Sistem

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.

Format file liyane sing didhukung

Sampeyan bisa nindakake operasi Mail merge kanggo format file liyane:

5%

Langganan kanggo Aspose Update Product

Entuk buletin saben wulan lan tawaran langsung dikirim menyang kothak layang.

© Aspose Pty Ltd 2001-2024. Kabeh hak dilindhungi undhang-undhang.