Node.jsとC++を使用したExcelからJSONへの変換
ExcelワークブックをJSONに変換
Excel WorkbookをJSONに変換する方法については、Aspose.Cells for Node.js via C++ライブラリが最適なソリューションを提供します。Aspose.Cells APIは、スプレッドシートをJSON形式に変換するサポートを提供します。ワークブックをJSONにエクスポートするには、SaveFormat.JsonをWorkbook.save(string, SaveFormat)メソッドの第2パラメータとして渡します。また、JsonSaveOptionsクラスを使用して、ワークシートのエクスポート設定を追加で指定することもできます。
以下のコード例は、ExcelワークブックをJSONにエクスポートする例です。変換されたJSONファイルは、ソースファイルをコードにより変換した結果を参考にしてください。
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "sample.xlsx");
// Load your source workbook
const workbook = new AsposeCells.Workbook(filePath);
// Convert the workbook to json file.
workbook.save("sample_out.json");
以下のコード例は、JsonSaveOptionsクラスを使用して追加設定を指定し、ExcelワークブックをJSONにエクスポートする例です。変換されたJSONファイルは、ソースファイルをコードにより変換した結果を参考にしてください。
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "sample.xlsx");
// Create an options of saving the file.
const options = new AsposeCells.JsonSaveOptions();
// Set the exporting range.
options.setExportArea(AsposeCells.CellArea.createCellArea("B1", "C4"));
// Load your source workbook
const workbook = new AsposeCells.Workbook(filePath);
// Convert the workbook to json file.
workbook.save("sample_out.json", options);