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 elektron mikroskobuna resim eklemek çok kolaydır. Sadece birkaç satır kod gerektirir: Basitçe, Pictures noktasal nesnesinde kapsüllenmiş olan Worksheet nesnesinin Add metodunu çağırın. Add metodu 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-.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 picture at the location of a cell whose row and column indices
// Are 5 in the worksheet. It is "F6" cell
worksheet.Pictures.Add(5, 5, dataDir + "logo.jpg");
// Saving the Excel file
workbook.Save(dataDir + "output.xls");

Resim Konumlandırma

Aspose.Cells kullanarak resimlerin konumlandırılmasını kontrol etmek için iki olası yol bulunmaktadır:

  • Oransal konumlandırma: satır yüksekliği ve genişliğine oranla bir konum tanımlayın.
  • Mutlak konumlandırma: resmin sayfaya yerleştirileceği kesin konumu tanımlayın, örneğin, hücrenin sol üstünden 40 piksel ve altından 20 piksel aşağıda.

Oransal Konumlandırma

Geliştiriciler, resimleri Aspose.Cells.Drawing.Picture nesnesinin UpperDeltaX ve UpperDeltaY özelliklerini kullanarak satır yüksekliğine ve sütun genişliğine oransal olarak konumlandırabilirler. Bir Picture nesnesi, resmin dizinini geçirerek Pictures koleksiyonundan alınabilir. Bu örnek, bir resmi F6 hücresine yerleştirir.

// 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 picture at the location of a cell whose row and column indices
// Are 5 in the worksheet. It is "F6" cell
int pictureIndex = worksheet.Pictures.Add(5, 5, dataDir + "logo.jpg");
// Accessing the newly added picture
Aspose.Cells.Drawing.Picture picture = worksheet.Pictures[pictureIndex];
// Positioning the picture proportional to row height and colum width
picture.UpperDeltaX = 200;
picture.UpperDeltaY = 200;
// Saving the Excel file
workbook.Save(dataDir + "book1.out.xls");

Mutlak Konumlandırma

Geliştiriciler, resimleri Picture nesnesinin Left ve Top özelliklerini kullanarak mutlak olarak da konumlandırabilirler. Bu örnek, resmi F6 hücresine sol üstten 60 piksel ve üstten 10 piksel uzaklığa yerleştirir.

// 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);
// 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 picture at the location of a cell whose row and column indices
// Are 5 in the worksheet. It is "F6" cell
int pictureIndex = worksheet.Pictures.Add(5, 5, dataDir + "logo.jpg");
// Accessing the newly added picture
Aspose.Cells.Drawing.Picture picture = worksheet.Pictures[pictureIndex];
// Absolute positioning of the picture in unit of pixels
picture.Left = 60;
picture.Top = 10;
// Saving the Excel file
workbook.Save(dataDir + "book1.out.xls");

Hücre Referansına Dayalı Resim Ekleme

Aspose.Cells, bir çalışma sayfası hücresinin içeriğini bir görüntü şeklinde görüntülemenizi sağlar. Verilerin görüntülenmesini istediğiniz hücreye bağlayabilirsiniz. Hücre veya hücre aralığı grafik nesnesine bağlandığından, o hücre veya hücre aralığındaki değişiklikler otomatik olarak grafik nesnesinde görünür.

Resmi Worksheet nesnesine kapsüllenmiş olan ShapeCollection koleksiyonunun AddPicture yöntemini çağırarak çalışma sayfasına ekleyin. Formula nesnesinin Picture özelliğini kullanarak hücre aralığını belirtin.

// 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);
// Instantiate a new Workbook
Workbook workbook = new Workbook();
// Get the first worksheet's cells collection
Cells cells = workbook.Worksheets[0].Cells;
// Add string values to the cells
cells["A1"].PutValue("A1");
cells["C10"].PutValue("C10");
// Add a blank picture to the D1 cell
Picture pic = workbook.Worksheets[0].Shapes.AddPicture(0, 3, 10, 6, null);
// Specify the formula that refers to the source range of cells
pic.Formula = "A1:C10";
// Update the shapes selected value in the worksheet
workbook.Worksheets[0].Shapes.UpdateSelectedValue();
// Save the Excel file.
workbook.Save(dataDir + "output.out.xls");

Gelişmiş Konular