Excel チャートを画像に変換する
Contents
[
Hide
]
グラフは視覚的に魅力的であり、ユーザーはデータの比較、パターン、および傾向を簡単に確認できます。たとえば、ワークシートの数値の列を分析するのではなく、売上が増減しているかどうか、または実際の売上が予測された売上とどのように比較されているかをグラフで一目で確認できます。人々は、理解しやすく維持しやすい方法で統計情報やグラフ情報を提示するように求められることがよくあります。写真が役立ちます。
アプリケーションまたは Web ページでグラフが必要になる場合があります。または、Word 文書、PDF ファイル、PowerPoint プレゼンテーション、またはその他のアプリケーションに必要な場合があります。いずれの場合も、グラフを画像としてレンダリングして、他の場所で使用できるようにします。
チャートを画像に変換する
ここの例では、円グラフと列の char が画像に変換されます。
円グラフを画像ファイルに変換する
まず、Microsoft Excel で円グラフを作成し、それを Aspose.Cells の画像ファイルに変換します。この例のコードは、テンプレート Microsoft Excel ファイルの円グラフに基づいて EMF 画像を作成します。
出力: 円グラフ画像 |
---|
![]() |
- Microsoft Excel で円グラフを作成します。
- Microsoft Excel で新しいワークブックを開きました。
- ワークシートにデータを入力します。
- データに基づいて円グラフを作成しました。
- ファイルを保存します。
入力ファイル。 |
---|
![]() |
- Aspose.Cells をダウンロードしてインストールします。
- 開発用コンピューターにインストールします。
全てAsposeコンポーネントは、最初のインストール時に評価モードで動作します。評価モードには時間制限がなく、出力ドキュメントに透かしを挿入するだけです。
- プロジェクトを作成します。
- Visual Studio.Net を起動します。
- 新しいコンソール アプリケーションを作成します。この例では C# コンソール アプリケーションを使用していますが、VB.NET も使用できます。
- 参照を追加します。このプロジェクトは Aspose.Cells を使用するため、Aspose.Cells への参照を追加します。
- チャートを見つけて変換するコードを書きます。以下は、タスクを実行するためにコンポーネントによって使用されるコードです。ごくわずかなコード行が使用されます。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
// Open the existing excel file which contains the pie chart. | |
Workbook workbook = new Workbook(dataDir+ "PieChart.xlsx"); | |
// Get the designer chart (first chart) in the first worksheet of the workbook. | |
Aspose.Cells.Charts.Chart chart = workbook.Worksheets[0].Charts[0]; | |
// Convert the chart to an image file. | |
chart.ToImage(dataDir+ "PieChart.out.emf", ImageType.Emf); |
縦棒グラフを画像ファイルに変換する
最初に Microsoft Excel で縦棒グラフを作成し、上記のように画像ファイルに変換します。サンプル コードを実行すると、テンプレート Excel ファイルの縦棒グラフに基づいて JPEG ファイルが作成されます。
出力ファイル: 縦棒グラフ イメージ。 |
---|
![]() |
- Microsoft Excel で縦棒グラフを作成します。
- Microsoft Excel で新しいワークブックを開きます。
- ワークシートにデータを入力します。
- データに基づいて縦棒グラフを作成します。
- ファイルを保存します。
入力ファイル。 |
---|
![]() |
- 上記のように、参照を使用してプロジェクトをセットアップします。
- グラフを画像に動的に変換します。以下は、タスクを実行するためにコンポーネントによって使用されるコードです。コードは前のものと似ています。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
// Open the existing excel file which contains the column chart. | |
Workbook workbook = new Workbook(dataDir+ "ColumnChart.xlsx"); | |
// Get the designer chart (first chart) in the first worksheet of the workbook. | |
Aspose.Cells.Charts.Chart chart = workbook.Worksheets[0].Charts[0]; | |
// Convert the chart to an image file. | |
chart.ToImage(dataDir+ "ColumnChart.out.jpeg", ImageType.Jpeg); |