Node.js と C++ を使用したスレッド付きコメントの管理

スレッド化されたコメント

MS Excel 365 では、スレッド型コメントを追加する機能が提供されています。これらのコメントは会話として機能し、ディスカッションに使用できます。新しいコメントにはスレッド型の会話が可能なリプライボックスが付属しています。古いコメントは Excel 365 ではノートと呼ばれます。以下のスクリーンショットは、Excel 365 でスレッド型コメントが開かれたときの表示例です。

todo:image_alt_text

古いバージョンの Excel では、スレッド型コメントは以下のように表示されます。以下の画像は、サンプルファイルを Excel 2016 で開いたものです。

todo:image_alt_text

todo:image_alt_text

Aspose.Cells では、スレッド型コメントの管理機能も提供されています。

スレッド型コメントの追加

Excel でスレッド型コメントを追加

Excel 365 でスレッド型コメントを追加するには、以下の手順に従ってください。

  • 方法 1
    • レビュー タブをクリック
    • 新しいコメント ボタンをクリック
    • これにより、アクティブなセルにコメントを入力するためのダイアログが開きます。
    • todo:image_alt_text
  • 方法 2
    • コメントを挿入したいセルを右クリック
    • 新しいコメント オプションをクリック
    • これにより、アクティブなセルにコメントを入力するためのダイアログが開きます。
    • todo:image_alt_text

Aspose.Cells を使用してスレッド型コメントを追加

Aspose.Cellsは、Comments.AddThreadedCommentメソッドを使ってスレッド化コメントを追加します。Comments.AddThreadedCommentメソッドは以下の3つのパラメータを受け取ります。

  • セル名: コメントを挿入するセルの名前。
  • コメントのテキスト: コメントのテキスト。
  • ThreadedCommentAuthor: コメントの作者

以下のコードサンプルは、Comments.AddThreadedCommentメソッドを使用してセルA1にスレッド付きコメントを追加する方法を示しています。参考のために、コードによって生成された出力Excelファイルを参照してください。

サンプルコード

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

// Source directory
const outDir = path.join(__dirname, "output");

const workbook = new AsposeCells.Workbook();

// Add Author
const authorIndex = workbook.getWorksheets().getThreadedCommentAuthors().add("Aspose Test", "", "");
const author = workbook.getWorksheets().getThreadedCommentAuthors().get(authorIndex);

// Add Threaded Comment
workbook.getWorksheets().get(0).getComments().addThreadedComment("A1", "Test Threaded Comment", author);

workbook.save(outDir + "AddThreadedComments_out.xlsx");

スレッド化されたコメントを読む

Excelでスレッド化されたコメントを読む

Excelでスレッド化されたコメントを読むには、単にコメントを含むセル上にマウスを動かすとコメントが表示されます。コメント表示は、次の画像に示すような表示になります。

todo:image_alt_text

Aspose.Cellsを使用してスレッド化されたコメントを読む

Aspose.Cellsは指定された列のスレッド化されたコメントを取得するためのComments.GetThreadedCommentsメソッドを提供します。Comments.GetThreadedCommentsメソッドは列名をパラメータとして受け取り、ThreadedCommentCollectionを返します。ThreadedCommentCollectionを繰り返し処理してコメントを表示できます。

次の例は、サンプルエクセルファイルを読み込んで列A1からコメントを読み取ることを示しています。参照のためにコードによって生成されたコンソール出力をご覧ください。

サンプルコード

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

// Source directory
const sourceDir = path.join(__dirname, "data"); // Adjust as necessary

const filePath = path.join(sourceDir, "ThreadedCommentsSample.xlsx");

// Loads the workbook which contains threaded comments
const workbook = new AsposeCells.Workbook(filePath);

// Access first worksheet
const worksheet = workbook.getWorksheets().get(0);

// Get Threaded Comments
const threadedComments = worksheet.getComments().getThreadedComments("A1");

const count = threadedComments.getCount();
for (let i = 0; i < count; i++) {
const comment = threadedComments.get(i);
console.log("Comment: " + comment.getNotes());
console.log("Author: " + comment.getAuthor().getName());
}

コンソール出力

  

Comment: Test Threaded Comment  

Author: Aspose Test  

スレッド化されたコメントの作成時間を読む

Aspose.Cellsは、指定された列のスレッド付きコメントを取得するためのComments.GetThreadedCommentsメソッドを提供します。Comments.GetThreadedCommentsメソッドは列名をパラメータとして受け入れ、ThreadedCommentCollectionを返します。ThreadedCommentCollectionを繰り返し、ThreadedComment.getCreatedTime()プロパティを使用できます。

次の例は、サンプルエクセルファイルを読み込んでスレッド化されたコメントの作成時間を読み取ることを示しています。参照のためにコードによって生成されたコンソール出力をご覧ください。

サンプルコード

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

// Source directory
const sourceDir = path.join(__dirname, "data");
const filePath = path.join(sourceDir, "ThreadedCommentsSample.xlsx");

// Loads the workbook
const workbook = new AsposeCells.Workbook(filePath);

// Access first worksheet
const worksheet = workbook.getWorksheets().get(0);

// Get Threaded Comments
const threadedComments = worksheet.getComments().getThreadedComments("A1");

const count = threadedComments.getCount();

for (let i = 0; i < count; i++) {
const comment = threadedComments.get(i);
console.log("Comment: " + comment.getNotes());
console.log("Author: " + comment.getAuthor().getName());
console.log("Created Time: " + comment.getCreatedTime());
}

コンソール出力

  

Comment: Test Threaded Comment  

Author: Aspose Test  

Created Time: 5/15/2019 12:46:23 PM  

スレッド化されたコメントの編集

Excelでスレッド化されたコメントを編集する

Excelでスレッド化されたコメントを編集するには、次の画像に示すようにコメントの編集リンクをクリックします。

todo:image_alt_text

Aspose.Cellsを使用してスレッド化されたコメントを編集する

Aspose.Cellsは、指定された列のスレッド付きコメントを取得するためのComments.GetThreadedCommentsメソッドを提供します。Comments.GetThreadedCommentsメソッドは列名をパラメータとして受け入れ、ThreadedCommentCollectionを返します。必要なコメントをThreadedCommentCollectionで更新し、ワークブックを保存できます。

次の例は、サンプルエクセルファイルを読み込んで列A1のコメントを削除することを示しています。参照のためにコードによって生成された更新されたコメントを示す出力エクセルファイルをご覧ください。

サンプルコード

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

// Source and output directories
const sourceDir = path.join(__dirname, "data");
const outDir = path.join(__dirname, "output");

const filePath = path.join(sourceDir, "ThreadedCommentsSample.xlsx");
const workbook = new AsposeCells.Workbook(filePath);

// Access first worksheet
const worksheet = workbook.getWorksheets().get(0);

// Get Threaded Comment
const comment = worksheet.getComments().getThreadedComments("A1").get(0);
comment.setNotes("Updated Comment");

workbook.save(outDir + "EditThreadedComments.xlsx");

スレッド化されたコメントを削除する

Excelでスレッド化されたコメントを削除する

Excelでスレッド化されたコメントを削除するには、コメントを含むセルを右クリックし、次の画像に示すようにコメントを削除オプションをクリックします。

todo:image_alt_text