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.
- Dosya menüsünden Bilgi‘yi seçin.
Bilgi Menüsünü Seçme |
---|
![]() |
- Özellikler başlığına tıklayıp “Gelişmiş Özellikler”‘i seçin.
Gelişmiş Özellikler Seçimini Tıklama |
---|
![]() |
- Dosyanın belge özelliklerini yönetin.
Özellikler İletişim Kutusu |
---|
![]() |
Ö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.
Aspose.Cells for Node.js via C++, çıktı belgelerine API ve Sürüm Numarası bilgilerini doğrudan yazar. Örneğin, belgeyi PDF olarak dışa aktarırken, Aspose.Cells for Node.js via C++ Uygulama alanını ‘Aspose.Cells’ değeriyle doldurur ve PDF Üreticisi alanını, örneğin ‘Aspose.Cells v17.9’ ile doldurur.
Lütfen dikkat edin, Aspose.Cells for Node.js via C++‘ye çıktı Belgelerinden bu bilgiyi değiştirmesini veya kaldırmasını söyleyemezsiniz.
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.
- Hazır belge özelliklerine ulaşmak için WorksheetCollection.getBuiltInDocumentProperties() kullanın.
- Özel belge özelliklerine ulaşmak için WorksheetCollection.getCustomDocumentProperties() 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:
- Özellik adını almak için DocumentProperty.getName() kullanın.
- Özellik değerini almak için DocumentProperty.getValue(). DocumentProperty.getValue() değeri bir Nesne olarak döndürür.
- Özellik türünü almak için DocumentProperty.getType(). Bu, PropertyType sıralama değeri içinden birini döndürür. Özellik türünü aldıktan sonra, uygun değeri almak için DocumentProperty.ToXXX metodlarından birini kullanın; DocumentProperty.getValue() kullanmak yerine. DocumentProperty.ToXXX metodları aşağıdaki tabloda açıklanmıştır.
Ü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"));