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: コメントの作者

次のコードサンプルは、セルA1にスレッド化されたコメントを追加するためのComments.AddThreadedCommentメソッドの使用を示しています。参照のためにコードによって生成された出力エクセルファイルをご覧ください。

サンプルコード

#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;

int main()
{
    Aspose::Cells::Startup();

    // Output directory path
    U16String outDir(u"..\\Data\\02_OutputDirectory\\");

    // Create a new workbook
    Workbook workbook;

    // Add Author
    int authorIndex = workbook.GetWorksheets().GetThreadedCommentAuthors().Add(u"Aspose Test", u"", u"");
    ThreadedCommentAuthor author = workbook.GetWorksheets().GetThreadedCommentAuthors().Get(authorIndex);

    // Add Threaded Comment
    workbook.GetWorksheets().Get(0).GetComments().AddThreadedComment(u"A1", u"Test Threaded Comment", author);

    // Save the workbook
    workbook.Save(outDir + u"AddThreadedComments_out.xlsx");

    std::cout << "Threaded comment added successfully!" << std::endl;

    Aspose::Cells::Cleanup();
}

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

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

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

todo:image_alt_text

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

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

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

サンプルコード

#include <iostream>
#include "Aspose.Cells.h"

using namespace Aspose::Cells;
using namespace std;

int main()
{
    Aspose::Cells::Startup();

    // Source directory path
    U16String srcDir(u"..\\Data\\01_SourceDirectory\\");

    // Create workbook
    Workbook workbook(srcDir + u"ThreadedCommentsSample.xlsx");

    // Access first worksheet
    Worksheet worksheet = workbook.GetWorksheets().Get(0);

    // Get Threaded Comments
    ThreadedCommentCollection threadedComments = worksheet.GetComments().GetThreadedComments(u"A1");

    // Iterate through threaded comments
    for (int i = 0; i < threadedComments.GetCount(); i++)
    {
        ThreadedComment comment = threadedComments.Get(i);
        cout << "Comment: " << comment.GetNotes().ToUtf8() << endl;
        cout << "Author: " << comment.GetAuthor().GetName().ToUtf8() << endl;
    }

    Aspose::Cells::Cleanup();
    return 0;
}

コンソール出力

Comment: Test Threaded Comment

Author: Aspose Test

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

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

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

サンプルコード

#include <iostream>
#include <iomanip>
#include <sstream>
#include "Aspose.Cells.h"

using namespace Aspose::Cells;
using namespace std;

int main()
{
    Aspose::Cells::Startup();

    U16String srcDir(u"..\\Data\\01_SourceDirectory\\");

    Workbook workbook(srcDir + u"ThreadedCommentsSample.xlsx");

    Worksheet worksheet = workbook.GetWorksheets().Get(0);

    ThreadedCommentCollection threadedComments = worksheet.GetComments().GetThreadedComments(u"A1");

    for (int i = 0; i < threadedComments.GetCount(); i++)
    {
        ThreadedComment comment = threadedComments.Get(i);
        cout << "Comment: " << comment.GetNotes().ToUtf8() << endl;
        cout << "Author: " << comment.GetAuthor().GetName().ToUtf8() << endl;
        Date createdTime = comment.GetCreatedTime();
        ostringstream oss;
        oss << setfill('0') 
            << setw(4) << createdTime.year << "-"
            << setw(2) << createdTime.month << "-"
            << setw(2) << createdTime.day << " "
            << setw(2) << createdTime.hour << ":"
            << setw(2) << createdTime.minute << ":"
            << setw(2) << createdTime.second;
        cout << "Created Time: " << oss.str() << endl;
    }

    Aspose::Cells::Cleanup();
    return 0;
}

コンソール出力

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メソッドは列名をパラメータとして受け取り、その列内のコメントを削除します。

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

サンプルコード

#include <iostream>
#include "Aspose.Cells.h"

using namespace Aspose::Cells;

int main()
{
    Aspose::Cells::Startup();

    // Source directory path
    U16String srcDir(u"..\\Data\\01_SourceDirectory\\");

    // Output directory path
    U16String outDir(u"..\\Data\\02_OutputDirectory\\");

    // Load the workbook
    Workbook workbook(srcDir + u"ThreadedCommentsSample.xlsx");

    // Access the first worksheet
    Worksheet worksheet = workbook.GetWorksheets().Get(0);

    // Get the threaded comment from cell A1
    ThreadedComment comment = worksheet.GetComments().GetThreadedComments(u"A1").Get(0);

    // Update the comment text
    comment.SetNotes(u"Updated Comment");

    // Save the workbook
    workbook.Save(outDir + u"EditThreadedComments.xlsx");

    std::cout << "Threaded comment updated successfully!" << std::endl;

    Aspose::Cells::Cleanup();
}

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

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

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

todo:image_alt_text

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

Aspose.Cellsは指定された列のコメントを削除するためのComments.RemoveAtメソッドを提供します。Comments.RemoveAtメソッドは列名をパラメータとして受け取り、その列内のコメントを削除します。

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

サンプルコード

#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;

int main()
{
    Aspose::Cells::Startup();

    // Source directory path
    U16String srcDir(u"..\\Data\\01_SourceDirectory\\");

    // Output directory path
    U16String outDir(u"..\\Data\\02_OutputDirectory\\");

    // Load the workbook
    Workbook workbook(srcDir + u"ThreadedCommentsSample.xlsx");

    // Access first worksheet
    Worksheet worksheet = workbook.GetWorksheets().Get(0);

    // Get the comments collection
    CommentCollection comments = worksheet.GetComments();

    // Get the author of the first threaded comment in cell A1
    ThreadedCommentAuthor author = worksheet.GetComments().GetThreadedComments(u"A1").Get(0).GetAuthor();

    // Remove the comment at cell A1
    comments.RemoveAt(u"A1");

    // Get the threaded comment authors collection
    ThreadedCommentAuthorCollection authors = workbook.GetWorksheets().GetThreadedCommentAuthors();

    // Save the workbook
    workbook.Save(outDir + u"ThreadedCommentsSample_Out.xlsx");

    std::cout << "Threaded comments processed successfully!" << std::endl;

    Aspose::Cells::Cleanup();
}