Hantera dokumentegenskaper i Ruby

Aspose.Cells - Åtkomst till dokumentegenskaper

Utvecklare kan använda sig avIndexellernamn av fastigheten för att få en specifik fastighet från enanpassade_egenskaperinsamling som visas nedan i exemplet.

Ruby kod

 def get_properties()

    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')

    # Retrieve a list of all custom document properties of the Excel file

    custom_properties = workbook.getWorksheets().getCustomDocumentProperties()

    # Accessng a custom document property by using the property index

    puts "Property By Index: " +  custom_properties.get(1).to_string

    # Accessng a custom document property by using the property name

    puts "Property By Name: " + custom_properties.get("Publisher").to_string

end

Aspose.Cells - Lägga till anpassade egenskaper

För att lägga till anpassade dokumentegenskaper med Aspose.Cells Java för Ruby, ringadd_custom_property metod förDokumentera modul.

Ruby kod

 def add_custom_property()

    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')

    # Retrieve a list of all custom document properties of the Excel file

    custom_properties = workbook.getWorksheets().getCustomDocumentProperties()

    # Adding a custom document property to the Excel file

    custom_properties.add("Publisher", "Aspose")

    # Save the document in PDF format

    workbook.save(data_dir + "Add_Property.xls")

    puts "Added custom property successfully."

end   

Aspose.Cells - Ta bort anpassade egenskaper

För att ta bort anpassade dokumentegenskaper med Aspose.Cells Java för Ruby, ringremove_custom_property metod förDokumentera modul.

Ruby kod

 def remove_custom_property()

    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')

    # Retrieve a list of all custom document properties of the Excel file

    custom_properties = workbook.getWorksheets().getCustomDocumentProperties()

    # Adding a custom document property to the Excel file

    custom_properties.remove("Publisher")

    # Save the document in PDF format

    workbook.save(data_dir + "Removed_Property.xls")

    puts "Removed custom property successfully."

end   

Ladda ner Running Code

Ladda ner**Åtkomst till dokumentegenskaper (Aspose.Cells)**från någon av nedan nämnda webbplatser för social kodning: