はじめに

インストール

Aspose.CellsをNuGetを通じてインストール

NuGet は Aspose.Cells for .NET をダウンロードしてインストールする最も簡単な方法です。

  1. Microsoft Visual Studio を開き、NuGet パッケージマネージャを開きます。
  2. “aspose.cells” を検索して、希望の Aspose.Cells for .NET を見つけます。
  3. “インストール” をクリックすると、Aspose.Cells for .NET がダウンロードされ、プロジェクトに参照されます。 NuGet を通じて Aspose Cells をインストール

また、nuget web ページから aspose.cells をダウンロードすることもできます: Aspose.Cells for .NET NuGetパッケージ

詳細な手順

Windows に Aspose.Cells をインストール

  1. 次のページから Aspose.Cells.msi をダウンロードします: Aspose.Cells.msi をダウンロード
  2. Aspose Cells msi をダブルクリックし、インストール手順に従います:

Windows 上で Aspose Cells をインストール

詳細な手順

Linux 上で Aspose.Cells をインストール

この例では、Ubuntu を使用して Linux 上で Aspose.Cells を使用する方法を示します。

  1. “.netcore application” を作成し、「AsposeCellsTest」と名付けます。
  2. 「AsposeCellsTest.csproj」ファイルを開き、Aspose.Cells パッケージの参照に以下の行を追加します。
      <ItemGroup>
        <PackageReference Include="Aspose.Cells" Version="24.7" />
      </ItemGroup>
  3. Ubuntu 上の VSCode でプロジェクトを開きます。 Linux 上で Aspose Cells をインストール
  4. 次のコードでテストを実行します:
    // For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
    Aspose.Cells.Workbook wb1 = new Aspose.Cells.Workbook();
    wb1.Worksheets.Add("linux");
    wb1.Worksheets["linux"].Cells[0, 0].Value = "Using Aspose Cells on linux with VS Code.";
    wb1.Save("linux.xlsx");

注: Aspose.Cells For .NetStandard は Linux での要件をサポートできます。

適用対象: NetStandard2.0, NetCore2.1, NetCore3.1, Net5.0, Net6.0 およびそれ以降のバージョン

MAC OS 上で Aspose.Cells をインストール

この例では、macOS High Sierra を使用して MAC OS 上で Aspose.Cells を使用する方法を示します。

  1. “.netcore application” を作成し、「AsposeCellsTest」と名付けます。
  2. Visual Studio for Mac でアプリケーションを開き、NuGet を介して Aspose Cells をインストールします。 macOS 上で Aspose Cells をインストール
  3. 次のコードでテストを実行します:
    // For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
    Aspose.Cells.Workbook wb1 = new Aspose.Cells.Workbook();
    wb1.Worksheets.Add("macOS");
    wb1.Worksheets["macOS"].Cells[0, 0].Value = "Using Aspose Cells on macOS with Visual Studio For MAC.";
    wb1.Save("macOS.xlsx");
  4. 描画関連の機能を使用する必要がある場合は、macOS に libgdiplus をインストールしてください。詳細は次を参照: macOS で libgdiplus のインストール方法

Note: Aspose.Cells For .NetStandard はMAC OSでの要件をサポートできます。

適用対象: NetStandard2.0, NetCore2.1, NetCore3.1, Net5.0, Net6.0 およびそれ以降のバージョン

Run Aspose Cells in Docker

Net6以外のプラットフォームでグラフィックスライブラリを使用する方法

Aspose.Cells for Net6 は今や、Microsoft の公式声明で推奨されているSkiaSharpをグラフィックスライブラリとして使用しています。NET6でAspose.Cellsを使用する詳細については、Aspose.Cells for .Net6 の実行方法を参照してください。

Hello Worldアプリケーションの作成

以下の手順により、Aspose.Cells APIを使用してHello Worldアプリケーションを作成できます:

  1. ライセンスがある場合は、適用します。 評価版を使用している場合は、ライセンスに関連するコード行をスキップします。
  2. Workbook クラスのインスタンスを作成して新しいExcelファイルを作成するか、既存のExcelファイルを開きます。
  3. Excelファイルのワークシートの任意のセルにアクセスします。
  4. アクセスしたセルに**Hello World!**の単語を挿入します。
  5. 変更されたMicrosoft Excelファイルを生成します。

上記の手順の実装は、以下の例で示されています。

コードサンプル: 新しいワークブックの作成

以下の例では、新しいブックを作成し、その初めのワークシートのセルA1に"Hello World!“を挿入し、Excelファイルとして保存します。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
try
{
// Create a License object
License license = new License();
// Set the license of Aspose.Cells to avoid the evaluation limitations
license.SetLicense(dataDir + "Aspose.Cells.lic");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
// Instantiate a Workbook object that represents Excel file.
Workbook wb = new Workbook();
// When you create a new workbook, a default "Sheet1" is added to the workbook.
Worksheet sheet = wb.Worksheets[0];
// Access the "A1" cell in the sheet.
Cell cell = sheet.Cells["A1"];
// Input the "Hello World!" text into the "A1" cell
cell.PutValue("Hello World!");
// Save the Excel file.
wb.Save(dataDir + "MyBook_out.xlsx");

コードサンプル: 既存のファイルを開く

以下の例では、既存のMicrosoft Excelテンプレートファイル “Sample.xlsx” を開き、その初めのワークシートのセルA1に"Hello World!“を挿入し、Excelファイルとして保存します。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
try
{
// Create a License object
License license = new License();
// Set the license of Aspose.Cells to avoid the evaluation limitations
license.SetLicense("Aspose.Cells.lic");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
// Creating a file stream containing the Excel file to be opened
FileStream fstream = new FileStream(dataDir + "Sample.xlsx", FileMode.Open);
// Instantiate a Workbook object that represents the existing Excel file
Workbook workbook = new Workbook(fstream);
// Get the reference of "A1" cell from the cells collection of a worksheet
Cell cell = workbook.Worksheets[0].Cells["A1"];
// Put the "Hello World!" text into the "A1" cell
cell.PutValue("Hello World!");
// Save the Excel file
workbook.Save(dataDir + "HelloWorld_out.xlsx");
// Closing the file stream to free all resources
fstream.Close();