Belge Özelliklerini Node.js ile C++ kullanarak yönetin

Giriş

Microsoft Excel, elektronik tablo dosyalarına özellik eklemek için yetenek sunmaktadır. Bu belge özellikleri kullanışlı bilgiler sağlar ve ayrıntıları aşağıdaki gibi 2 kategoriye ayrılmıştır.

  • Sistem tanımlı (hazır) özellikler: Hazır özellikler belge başlığı, yazar adı, belge istatistikleri gibi belge hakkında genel bilgiler içerir.
  • Kullanıcı tanımlı (özel) özellikler: Kullanıcı tanımlı özellikler son kullanıcı tarafından ad-değer çifti şeklinde tanımlanan özelleştirilmiş özelliklerdir.

Microsoft Excel ile Belge Portalları Nasıl Yönetilir

Microsoft Excel, Excel dosyalarının belge özelliklerini WYSIWYG tarzında yönetmenize olanak tanır. Lütfen Excel 2016’da Özellikler diyaloğunu açmak için aşağıdaki adımları izleyiniz.

  1. Dosya menüsünden Bilgi‘yi seçin.
Bilgi Menüsünü Seçme
todo:image_alt_text
  1. Özellikler başlığına tıklayıp “Gelişmiş Özellikler”‘i seçin.
Gelişmiş Özellikler Seçimini Tıklama
todo:image_alt_text
  1. Dosyanın belge özelliklerini yönetin.
Özellikler İletişim Kutusu
todo:image_alt_text
Özellikler iletişim kutusunda Genel, Özet, İstatistikler, İçerik ve Gümrük gibi farklı sekmeler bulunur. Her sekme, dosya ile ilgili farklı türde bilgileri yapılandırmaya yardımcı olur. Gümrük sekmesi, özel özellikleri yönetmek için kullanılır.

Aspose.Cells Kullanarak Belge Portalları İle Nasıl Çalışılır

Geliştiriciler, Aspose.Cells ara yüz yöntemleri kullanarak belge portal değişkenlerini dinamik olarak yönetebilirler. Bu özellik, geliştiricilere dosya ile birlikte alınan bilgiyi depolama olanağı sağlar, örneğin dosyanın ne zaman alındığı, işlendiği, zaman damgalandığı v.b.

Belge Portallarına Erişim Yöntemleri

Aspose.Cells API’leri, hem yerleşik hem de özel belge özelliklerini destekler. Aspose.Cells’in Workbook sınıfı, bir Excel dosyasını temsil eder ve tıpkı bir Excel dosyası gibi, Workbook sınıfı birçok çalışma sayfası içerebilir ve her biri Worksheet sınıfıyla temsil edilir; çalışma sayfaları koleksiyonu ise WorksheetCollection sınıfı tarafından temsil edilir.

Dosyanın belge özelliklerine aşağıda anlatıldığı gibi erişmek için WorksheetCollection kullanın.

Hem WorksheetCollection.getBuiltInDocumentProperties() hem de WorksheetCollection.getCustomDocumentProperties(), Aspose.Cells.Properties.DocumentPropertyCollection örneğinde gösterildiği gibi Aspose.Cells.Properties.DocumentPropertyCollection örneğinin örneğini döndürür. Bu koleksiyon, her biri tek bir yerleşik veya özel belge özelliğini temsil eden Aspose.Cells.Properties.DocumentProperty nesnesinden oluşur.

Bir özelliğe erişmek uygulama gereksinimlerine bağlıdır; yani, örneğin DocumentPropertyCollection ile gösterildiği gibi, özelliğin indeks veya adını kullanabilirsiniz.

const path = require("path");
const AsposeCells = require("aspose.cells.node");

// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "sample-document-properties.xlsx");
// Instantiate a Workbook object
// Open an Excel file
const workbook = new AsposeCells.Workbook(filePath);

// Retrieve a list of all custom document properties of the Excel file
const customProperties = workbook.getCustomDocumentProperties();

// Accessing a custom document property by using the property name
const customProperty1 = customProperties.get("ContentTypeId");
console.log(`${customProperty1.getName()} ${customProperty1.getValue()}`);

// Accessing the same custom document property by using the property index
const customProperty2 = customProperties.get(0);
console.log(`${customProperty2.getName()} ${customProperty2.getValue()}`);

Aspose.Cells.Properties.DocumentProperty sınıfı, belge özelliğinin adını, değerini ve türünü almak için izin verir:

Üye Adı Açıklama ToXXX Yöntemi
Boolean Özellik veri türü Boolean’dır ToBool
Date Özellik veri türü DateTime’dir. Microsoft Excel’in bu tür özel bir özelliğinde sadece tarih kısmının saklandığına dikkat edin, zaman saklanamaz ToDateTime
Float Özellik veri türü Double’dır ToDouble
Number Özellik veri türü Int32’dir ToInt
String Özellik veri tipi string ToString
const path = require("path");
const AsposeCells = require("aspose.cells.node");

// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "sample-document-properties.xlsx");
// Instantiate a Workbook object
// Open an Excel file
const workbook = new AsposeCells.Workbook(filePath);

// Retrieve a list of all custom document properties of the Excel file
const customProperties = workbook.getCustomDocumentProperties();

// Accessing a custom document property
const customProperty1 = customProperties.get(0);

// Storing the value of the document property as an object
const objectValue = customProperty1.getValue();

// Accessing a custom document property
const customProperty2 = customProperties.get(1);

// Checking the type of the document property and then storing the value of the
// document property according to that type
if (customProperty2.getType() === AsposeCells.PropertyType.String) {
const value = customProperty2.getValue().toString();
console.log(`${customProperty2.getName()} : ${value}`);
}

Özel Belge Özellikleri Nasıl Eklenir veya Kaldırılır

Bu konunun başında daha önce açıkladığımız gibi, geliştiriciler yerleşik özellikler ekleyemez veya kaldıramaz çünkü bu özellikler sistem tanımlıdır, ancak kullanıcı tanımlı olduğu için özel özellikler eklemek veya kaldırmak mümkündür.

Özel Özellikler Nasıl Eklenir

Aspose.Cells API’leri, koleksiyonlara özel özellikler eklemek için add(string, string) metodunu CustomDocumentPropertyCollection sınıfı ile açığa çıkarmıştır. add(string, string) metodu, özelliği Excel dosyasına ekler ve yeni belge özelliğine referans olarak bir Aspose.Cells.Properties.DocumentProperty nesnesi döner.

const path = require("path");
const AsposeCells = require("aspose.cells.node");

// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
// Instantiate a Workbook object
// Open an Excel file
const workbook = new AsposeCells.Workbook(path.join(dataDir, "sample-document-properties.xlsx"));

// Retrieve a list of all custom document properties of the Excel file
const customProperties = workbook.getCustomDocumentProperties();

// Adding a custom document property to the Excel file
customProperties.add("Publisher", "Aspose");

// Saving resultant spreadsheet
workbook.save(path.join(dataDir, "out_sample-document-properties.xlsx"));

“İçeriğe bağlantı” Özel Özelliğin Yapılandırılması Nasıl Yapılır

Belirli bir alanın içeriğiyle bağlantılı özel bir özellik oluşturmak için CustomDocumentPropertyCollection.addLinkToContent(string, string) metodunu çağırın ve özellik adını ve kaynağını iletin. Bir özelliğin içeriğe bağlı olarak yapılandırılıp yapılandırılmadığını DocumentProperty.isLinkedToContent() özelliği ile kontrol edebilirsiniz. Ayrıca, getSource() özelliği kullanılarak kaynak alan alınabilir ve DocumentProperty sınıfının.

Örneğin basit bir şablon Microsoft Excel dosyası kullanıyoruz. Çalışma kitabında, MyRange olarak etiketlenmiş tanımlanan bir adlandırılmış aralık, bir hücre değerine atıfta bulunur.

const path = require("path");
const AsposeCells = require("aspose.cells.node");

// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
// Instantiate an object of Workbook
// Open an Excel file
const workbook = new AsposeCells.Workbook(path.join(dataDir, "sample-document-properties.xlsx"));

// Retrieve a list of all custom document properties of the Excel file
const customProperties = workbook.getWorksheets().getCustomDocumentProperties();

// Add link to content.
customProperties.addLinkToContent("Owner", "MyRange");

// Accessing the custom document property by using the property name
const customProperty1 = customProperties.get("Owner");

// Check whether the property is linked to content
const isLinkedToContent = customProperty1.isLinkedToContent();

// Get the source for the property
const source = customProperty1.getSource();

// Save the file
workbook.save(path.join(dataDir, "out_sample-document-properties.xlsx"));

Özel Özellikler Nasıl Kaldırılır

Aspose.Cells kullanarak özel özellikleri kaldırmak için, DocumentPropertyCollection.remove(string) metodunu çağırın ve kaldırılacak belge özelliği adını iletin.

const path = require("path");
const AsposeCells = require("aspose.cells.node");

// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
// Instantiate a Workbook object
// Open an Excel file
const workbook = new AsposeCells.Workbook(path.join(dataDir, "sample-document-properties.xlsx"));

// Retrieve a list of all custom document properties of the Excel file
const customProperties = workbook.getCustomDocumentProperties();

// Removing a custom document property
customProperties.remove("Publisher");

// Save the file
workbook.save(path.join(dataDir, "out_sample-document-properties.xlsx"));

Gelişmiş Konular