Php でのワークシートの管理

Aspose.Cells - ワークシートの管理

新しい Excel ファイルへのワークシートの追加

を使用して新しい Excel ファイルにワークシートを追加するにはAspose.Cells Java for PHP、単に呼び出すadd_worksheet方法ワークシートの管理モジュール。

PHP コード

 //Instantiating a Workbook object

$workbook = new Workbook();

//Adding a new worksheet to the Workbook object

$worksheets = $workbook->getWorksheets();

$sheetIndex = $worksheets->add();

$worksheet = $worksheets->get($sheetIndex);

//Setting the name of the newly added worksheet

$worksheet->setName("My Worksheet");

//Saving the Excel file

$workbook->save($dataDir . "book.out.xls");

シート名を使用してワークシートを削除する

を使用してシート名でワークシートを削除するにはAspose.Cells Java for PHP、単に呼び出すremove_worksheet_by_name方法ワークシートの管理モジュール。

PHP コード

 //Creating a file stream containing the Excel file to be opened

$fstream = new FileInputStream($dataDir . "book.xls");

//Instantiating a Workbook object with the stream

$workbook = new Workbook($fstream);

//Removing a worksheet using its sheet name

$workbook->getWorksheets()->removeAt("Sheet1");

//Saving the Excel file

$workbook->save($dataDir . "book.out.xls");

//Closing the file stream to free all resources

$fstream->close();

シート インデックスを使用してワークシートを削除する

を使用してシート インデックスごとにワークシートを削除するにはAspose.Cells Java for PHP、単に呼び出すremove_worksheet_by_index方法ワークシートの管理モジュール。

PHP コード

 //Creating a file stream containing the Excel file to be opened

$fstream=new FileInputStream($dataDir . "book.xls");

//Instantiating a Workbook object with the stream

$workbook = new Workbook($fstream);

//Removing a worksheet using its sheet index

$workbook->getWorksheets()->removeAt(0);

//Saving the Excel file

$workbook->save($dataDir . "book.out.xls");

//Closing the file stream to free all resources

$fstream->close();

実行中のコードをダウンロード

ダウンロード**ワークシートの管理 (Aspose.Cells)**以下のソーシャルコーディングサイトのいずれかから: