Yorumları ve Notları Yönetin
Giriş
Yorumlar, hücrelere ek bilgi eklemek için kullanılır. Aspose.Cells, hücrelere yorum eklemek için iki yöntem sağlar. İlki, bir tasarımcı dosyasında manuel olarak yorumlar oluşturmaktır. Bu yorumlar daha sonra Aspose.Cells kullanılarak içe aktarılır. İkincisi, çalışma zamanında Aspose.Cells API kullanılarak yorum eklemektir. Bu konuda, Aspose.Cells API kullanılarak hücrelere yorum eklenmesi ele alınmaktadır. Yorumların biçimlendirilmesi de açıklanacaktır.
Yorum Ekleme
öğesini çağırarak bir hücreye yorum ekleyin.Yorumlar koleksiyonunEklemek yöntem (kapsüllenmişÇalışma kağıdı nesne). YeniYorum Yap nesneden erişilebilir.Yorumlar yorum dizinini geçirerek koleksiyon. eriştikten sonraYorum Yap kullanarak yorum notunu özelleştirin.Yorum Yap nesneninNotEmlak.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Adding a new worksheet to the Workbook object | |
int sheetIndex = workbook.Worksheets.Add(); | |
// Obtaining the reference of the newly added worksheet by passing its sheet index | |
Worksheet worksheet = workbook.Worksheets[sheetIndex]; | |
// Adding a comment to "F5" cell | |
int commentIndex = worksheet.Comments.Add("F5"); | |
// Accessing the newly added comment | |
Comment comment = worksheet.Comments[commentIndex]; | |
// Setting the comment note | |
comment.Note = "Hello Aspose!"; | |
// Saving the Excel file | |
workbook.Save(dataDir + "book1.out.xls"); |
Yorum Biçimlendirme
Yükseklik, genişlik ve yazı tipi ayarlarını yapılandırarak yorumların görünümünü biçimlendirmek de mümkündür.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Adding a new worksheet to the Workbook object | |
int sheetIndex = workbook.Worksheets.Add(); | |
// Obtaining the reference of the newly added worksheet by passing its sheet index | |
Worksheet worksheet = workbook.Worksheets[sheetIndex]; | |
// Adding a comment to "F5" cell | |
int commentIndex = worksheet.Comments.Add("F5"); | |
// Accessing the newly added comment | |
Comment comment = worksheet.Comments[commentIndex]; | |
// Setting the comment note | |
comment.Note = "Hello Aspose!"; | |
// Setting the font size of a comment to 14 | |
comment.Font.Size = 14; | |
// Setting the font of a comment to bold | |
comment.Font.IsBold = true; | |
// Setting the height of the font to 10 | |
comment.HeightCM = 10; | |
// Setting the width of the font to 2 | |
comment.WidthCM = 2; | |
// Saving the Excel file | |
workbook.Save(dataDir + "book1.out.xls"); |
Yoruma Resim Ekleyin
Microsoft Excel 2007 ile, bir hücre yorumunun arka planı olarak bir görüntüye sahip olmak da mümkündür. Excel 2007’de bu, aşağıdaki adımlar izlenerek gerçekleştirilir. (Zaten bir hücre yorumu eklediğinizi varsayarlar.)
- Açıklamayı içeren hücreye sağ tıklayın.
- SeçmeYorumları Göster/Gizle, ve yorumdaki tüm metni temizleyin.
- Seçmek için yorumun kenarlığına tıklayın.
- SeçmeBiçim , o zamanlarYorum Yap.
- ÜzerindeRenkler ve Çizgiler sekmesini genişletinRenk liste.
- TıklamakDolgu Efektleri.
- ÜzerindeResim sekme, tıklayınResim Seç.
- Resmi bulun ve seçin.
- TıklamakTamam tüm diyaloglar kapanana kadar.
Aspose.Cells de bu özelliği sağlıyor. Aşağıda, sıfırdan bir XLSX dosyası oluşturan ve “A1” hücresine arka planı resim olarak ayarlanmış bir yorum ekleyen bir kod örneği verilmiştir.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Instantiate a Workbook | |
Workbook workbook = new Workbook(); | |
// Get a reference of comments collection with the first sheet | |
CommentCollection comments = workbook.Worksheets[0].Comments; | |
// Add a comment to cell A1 | |
int commentIndex = comments.Add(0, 0); | |
Comment comment = comments[commentIndex]; | |
comment.Note = "First note."; | |
comment.Font.Name = "Times New Roman"; | |
// Load an image into stream | |
Bitmap bmp = new Bitmap(dataDir + "logo.jpg"); | |
MemoryStream ms = new MemoryStream(); | |
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png); | |
// Set image data to the shape associated with the comment | |
comment.CommentShape.Fill.ImageData = ms.ToArray(); | |
// Save the workbook | |
workbook.Save(dataDir + "book1.out.xlsx", Aspose.Cells.SaveFormat.Xlsx); |