ワークシートのコピーと移動
Contents
[
Hide
]
場合によっては、共通の書式設定とデータを含む多数のワークシートが必要になることがあります。たとえば、四半期ごとの予算を扱う場合、同じ列見出し、行見出し、および数式を含むシートを含むワークブックを作成できます。これを行う方法があります: 1 つのシートを作成し、それをコピーします。
Aspose.Cells は、ワークブック内またはワークブック間でのワークシートのコピーと移動をサポートしています。データ、書式設定、テーブル、マトリックス、グラフ、画像、その他のオブジェクトを含むワークシートは、最高の精度でコピーされます。
Microsoft Excel を使用したシートの移動またはコピー
Microsoft Excel でワークブック内またはワークブック間でワークシートをコピーおよび移動する手順は次のとおりです。
- シートを別のブックに移動またはコピーするには、シートを受け取るブックを開きます。
- 移動またはコピーするシートを含むブックに切り替えてから、シートを選択します。
- 上で編集メニュー、クリックシートの移動またはコピー.
- の中に予約するダイアログで、ワークブックをクリックしてシートを受け取ります。
- 選択したシートを新しいワークブックに移動またはコピーするには、新しい本.
- の中にシート前ボックスで、移動またはコピーしたシートを挿入する前のシートをクリックします。
- シートを移動する代わりにコピーするには、コピーを作成するチェックボックス。
Aspose.Cells のワークブック内でワークシートをコピーする
Aspose.Cells はオーバーロードされたメソッドを提供しますAddCopy()ワークシートをコレクションに追加し、既存のワークシートからデータをコピーするために使用されます。メソッドの 1 つのバージョンは、ソース ワークシートのインデックスをパラメーターとして受け取ります。もう一方のバージョンは、ソース ワークシートの名前を取ります。次の例は、ブック内の既存のワークシートをコピーする方法を示しています。
This file contains hidden or 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-C | |
//Source directory path | |
StringPtr srcDir = new String("..\\Data\\01_SourceDirectory\\"); | |
//Output directory path | |
StringPtr outDir = new String("..\\Data\\02_OutputDirectory\\"); | |
//Path of input excel file | |
StringPtr sampleCopyingAndMovingWorksheets = srcDir->StringAppend(new String("sampleCopyingAndMovingWorksheets.xlsx")); | |
//Path of output excel file | |
StringPtr outputCopyingAndMovingWorksheets = outDir->StringAppend(new String("outputCopyingAndMovingWorksheets.xlsx")); | |
//Create workbook | |
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(sampleCopyingAndMovingWorksheets); | |
//Create worksheets object with reference to the sheets of the workbook. | |
intrusive_ptr<IWorksheetCollection> sheets = workbook->GetIWorksheets(); | |
//Copy data to a new sheet from an existing sheet within the workbook. | |
sheets->AddCopy(new String("Test1")); | |
//Save the Excel file. | |
workbook->Save(outputCopyingAndMovingWorksheets); | |
StringPtr msg = new String("Worksheet copied successfully with in a workbook!"); | |
Console::WriteLine(msg); |
ワークブック内でワークシートを移動する
Aspose.Cells はメソッドを提供しますへ引っ越す()ワークシートを同じスプレッドシート内の別の場所に移動するために使用されます。このメソッドは、対象のワークシート インデックスをパラメーターとして受け取ります。次の例は、ワークシートをブック内の別の場所に移動する方法を示しています。
This file contains hidden or 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-C | |
//Source directory path | |
StringPtr srcDir = new String("..\\Data\\01_SourceDirectory\\"); | |
//Output directory path | |
StringPtr outDir = new String("..\\Data\\02_OutputDirectory\\"); | |
//Path of input excel file | |
StringPtr sampleCopyingAndMovingWorksheets = srcDir->StringAppend(new String("sampleCopyingAndMovingWorksheets.xlsx")); | |
//Path of output excel file | |
StringPtr outputCopyingAndMovingWorksheets = outDir->StringAppend(new String("outputCopyingAndMovingWorksheets.xlsx")); | |
//Create workbook | |
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(sampleCopyingAndMovingWorksheets); | |
//Create worksheets object with reference to the sheets of the workbook. | |
intrusive_ptr<IWorksheetCollection> sheets = workbook->GetIWorksheets(); | |
//Access the first sheet | |
intrusive_ptr<IWorksheet> sheet = sheets->GetObjectByIndex(0); | |
//Move the first sheet to the third position in the workbook. | |
sheet->MoveTo(2); | |
//Save the Excel file. | |
workbook->Save(outputCopyingAndMovingWorksheets); | |
StringPtr msg = new String("Worksheet moved successfully with in a workbook!"); | |
Console::WriteLine(msg); |