Yorumları ve Notları Yönetme
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. İlk yöntem, tasarımcı dosyasında manuel olarak yorumlar oluşturmaktır. Bu yorumlar daha sonra Aspose.Cells kullanılarak içe aktarılır. İkinci yöntem, Aspose.Cells API’sını kullanarak çalışma zamanında yorum eklemektir. Bu konu, Aspose.Cells API’sını kullanarak hücrelere yorum eklemeyi tartışmaktadır. Yorumları biçimlendirmek de açıklanacaktır.
Yorum Ekleme
Yeni bir yorum notunu Comments koleksiyonundan alarak Worksheet nesnesine kapsüllenen Comments koleksiyonunun Ekle yöntemini çağırarak bir hücreye yorum ekleyin. Yeni Comment nesnesi, yorum endeksini geçirerek Comments koleksiyonundan erişilebilir. Comment nesnesine erişme sonrasında, Comment nesnesinin Note özelliğini kullanarak yorum notunu özelleştirin.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = ""; | |
// Create directory if it is not already present. | |
File file = new File(dataDir); | |
if(!file.exists()) | |
file.mkdir(); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Adding a new worksheet to the Workbook object | |
int sheetIndex = workbook.getWorksheets().add(); | |
// Obtaining the reference of the newly added worksheet by passing its sheet index | |
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex); | |
// Adding a comment to "F5" cell | |
int commentIndex = worksheet.getComments().add("F5"); | |
// Accessing the newly added comment | |
com.aspose.cells.Comment comment = worksheet.getComments().get(commentIndex); | |
// Setting the comment note | |
comment.setNote( "Hello Aspose!"); | |
// Saving the Excel file | |
workbook.save(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.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = ""; | |
// Create directory if it is not already present. | |
File file = new File(dataDir); | |
if(!file.exists()) | |
file.mkdir(); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Adding a new worksheet to the Workbook object | |
int sheetIndex = workbook.getWorksheets().add(); | |
// Obtaining the reference of the newly added worksheet by passing its sheet index | |
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex); | |
// Adding a comment to "F5" cell | |
int commentIndex = worksheet.getComments().add("F5"); | |
// Accessing the newly added comment | |
com.aspose.cells.Comment 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().setBold(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(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.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = ""; | |
// Create directory if it is not already present. | |
File file = new File(dataDir); | |
if(!file.exists()) | |
file.mkdir(); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Get a reference of comments collection with the first sheet | |
com.aspose.cells.CommentCollection comments = workbook.getWorksheets().get(0).getComments(); | |
// Add a comment to cell A1 | |
int commentIndex = comments.add(0, 0); | |
com.aspose.cells.Comment comment = comments.get(commentIndex); | |
comment.setNote("First note."); | |
comment.getFont().setName("Times New Roman"); | |
// Load an image | |
String filename = dataDir + "image.jpg"; | |
byte[] result = null; | |
java.nio.channels.FileChannel fc = null; | |
try { | |
fc = new java.io.RandomAccessFile(filename, "r").getChannel(); | |
java.nio.MappedByteBuffer byteBuffer = fc.map(java.nio.channels.FileChannel.MapMode.READ_ONLY, 0, | |
fc.size()).load(); | |
System.out.println(byteBuffer.isLoaded()); | |
result = new byte[(int) fc.size()]; | |
if (byteBuffer.remaining() > 0) { | |
byteBuffer.get(result, 0, byteBuffer.remaining()); | |
} | |
} catch (IOException e) { | |
throw e; | |
} finally { | |
try { | |
fc.close(); | |
} catch (IOException e) { | |
throw e; | |
} | |
} | |
// Set image data to the shape associated with the comment | |
comment.getCommentShape().getFill().setImageData(result); | |
// Saving the Excel file | |
workbook.save(dataDir + "book1.out.xlsx"); |