
Cara Mengedit Lembar Excel di Node.js
- Pustaka Node.js untuk mengedit file Excel
- Cari dan ganti di Excel menggunakan Node.js
- Bagaimana cara mengedit sel di Excel secara terprogram?
- Hapus data dari spreadsheet Excel
Pustaka Node.js untuk mengedit file Excel
Silakan jalankan perintah berikut untuk menyiapkan library Node.js Excel untuk mulai mengedit spreadsheet Excel secara terprogram.
npm install aspose.cells
npm install java
Silakan ikuti [postingan blog] ini 7 untuk mengetahui tentang info penyiapan lengkap dan prasyarat. Catatan: Anda harus memiliki file XLSX sumber di direktori akar proyek Anda karena kami telah menempatkan file “sample.xlsx” dalam tutorial ini.
Cari dan ganti di Excel menggunakan Node.js
Berikut ini adalah langkah-langkah untuk melakukan tindakan ini secara terprogram.
- Impor dan buat objek dari kelas Cells.
- Membuat instance kelas anak WorkBook dengan file XLSX.
- Panggil metode replace(placeHolder, newValue) untuk mencari nilai dan menggantinya dengan nilai baru.
- Simpan file menggunakan metode save(fileName).
Contoh kode berikut menunjukkan cara mencari dan mengganti teks dalam file Excel menggunakan Node.js.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
// edit a value by search and replace var aspose = aspose || {}; // create an obect of the Cells class. aspose.cells = require("aspose.cells"); // instantiates WorkBook child class with an XLSX file var sampleFile = "sample.xlsx"; var workbook = new aspose.cells.Workbook(sampleFile); // call the replace method to search a value and replace it with a new value workbook.replace("mustafa", 100); // save the data into a new xlsx file workbook.save("result.xlsx"); Cara Mengedit Lembar Excel di Node.js
Bagaimana cara mengedit sel di Excel secara terprogram?
Pustaka Node.js Excel juga memungkinkan Anda memperbarui nilai di sel tertentu pada lembar Excel. Ikuti langkah-langkah berikut untuk mencapai fungsi ini di file Node.js Anda:
- Buat objek dari kelas Sel.
- Buat objek kelas anak WorkBook dengan membuat instance-nya dengan file XLSX.
- Akses buku kerja, dapatkan sel dengan memanggil metode getCells() dan memanggil metode putValue(string) untuk memperbarui sel tertentu (yaitu B2) dari lembar Excel.
- Panggil metode save(fileName) untuk menyimpan file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
// edit a specific cell in an Excel sheet var aspose = aspose || {}; // create an object of the Cells class. aspose.cells = require("aspose.cells"); // instantiates WorkBook child class with an XLSX file var sampleFile = "sample.xlsx"; var workbook = new aspose.cells.Workbook(sampleFile); // Access workbook, get the cells by calling getCells() method and call putValue(string) method to update a specefic cell(B2) of Excel sheet workbook.getWorksheets().get(0).getCells().get("B2").putValue("new value"); // save the data into a new xlsx file workbook.save("result.xlsx"); Edit sel di Excel secara terprogram
Hapus data dari spreadsheet Excel
Pada bagian ini, kita akan mempelajari bagaimana kita dapat menghapus data dari lembar Excel menggunakan Node.js secara terprogram. Kami akan melakukan langkah-langkah berikut:
- Buat objek dari kelas Sel.
- Membuat instance kelas anak WorkBook dengan file XLSX.
- Panggil metode clear() untuk menghapus semua objek sel dan baris.
- Panggil metode save(fileName) untuk menyimpan file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
// clear the content of an SLSX file var aspose = aspose || {}; // create an object of the Cells class. aspose.cells = require("aspose.cells"); // instantiates WorkBook child class with an XLSX file var sampleFile = "sample.xlsx"; var workbook = new aspose.cells.Workbook(sampleFile); // call clear() method to clear all cell and row objects. workbook.getWorksheets().get(0).getCells().clear(); // save the data into a new xlsx file workbook.save("result.xlsx"); Hapus data dari lembar Excel menggunakan pustaka Node.js
Dapatkan Lisensi Gratis
Anda dapat menggunakan lisensi sementara gratis untuk menggunakan Aspose.Cells untuk Node.js tanpa batasan evaluasi.
Kesimpulan
Ini membawa kita ke akhir posting blog ini. Kita telah mempelajari cara mengedit Excel Sheets di Node.js secara terprogram. Kami telah menggunakan library Node.js Excel untuk mengedit sel tertentu dan menghapus data file. Ada banyak metode lebih lanjut yang tersedia di sini yang dapat Anda jelajahi dan praktikkan sendiri. Selanjutnya, conholdate.com secara konsisten menulis tentang topik baru. Oleh karena itu, harap tetap terhubung untuk pembaruan rutin.
Berikan pertanyaan
Jika Anda memiliki pertanyaan, jangan ragu untuk menghubungi kami di forum.