Module: Asposecellsjava::CopyWorksheets

Defined in:
lib/asposecellsjava/copyworksheets.rb

Instance Method Summary collapse

Instance Method Details

#copy_worksheet(workbook) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/asposecellsjava/copyworksheets.rb', line 16

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

#initializeObject



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/asposecellsjava/copyworksheets.rb', line 3

def initialize()
    @data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
    
    # Instantiating a Workbook object by excel file path
    workbook = Rjb::import('com.aspose.cells.Workbook').new(@data_dir + 'Book1.xls')
    
    # Copy Worksheets within a Workbook
    copy_worksheet(workbook)

    # Move Worksheets within Workbook
    move_worksheet(workbook)
end

#move_worksheet(workbook) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/asposecellsjava/copyworksheets.rb', line 29

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