Node.js ile C++ üzerinden Yorumlar ve Notlar Yönetimi
Giriş
Yorumlar, hücrelere ek bilgi eklemek için kullanılır. Aspose.Cells for Node.js via C++, hücrelere yorum eklemek için iki yöntem sunar. Birincisi, tasarımcı dosyasında manuel olarak yorumlar oluşturmaktır. Bu yorumlar, Aspose.Cells kullanılarak içe aktarılır. İkincisi ise, Aspose.Cells API kullanılarak çalışma zamanında yorum eklemektir. Bu konu, Aspose.Cells API kullanarak hücrelere yorum eklemeyi tartışır. Yorumların biçimlendirilmesi de açıklanacaktır.
Yorum Ekleme
Yorum eklemek için Comments koleksiyonunun CommentCollection.add(number, number) metodunu çağırın ({2} nesnesinde kapsüllenmiş). Yeni Comment nesnesine, yorum dizinine geçerek erişilebilir. Comments nesnesine eriştikten sonra, yorumu özelleştirmek için getNote() özelliği kullanılır.
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
// Instantiating a Workbook object
const workbook = new AsposeCells.Workbook();
// Adding a new worksheet to the Workbook object
const sheetIndex = workbook.getWorksheets().add();
// Obtaining the reference of the newly added worksheet by passing its sheet index
const worksheet = workbook.getWorksheets().get(sheetIndex);
// Adding a comment to "F5" cell
const commentIndex = worksheet.getComments().add("F5");
// Accessing the newly added comment
const comment = worksheet.getComments().get(commentIndex);
// Setting the comment note
comment.setNote("Hello Aspose!");
// Saving the Excel file
workbook.save(path.join(dataDir, "book1.out.xls"));
Yorum Biçimlendirme
Yorumların görünümünü yükseklik, genişlik ve yazı tipi ayarlarıyla biçimlendirmek de mümkündür.
const fs = require("fs");
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
// Instantiating a Workbook object
const workbook = new AsposeCells.Workbook();
// Adding a new worksheet to the Workbook object
const sheetIndex = workbook.getWorksheets().add();
// Obtaining the reference of the newly added worksheet by passing its sheet index
const worksheet = workbook.getWorksheets().get(sheetIndex);
// Adding a comment to "F5" cell
const commentIndex = worksheet.getComments().add("F5");
// Accessing the newly added comment
const comment = worksheet.getComments().get(commentIndex);
// Setting the comment note
comment.setNote("Hello Aspose!");
// Setting the font size of a comment to 14
comment.getFont().setSize(14);
// Setting the font of a comment to bold
comment.getFont().setIsBold(true);
// Setting the height of the font to 10
comment.setHeightCM(10);
// Setting the width of the font to 2
comment.setWidthCM(2);
// Saving the Excel file
workbook.save(path.join(dataDir, "book1.out.xls"));
Yoruma Resim Ekle
Microsoft Excel 2007 ile, bir hücre yorumuna arka plan olarak bir resim eklemek de mümkündür. Excel 2007’de bunu aşağıdaki adımları takip ederek başarabilirsiniz. (Zaten bir hücre yorumu eklediğinizi varsayarlar.)
- Yorum içeren hücreye sağ tıklayın.
- Yorumları Göster/Gizle‘yi seçin ve yorumdan herhangi bir metni temizleyin.
- Yorumun kenarına tıklayın.
- Biçim, ardından Yorum‘u seçin.
- Renk ve Çizgiler sekmesinde, Renk listesini genişletin.
- Dolgu Efektleri‘ni tıklayın.
- Resim sekmesinde, Resim Seç‘i tıklayın.
- Resmi bulun ve seçin.
- Tüm iletiler kapatılıncaya kadar Tamam‘ı tıklayın.
Aspose.Cells ayrıca bu özelliği sağlar. Aşağıda, sıfırdan XLSX dosyası oluşturan ve “A1” hücresine resimli bir arka plan ekleyen bir kod örneği bulunmaktadır.
const path = require("path");
const fs = require("fs");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
// Instantiate a Workbook
const workbook = new AsposeCells.Workbook();
// Get a reference of comments collection with the first sheet
const comments = workbook.getWorksheets().get(0).getComments();
// Add a comment to cell A1
const commentIndex = comments.add(0, 0);
const comment = comments.get(commentIndex);
comment.setNote("First note.");
comment.getFont().setName("Times New Roman");
// Load an image into stream
const bmpPath = path.join(dataDir, "logo.jpg");
const bmpData = fs.readFileSync(bmpPath);
// Set image data to the shape associated with the comment
comment.getCommentShape().getFill().setImageData(bmpData);
// Save the workbook
workbook.save(path.join(dataDir, "book1.out.xlsx"), AsposeCells.SaveFormat.Xlsx);