Module: Asposecellsjava::ManagingWorksheets
- Defined in:
- lib/asposecellsjava/managingworksheets.rb
Instance Method Summary collapse
- #add_worksheet ⇒ Object
- #add_worksheet_to_designer_spreadsheet ⇒ Object
- #get_worksheet ⇒ Object
- #initialize ⇒ Object
- #remove_worksheet_by_index ⇒ Object
- #remove_worksheet_by_name ⇒ Object
Instance Method Details
#add_worksheet ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/asposecellsjava/managingworksheets.rb', line 22 def add_worksheet() # Instantiating a Workbook object workbook = Rjb::import('com.aspose.cells.Workbook').new # Adding a new worksheet to the Workbook object worksheets = workbook.getWorksheets() sheet_index = worksheets.add() worksheet = worksheets.get(sheet_index) # Setting the name of the newly added worksheet worksheet.setName("My Worksheet") # Saving the modified Excel file in default (that is Excel 2003) format workbook.save(@data_dir + "book.out.xls") puts "Sheet added successfully." end |
#add_worksheet_to_designer_spreadsheet ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/asposecellsjava/managingworksheets.rb', line 41 def add_worksheet_to_designer_spreadsheet() # Creating a file stream containing the Excel file to be opened fstream = IO.sysopen(@data_dir + 'book1.xls', "w") # Instantiating a Workbook object with the stream workbook = Rjb::import('com.aspose.cells.Workbook').new(fstream) # Adding a new worksheet to the Workbook object worksheets = workbook.getWorksheets() sheet_index = worksheets.add() worksheet = worksheets.get(sheet_index) # Setting the name of the newly added worksheet worksheet.setName("My Worksheet") # Saving the modified Excel file in default (that is Excel 2003) format workbook.save(@data_dir + "book1.out.xls") end |
#get_worksheet ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/asposecellsjava/managingworksheets.rb', line 60 def get_worksheet() # Creating a file stream containing the Excel file to be opened fstream = IO.sysopen(@data_dir + 'book1.xls', "w") # Instantiating a Workbook object with the stream workbook = Rjb::import('com.aspose.cells.Workbook').new(fstream) # Accessing a worksheet using its sheet name worksheet = workbook.getWorksheets().get("Sheet1") puts worksheet.to_string end |
#initialize ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/asposecellsjava/managingworksheets.rb', line 3 def initialize() @data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/' # Adding Worksheets to a New Excel File add_worksheet(workbook) # Adding Worksheets to a Designer Spreadsheet add_worksheet_to_designer_spreadsheet() # Accessing Worksheets using Sheet Name get_worksheet() # Removing Worksheets using Sheet Name remove_worksheet_by_name() # Removing Worksheets using Sheet Name remove_worksheet_by_index() end |
#remove_worksheet_by_index ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/asposecellsjava/managingworksheets.rb', line 90 def remove_worksheet_by_index() # Creating a file stream containing the Excel file to be opened fstream = IO.sysopen(@data_dir + 'book1.xls', "w") # Instantiating a Workbook object with the stream workbook = Rjb::import('com.aspose.cells.Workbook').new(fstream) # Removing a worksheet using its sheet name workbook.getWorksheets().removeAt(0) # Saving the Excel file workbook.save(@data_dir + "book.out.xls") # Print Message puts "Sheet removed successfully." end |
#remove_worksheet_by_name ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/asposecellsjava/managingworksheets.rb', line 73 def remove_worksheet_by_name() # Creating a file stream containing the Excel file to be opened fstream = IO.sysopen(@data_dir + 'book1.xls', "w") # Instantiating a Workbook object with the stream workbook = Rjb::import('com.aspose.cells.Workbook').new(fstream) # Removing a worksheet using its sheet name workbook.getWorksheets().removeAt("Sheet1") # Saving the Excel file workbook.save(@data_dir + "book.out.xls") # Print Message puts "Sheet removed successfully." end |