Resim Yönetimi
Aspose.Cells, geliştiricilere çalışma zamanında elektron mikroskobu resimlerini elektron mikroskobuna eklemelerine olanak tanır. Dahası, bu resimlerin konumu çalışma zamanında kontrol edilebilir, bu daha sonra detaylı olarak tartışılacaktır.
Bu makale, resim eklemenin ve belirli hücrelerin içeriğini gösteren bir resmin nasıl eklenmesinin açıklamasını içerir.
Resim Ekleme
Bir çalışma kitabına resim eklemek çok kolaydır. Sadece birkaç satır kod gerektirir.
Sadece Worksheet nesnesine kapsüllenmiş olan Pictures koleksiyonunun add yöntemini çağırın. add yöntemi aşağıdaki parametreleri alır:
- Sol üst satır dizini, sol üst sütunun dizini.
- Sol üst sütun dizini, sol üst sütunun dizini.
- Resim dosya adı, yol bilgisi ile birlikte resim dosyasının adı.
// 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 = Utils.getDataDir(AddingPictures.class); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
WorksheetCollection worksheets = workbook.getWorksheets(); | |
// Obtaining the reference of first worksheet | |
Worksheet sheet = worksheets.get(0); | |
// Adding a picture at the location of a cell whose row and column indices are 5 in the worksheet. It is "F6" cell | |
int pictureIndex = sheet.getPictures().add(5, 5, dataDir + "logo.jpg"); | |
Picture picture = sheet.getPictures().get(pictureIndex); | |
// Saving the Excel file | |
workbook.save(dataDir + "book1.xls"); |
Resimlerin Konumlandırılması
Resimler, Aspose.Cells kullanılarak aşağıdaki gibi konumlandırılabilir:
Mutlak Konumlandırma
Geliştiriciler, resimleri setUpperDeltaX ve setUpperDeltaY yöntemlerini kullanarak mutlak olarak konumlandırabilirler.
// 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 = Utils.getDataDir(AbsolutePositioning.class); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Obtaining the reference of the newly added worksheet. | |
int sheetIndex = workbook.getWorksheets().add(); | |
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex); | |
// Adding a picture at the location of a cell whose row and column indices are 5 in the worksheet. It is "F6" cell | |
int pictureIndex = worksheet.getPictures().add(5, 5, dataDir + "logo.jpg"); | |
Picture picture = worksheet.getPictures().get(pictureIndex); | |
// Positioning the picture proportional to row height and colum width | |
picture.setUpperDeltaX(200); | |
picture.setUpperDeltaY(200); | |
// Saving the Excel file | |
workbook.save(dataDir + "test_pictures.xls"); |