行と列、およびスクロールバーの表示/非表示をNode.jsとC++を使って制御する

行や列の表示と非表示

Aspose.Cellsは、Microsoft Excelファイルを表すWorkbookクラスを提供します。Workbookクラスは、Excelファイル内の各ワークシートにアクセスできるgetWorksheets()コレクションを含みます。ワークシートはWorksheetクラスで表されます。Worksheetクラスは、そのワークシート内のすべてのセルを表すgetCells()コレクションを提供します。getCells()コレクションは、ワークシートの行や列を管理するための複数のメソッドを提供します。その一部を以下に示します。

行と列を表示

開発者は、unhideRow(number, number)unhideColumn(number, number)のメソッドを呼び出すことで、非表示になっている行や列を表示させることができます。どちらのメソッドも、2つのパラメータを取ります:

  • 行または列のインデックス - 特定の行または列を表示するために使用される行または列のインデックス。
  • 行の高さまたは列の幅 - 非表示にする行または列に割り当てられた行の高さまたは列の幅。
const path = require("path");
const fs = require("fs");
const AsposeCells = require("aspose.cells.node");

// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "book1.xls");

// Reading the Excel file into a buffer
const fileBuffer = fs.readFileSync(filePath);

// Instantiating a Workbook object with file buffer
const workbook = new AsposeCells.Workbook(fileBuffer);

// Accessing the first worksheet in the Excel file
const worksheet = workbook.getWorksheets().get(0);

// Unhiding the 3rd row and setting its height to 13.5
worksheet.getCells().unhideRow(2, 13.5);

// Unhiding the 2nd column and setting its width to 8.5
worksheet.getCells().unhideColumn(1, 8.5);

// Saving the modified Excel file
workbook.save(path.join(dataDir, "output.xls"));

行と列を非表示

開発者は、hideRow(number)hideColumn(number)のメソッドを呼び出すことで、行や列を非表示にできます。どちらのメソッドも、特定の行や列のインデックスをパラメータとして受け取り、その行または列を非表示にします。

const path = require("path");
const fs = require("fs");
const AsposeCells = require("aspose.cells.node");

const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "book1.xls");

const fileBuffer = fs.readFileSync(filePath);

const workbook = new AsposeCells.Workbook(fileBuffer);

const worksheet = workbook.getWorksheets().get(0);

worksheet.getCells().hideRow(2);

worksheet.getCells().hideColumn(1);

workbook.save(path.join(dataDir, "output.out.xls"));

複数の行と列を非表示

開発者は、hideRows(number, number)hideColumns(number, number)のメソッドを呼び出し、複数の行や列を一度に非表示にできます。これらの両方のメソッドは、開始行または列のインデックスと隠す行または列の数をパラメータとして受け取ります。

const fs = require('fs');
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, "book1.xls");
// Creating a file stream containing the Excel file to be opened
const fstream = fs.readFileSync(filePath);

// Instantiating a Workbook object
// Opening the Excel file through the file stream
const workbook = new AsposeCells.Workbook(fstream);

// Accessing the first worksheet in the Excel file
const worksheet = workbook.getWorksheets().get(0);

// Hiding 3, 4 and 5 rows in the worksheet
worksheet.getCells().hideRows(2, 3);

// Hiding 2 and 3 columns in the worksheet
worksheet.getCells().hideColumns(1, 2);

// Saving the modified Excel file
workbook.save(path.join(dataDir, "outputxls"));

// No explicit close needed for file stream as we're working with in-memory data

スクロールバーの表示と非表示

スクロールバーは、どのファイルの内容をナビゲートするために使用されます。通常、2種類のスクロールバーがあります。

  • 垂直スクロールバー
  • 水平スクロールバー

Microsoft Excelは、ユーザーがワークシートの内容をスクロールできるように、水平および垂直のスクロールバーを提供しています。Aspose.Cellsを使用すると、Excelファイルの両方のタイプのスクロールバーの表示/非表示を制御することができます。

スクロールバーの表示を制御する

Aspose.Cellsは、Excelファイルを表すWorkbookクラスを提供します。Workbookクラスは、Excelファイルの管理に役立つさまざまなプロパティとメソッドを備えています。スクロールバーの表示制御には、WorkbookSettings.isVScrollBarVisible()WorkbookSettings.isHScrollBarVisible()プロパティを使用します。WorkbookSettings.isVScrollBarVisible()WorkbookSettings.isHScrollBarVisible()はBoolean型のプロパティであり、これらはtrueまたはfalseのみを格納できます。

スクロールバーを表示する

スクロールバーを表示するには、WorkbookクラスのWorkbookSettings.isVScrollBarVisible()またはWorkbookSettings.isHScrollBarVisible()プロパティをtrueに設定します。

スクロールバーを非表示にする

スクロールバーを非表示にするには、WorkbookクラスのWorkbookSettings.isVScrollBarVisible()またはWorkbookSettings.isHScrollBarVisible()プロパティをfalseに設定します。

サンプルコード

以下は、Excelファイルであるbook1.xlsを開き、両方のスクロールバーを非表示にし、変更されたファイルをoutput.xlsとして保存する完全なコードです。

const fs = require("fs");
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, "book1.xls");

// Creating a file stream containing the Excel file to be opened
const fstream = fs.readFileSync(filePath);

// Instantiating a Workbook object
// Opening the Excel file through the file stream
const workbook = new AsposeCells.Workbook(fstream);

// Hiding the vertical scroll bar of the Excel file
workbook.getSettings().setIsVScrollBarVisible(false);

// Hiding the horizontal scroll bar of the Excel file
workbook.getSettings().setIsHScrollBarVisible(false);

// Saving the modified Excel file
workbook.save(path.join(dataDir, "output.xls"));