ワークシートの追加または挿入
Contents
[
Hide
]
このトピックでは、Aspose.Cells.GridDesktopを使用してExcelファイルにワークシートを追加または挿入する技術について説明します。追加と挿入の違いは、追加は単にワークシートがExcelファイルのワークシートコレクションの末尾に追加されるという点ですが、挿入はワークシートをワークシートコレクション内の特定の位置に追加することを意味します。
ワークシートの追加
Aspose.Cells.GridDesktopを使用してワークシートを追加するには、次の手順に従ってください。
- フォームにAspose.Cells.GridDesktopコントロールを追加します。
- GridDesktopコントロールのワークシートコレクションのAddメソッドを呼び出します。
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 | |
// Adding a worksheet to the Grid | |
int i = gridDesktop1.Worksheets.Add(); | |
Worksheet sheet = gridDesktop1.Worksheets[i]; |
多くのオーバーロードされたAddメソッドのバージョンが利用可能です。上記のオーバーロードされたバージョンを使用すると、たとえば、ワークシートがデフォルトのシート名でExcelファイルに追加されます。Addメソッドの他のオーバーロードされたバージョンを使用すると、次に示すように名前を定義することができます。
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 | |
// Adding a worksheet to the Grid with a specific name | |
Worksheet sheet1 = gridDesktop1.Worksheets.Add("AddWorksheetWithName"); |
ワークシートの挿入
Aspose.Cells.GridDesktopを使用してワークシートを挿入するには、次の手順に従ってください。
- Aspose.Cells.GridDesktopコントロールをフォームに追加します。
- GridDesktopコントロールのワークシートコレクションのInsertメソッドを呼び出します。
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 | |
// Inserting a worksheet to Grid at first position of the worksheets collection | |
gridDesktop1.Worksheets.Insert(0); |
重要: Microsoft Excel(97-2003 XLS)は、最大65,536行および256列のExcelシートをサポートしています。Aspose.Cells.GridDesktopも同じ基準に従います。Aspose.Cells.GridDesktopコントロールでは、標準制限を超えた行数や列数のワークシートを追加または挿入できますが、GridデータをExcelファイルに保存しようとすると例外がスローされます。つまり、Aspose.Cells.GridDesktopを使用してExcel XLSファイルに保存できるのは、65,536行と256列に含まれるデータだけであり、XLSX(MS Excel 2007/2010)ファイル形式を使用する場合は、そのような制限はありません。