在Ruby中复制和移动工作表

Aspose.Cells - 复制和移动工作表

在工作簿内复制工作表

要在Ruby中使用Aspose.Cells for Java复制工作表,调用copyworksheets模块的copy_worksheet方法。下面是代码示例。

Ruby 代码

 def copy_worksheet(workbook)

    # Create a Worksheets object with reference to the sheets of the Workbook.

    sheets = workbook.getWorksheets()

    # Copy data to a new sheet from an existing sheet within the Workbook.

    sheets.addCopy("Sheet1")

    # Saving the modified Excel file in default (that is Excel 2003) format

    workbook.save(@data_dir + "Copy Worksheet.xls")

    puts "Copy worksheet, please check the output file."

end 

在工作簿内移动工作表

要在Ruby中使用Aspose.Cells for Java移动工作表,调用copyworksheets模块的move_worksheet方法。下面是代码示例。

Ruby 代码

 def move_worksheet(workbook)

    # Get the first worksheet in the book.

    sheet = workbook.getWorksheets().get(0)

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

    sheet.moveTo(2)

    # Saving the modified Excel file in default (that is Excel 2003) format

    workbook.save(@data_dir + "Move Worksheet.xls")

    puts "Move worksheet, please check the output file."

end 

下载运行代码

从以下任何社交编程网站下载复制和移动工作表(Aspose.Cells)