ワークブック内でワークシートを移動する

Aspose.Cells は、ワークシートをスプレッドシート内の別の場所に移動するために使用される Aspose.Cells.Worksheet.MoveTo() メソッドを提供します。このメソッドは、対象のワークシート インデックスをパラメーターとして受け取ります。

次の例は、ワークシートをブック内の別の場所に移動する方法を示しています。

 string FilePath = @"..\..\..\Sample Files\";

string FileName = FilePath + "Move Worksheet.xlsx";

//Open an existing excel file.

Workbook wb = new Workbook(FileName);

//Create a Worksheets object with reference to

//the sheets of the Workbook.

WorksheetCollection sheets = wb.Worksheets;

//Get the first worksheet.

Worksheet worksheet = sheets[0];

string test = worksheet.Name;

//Move the first sheet to the third position in the workbook.

worksheet.MoveTo(2);

//Save the excel file.

wb.Save(FileName);

サンプルコードをダウンロード