Excel paling akeh digunakake dening bisnis kanggo nganalisa data kanthi efektif. Alesan liya kanggo popularitas kasebut yaiku ndhukung nggawe grafik, grafik, lan macem-macem visualisasi sing mbantu ngerteni data kanthi cara sing luwih efektif. Nanging, yen kita kudu nuduhake data lembar kerja excel karo aplikasi liyane, kita kudu ngurai isi lan nuduhake ing format umum. Mula, kita bisa uga nimbang opsi kanggo ngekspor Excel menyang format JSON, amarga umume digunakake kanggo nyimpen lan ijol-ijolan data liwat internet. Ing artikel iki, kita bakal njelajah rincian babagan konversi Excel dadi JSON.
- API Konversi Excel menyang JSON
- Ngonversi Excel menyang JSON nggunakake Java
- Ekspor Excel menyang JSON tanpa Upload
- XLSX menyang JSON nggunakake CURL Commands
API Konversi Excel menyang JSON
Aspose.Cells Cloud SDK for Java utamane dikembangake kanggo ndhukung kemampuan nggawe buku kerja Excel, manipulasi lan transformasi menyang format kayata HTML, PDF, JPG lan format liyane. Saiki kanggo miwiti, langkah pisanan yaiku nambah rincian ing pom.xml proyek jinis mbangun maven.
<repositories>
<repository>
<id>aspose-cloud</id>
<name>artifact.aspose-cloud-releases</name>
<url>https://artifact.aspose.cloud/repo</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-cells-cloud</artifactId>
<version>22.8</version>
</dependency>
</dependencies>
Sawise referensi SDK wis ditambahake, kita kudu nggawe akun gratis liwat Aspose Cloud. Mlebet nggunakake akun sing mentas digawe lan goleki / gawe ID Klien lan Rahasia Klien ing Cloud Dashboard. Rincian kasebut dibutuhake ing bagean sabanjure.
Ngonversi Excel menyang JSON nggunakake Java
Kita bakal ngrembug rincian excel menyang konversi JSON nggunakake potongan kode Java. Dadi, tindakake pandhuan ing ngisor iki kanggo ngrampungake syarat kasebut.
- Kaping pisanan, gawe obyek CellsApi nalika nyedhiyakake rincian rahasia ClientID lan Klien minangka argumen
- Kapindho, nggawe conto File kanggo mbukak buku kerja Excel input
- Katelu, nelpon metode uploadFile(…) kanggo ngunggah buku kerja Excel menyang panyimpenan maya
- Saiki nelpon cara cellsWorkbookGetWorkbook(…) sing mbutuhake jeneng Excel input, format asil minangka Json lan jeneng file output. Sawise konversi sukses, file JSON disimpen ing panyimpenan maya
// kanggo conto liyane, bukak https://github.com/aspose-cells-cloud/aspose-cells-cloud-java
try
{
// Entuk ClientID lan ClientSecret saka https://dashboard.aspose.cloud/
String clientId = "bb959721-5780-4be6-be35-ff5c3a6aa4a2";
String clientSecret = "4d84d5f6584160cbd91dba1fe145db14";
// nggawe conto CellsApi nggunakake kredensial klien
CellsApi api = new CellsApi(clientId,clientSecret);
// jeneng input buku kerja Excel
String fileName = "TestCase.xlsx";
// rincian sandi yen workbook ing ndhelik
String password = null;
// Nemtokake manawa nyetel baris buku kerja dadi pas otomatis.
Boolean isAutoFit = true;
// Nemtokake apa mung nyimpen data tabel. Mung nggunakake pdf kanggo Excel.
Boolean onlySaveTable = true;
// format file asil
String format = "JSON";
// mbukak file saka sistem lokal
File file = new File("c://Users/nayyer/"+fileName);
// upload input Excel menyang panyimpenan maya
api.uploadFile("source.xlsx", file, "default");
// nindakake operasi konversi dokumen
File response = api.cellsWorkbookGetWorkbook("source.xlsx", password, format,
isAutoFit, onlySaveTable, null,"default", "Resultant.json","default", null);
// pesen sukses print
System.out.println("Successsul conversion of Excel to JSON !");
}catch(Exception ex)
{
System.out.println(ex);
}
Ekspor Excel menyang JSON tanpa Upload
Ing bagean iki, kita bakal ngrembug rincian babagan cara ngowahi Excel dadi JSON tanpa ngunggah input Excel menyang panyimpenan awan. Nanging, file JSON asil bakal disimpen ing panyimpenan maya.
- Kaping pisanan, gawe obyek CellsApi nalika nyedhiyakake rincian rahasia ClientID lan Klien minangka argumen
- Kapindho, nggawe conto File kanggo mbukak buku kerja Excel input
- Katelu, nelpon cara cellsWorkbookPutConvertWorkbook(…) sing mbutuhake jeneng Excel input, format asil minangka Json lan jeneng file output. Sawise konversi sukses, file JSON disimpen ing panyimpenan maya
// kanggo conto liyane, bukak https://github.com/aspose-cells-cloud/aspose-cells-cloud-java
try
{
// Entuk ClientID lan ClientSecret saka https://dashboard.aspose.cloud/
String clientId = "bb959721-5780-4be6-be35-ff5c3a6aa4a2";
String clientSecret = "4d84d5f6584160cbd91dba1fe145db14";
// nggawe conto CellsApi nggunakake kredensial klien
CellsApi api = new CellsApi(clientId,clientSecret);
// jeneng input buku kerja Excel
String fileName = "TestCase.xlsx";
// rincian sandi yen workbook ing ndhelik
String password = null;
// format file asil
String format = "JSON";
// mbukak file saka sistem lokal
File file = new File("c://Users/nayyer/"+fileName);
// nindakake operasi konversi dokumen
File response = api.cellsWorkbookPutConvertWorkbook(file, format, password, "output.json", "default", null);
// pesen sukses print
System.out.println("Successsul conversion of Excel to JSON !");
}catch(Exception ex)
{
System.out.println(ex);
}
Buku kerja input excel lan file Json asil sing digawe ing conto ing ndhuwur bisa diundhuh saka Testcase.xlsx lan output.json
XLSX menyang JSON nggunakake CURL Commands
Wiwit REST API bisa diakses kanthi gampang liwat perintah cURL, mula ing bagean iki, kita bakal nelpon Aspose.Cells Cloud liwat perintah cURL kanggo ngrampungake syarat kita. Saiki salah sawijining prasyarat kanggo operasi iki yaiku ngasilake token akses JWT (adhedhasar kredensial klien) nalika nglakokake perintah ing ngisor iki.
curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=bb959721-5780-4be6-be35-ff5c3a6aa4a2&client_secret=4d84d5f6584160cbd91dba1fe145db14" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"
Saiki yen kita duwe token JWT, kita kudu nglakokake perintah ing ngisor iki kanggo ngowahi Excel dadi JSON. File JSON asil bakal disimpen ing panyimpenan maya.
curl -v -X GET "https://api.aspose.cloud/v3.0/cells/TestCase-original.xlsx?format=JSON&isAutoFit=false&onlySaveTable=false&outPath=output.json&checkExcelRestriction=true" \
-H "accept: application/json" \
-H "authorization: Bearer <JWT Token>"
Kesimpulan
Ing artikel iki, kita wis Sinau konversi Excel menyang file JSON nggunakake Java Cloud SDK. Dadi, kita wis nyekseni manawa kanthi garis kode sing luwih sithik, kita wis bisa ngrampungake syarat kita. Kajaba saka pendekatan kasebut, cara liya sing paling gampang kanggo njelajah API ing browser web yaiku liwat antarmuka swagger. Uga, elinga yen kabeh Cloud SDK dibangun ing lisensi MIT, supaya kode sumber lengkap bisa diundhuh saka GitHub. Sampeyan bisa uga nimbang nyedhaki kita kanggo ngrampungake masalah kanthi cepet liwat [forum dhukungan produk] gratis 9.
Artikel sing gegandhengan
Disaranake ngunjungi tautan ing ngisor iki kanggo sinau luwih lengkap babagan: