Excel の条件付き書式

Microsoft Office Excel を使用すると、テキスト データをスプレッドシートまたはワークブック形式でレイアウトできます。さまざまなファイルや場所から情報やデータを 1 つの場所に集めて、1 つのファイルで処理および分析できます。Excel ワークシートでさまざまな色合い、太字、斜体を定義して重要なデータを強調表示します。適切な配色を選択して、すばやく分析できます。以下に、Excel ファイルの一般的な使用方法を示します。

  • データ入力と保存
  • ビジネスデータの収集と検証
  • 管理および経営の職務
  • 会計と予算
  • データ分析
  • レポート + 視覚化
  • 予測

条件付き書式

条件付き書式設定は、多くのスプレッドシート アプリケーションの機能です。特定の条件を満たすセルに特定の書式設定を適用できます。スプレッドシートに保存されているデータや情報を強調したり、区別したりするために、色ベースの書式設定として最もよく使用されます。条件が偽の場合、セル範囲は書式設定されません。たとえば、1000 未満の数字を赤色で、1000 を超える数字を青色で表示することができます。

以下に、利用可能な一般的な条件付き書式の視覚化を示します。

  • 背景色のシェーディング(セル)
  • 前景色のシェーディング(フォント)
  • データバー
  • アイコン(4種類の画像タイプがあります)
  • 価値観

以下に指定されたトピックについてさらに詳しく説明します

ワークシートの条件付き書式を取得する

Aspose.Cells Cloud は、Excel ワークシートから条件付き書式設定情報を読み取る機能を提供します。API の GetWorksheetConditionalFormattings メソッドを使用すると、Excel ワークシートから書式設定の詳細を読み取ることができます。最初の手順は、パーソナライズされたクライアント ID とクライアント シークレットに基づいて JWT トークンを生成することです。詳細については、クライアント ID とクライアント シークレット キーを使用して JWT トークンを取得する方法 を参照してください。

以下にcURLコマンドを示します。これはExcelワークシートから書式設定の詳細を読み取るのに役立ちます。

curl -X GET "https://api.aspose.cloud/v3.0/cells/conditional.xlsx/worksheets/Sheet1/conditionalFormattings" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>"

C# .NET

// 完全な例とデータ ファイルについては、https://github.com/aspose-cells-cloud/aspose-cells-cloud-dotnet/ をご覧ください。
CellsApi instance = new CellsApi(clientId, clientSecret, apiVersion, testbaseurl);
string name = BOOK1;
string sheetName = SHEET1;
string folder = TEMPFOLDER;
instance.UploadFile(folder + @"\" + name, File.Open( @"C:\TestData\" +name));
var response = instance.CellsConditionalFormattingsGetWorksheetConditionalFormattings(name, sheetName, folder);
Assert.IsInstanceOf<ConditionalFormattingsResponse>(response, "response is ConditionalFormattingsResponse");
Assert.AreEqual(response.Code, 200);

条件付き書式を追加する

Microsoft Excel には、条件付き書式、データ バー、カラー スケール、アイコン セットの 3 つのプリセットが用意されており、Aspose.Cells Cloud API はこれらすべてのタイプをサポートしています。タイプ、演算子、スタイル、セル領域など、条件のさまざまなパラメーターを指定します。

cURLコマンド

curl -X PUT "https://api.aspose.cloud/v3.0/cells/conditional.xlsx/worksheets/Sheet1/conditionalFormattings?cellArea=C4%3AC6" \
-H "accept: application/json" \
-H "authorization: Bearer <JWT Token>" \
-H "Content-Type: application/json" \
-d "{ \"link\": { \"Href\": \"string\", \"Rel\": \"string\", \"Title\": \"string\", \"Type\": \"string\" }, \"Priority\": 2, \"Type\": \"CellValue\", \"StopIfTrue\": true, \"AboveAverage\": { \"IsAboveAverage\": true, \"IsEqualAverage\": true, \"StdDev\": 0 }, \"ColorScale\": { \"MaxCfvo\": { \"IsGTE\": true, \"Type\": \"string\" }, \"MaxColor\": { \"A\": 100, \"R\": 200, \"G\": 200, \"B\": 0 }, \"MidCfvo\": { \"IsGTE\": true, \"Type\": \"string\" }, \"MidColor\": { \"A\": 0, \"R\": 0, \"G\": 0, \"B\": 0 }, \"MinCfvo\": { \"IsGTE\": true, \"Type\": \"string\" }, \"MinColor\": { \"A\": 0, \"R\": 0, \"G\": 0, \"B\": 0 } }, \"DataBar\": { \"AxisColor\": { \"A\": 0, \"R\": 0, \"G\": 0, \"B\": 0 }, \"AxisPosition\": \"string\", \"BarBorder\": { \"Color\": { \"A\": 0, \"R\": 0, \"G\": 0, \"B\": 0 }, \"Type\": \"string\" }, \"BarFillType\": \"string\", \"Color\": { \"A\": 0, \"R\": 0, \"G\": 0, \"B\": 0 }, \"Direction\": \"string\", \"MaxCfvo\": { \"IsGTE\": true, \"Type\": \"string\" }, \"MaxLength\": 0, \"MinCfvo\": { \"IsGTE\": true, \"Type\": \"string\" }, \"MinLength\": 0, \"NegativeBarFormat\": { \"BorderColor\": { \"A\": 0, \"R\": 0, \"G\": 0, \"B\": 0 }, \"BorderColorType\": \"string\", \"Color\": { \"A\": 0, \"R\": 0, \"G\": 0, \"B\": 0 }, \"ColorType\": \"string\" }, \"ShowValue\": true }, \"Formula1\": \"string\", \"Formula2\": \"string\", \"IconSet\": { \"CfIcons\": [ { \"ImageData\": \"string\", \"Index\": 0, \"Type\": \"string\" } ], \"Cfvos\": [ { \"IsGTE\": true, \"Type\": \"string\" } ], \"IsCustom\": true, \"Reverse\": true, \"ShowValue\": true, \"IconSetType\": \"string\" }, \"Operator\": \"string\", \"Style\": { \"link\": { \"Href\": \"string\", \"Rel\": \"string\", \"Title\": \"string\", \"Type\": \"string\" }, \"Font\": { \"Color\": { \"A\": 0, \"R\": 0, \"G\": 0, \"B\": 0 }, \"DoubleSize\": 0, \"IsBold\": true, \"IsItalic\": true, \"IsStrikeout\": true, \"IsSubscript\": true, \"IsSuperscript\": true, \"Name\": \"string\", \"Size\": 0, \"Underline\": \"string\" }, \"Name\": \"string\", \"CultureCustom\": \"string\", \"Custom\": \"string\", \"BackgroundColor\": { \"A\": 220, \"R\": 10, \"G\": 120, \"B\": 0 }, \"ForegroundColor\": { \"A\": 0, \"R\": 0, \"G\": 0, \"B\": 0 }, \"IsFormulaHidden\": true, \"IsDateTime\": true, \"IsTextWrapped\": true, \"IsGradient\": true, \"IsLocked\": true, \"IsPercent\": true, \"ShrinkToFit\": true, \"IndentLevel\": 0, \"Number\": 0, \"RotationAngle\": 0, \"Pattern\": \"None\", \"TextDirection\": \"Context\", \"VerticalAlignment\": \"Center\", \"HorizontalAlignment\": \"General\", \"BorderCollection\": [ { \"LineStyle\": \"string\", \"Color\": { \"A\": 120, \"R\": 0, \"G\": 0, \"B\": 0 }, \"BorderType\": \"BottomBorder\", \"ThemeColor\": { \"ColorType\": \"string\", \"Tint\": 0 }, \"ArgbColor\": -16777216 } ], \"BackgroundThemeColor\": { \"ColorType\": \"string\", \"Tint\": 0 }, \"ForegroundThemeColor\": { \"ColorType\": \"string\", \"Tint\": 0 } }, \"Text\": \"string\", \"TimePeriod\": \"string\", \"Top10\": { \"IsBottom\": true, \"IsPercent\": true, \"Rank\": 0 }}"

以下の C# コード スニペットは、Excel ワークシートに条件付き書式を追加します。

C# .NET

// https://dashboard.aspose.cloud/ から AppKey と AppSID を取得します。
// NuGet パッケージ Aspose.Cells-Cloud をインストールする
// 完全な例とデータ ファイルについては、https://github.com/aspose-cells-cloud/aspose-cells-cloud-dotnet をご覧ください。

CellsApi cellsApi = new CellsApi(AppKey, AppSid);
string name = "BOOK1.xlsx";
string sheetName = "SHEET1";
string cellArea = "A1:C10";
FormatCondition formatcondition = new FormatCondition();
formatcondition.Type = "CellValue";
formatcondition.Operator = "Between";
formatcondition.Formula1 = "10";
formatcondition.Formula2 = "20";
var color = new Color();
color.A = 1;
color.R = 132;
color.G = 157;
color.B = 204;
Style style = new Style();
style.BackgroundColor = color;
formatcondition.Style = style;
string folder = "TEMPFOLDER";
var response = cellsApi.CellsConditionalFormattingsPutWorksheetConditionalFormatting(name, sheetName, cellArea, formatcondition, folder);

すべての条件付き書式をクリア

Aspose.Cells Cloud では、条件付き書式の書式設定をクリアする機能を使用できます。DeleteWorksheetConditionalFormattings メソッドを使用すると、Excel スプレッドシートから条件付き書式をクリアできます。以下の cURL コマンドを使用して、この要件を満たすことができます。

cURLコマンド

curl -X DELETE "https://api.aspose.cloud/v3.0/cells/conditional.xlsx/worksheets/Sheet1/conditionalFormattings" \
-H "accept: application/json" \
-H "authorization: Bearer <JWT Token>"

C# .NET

// 完全な例とデータ ファイルについては、https://github.com/aspose-cells-cloud/aspose-cells-cloud-dotnet/ をご覧ください。
CellsApi instance = new CellsApi(clientId, clientSecret, apiVersion, testbaseurl);
string name = BOOK1;
string sheetName = SHEET1;
string folder = TEMPFOLDER;
instance.UploadFile(folder + @"\" + name, File.Open( @"C:\TestData\" +name));
var response = instance.CellsConditionalFormattingsDeleteWorksheetConditionalFormattings(name, sheetName, folder);
Assert.IsInstanceOf<CellsCloudResponse>(response, "response is CellsCloudResponse");
Assert.AreEqual(response.Code, 200);

上記のメソッドはすべての条件付き書式を削除します。特定の書式を削除したい場合は、DeleteWorksheetConditionalFormatting メソッドを使用してください。このメソッドは、Excel スプレッドシートの書式設定条件のインデックス番号を受け入れます。

以下のコマンドは、インデックス 1 (インデックス値は 0 から始まります) の条件付き書式を削除します。

cURLコマンド

curl -X DELETE "https://api.aspose.cloud/v3.0/cells/conditional.xlsx/worksheets/Sheet1/conditionalFormattings/1" \
-H "accept: application/json" \
-H "authorization: Bearer <JWT Token>"
ワークシートから書式設定が削除されました。

画像 1: Excel ワークシートから書式設定が削除されました。

特定のエリアの条件付き書式を削除する

特定の領域から条件付き書式を削除する必要がある場合は、DeleteWorksheetConditionalFormattingArea メソッドを使用してください。要件を満たすには、startRow、startColumn、totalRows、totalColumns 情報を指定する必要があります。行と列のインデックスは 0 から始まることに注意してください。

cURLコマンド

curl -X DELETE "https://api.aspose.cloud/v3.0/cells/conditional.xlsx/worksheets/Sheet1/conditionalFormattings/area?startRow=4&startColumn=1&totalRows=3&totalColumns=1" \
-H "accept: application/json" \
-H "authorization: Bearer <JWT Token>"

結論

Aspose.Cells Cloud API は素晴らしい製品であり、MS Excel および OpenOffice sheet ファイルを作成、操作し、サポートされている他の形式に変換する機能を提供します。製品のインストールは必要ありません。

詳細については、Aspose.Cells Cloud ホームページ をご覧ください。また、プログラミング言語固有の SDK のインストールと構成に関する情報については、Aspose.Cloud SDK のインストール方法 をご覧ください。