Köprüleri Excel veya OpenOffice'e Ekleme

Bağlantı Verilerine Köprü Ekleme

Köprü Ekleme

Aspose.Cells kullanılarak bir hücreye üç tür köprü eklenebilir:

Aspose.Cells, geliştiricilerin Excel dosyalarına API veyatasarımcı elektronik tabloları(köprülerin manuel olarak oluşturulduğu ve bunları diğer elektronik tablolara aktarmak için Aspose.Cells’in kullanıldığı elektronik tablolar).

Aspose.Cells bir sınıf sağlar,Çalışma kitabı bu bir Microsoft Excel dosyasını temsil eder. buÇalışma kitabısınıf bir içerirÇalışma Sayfası Koleksiyonu Excel dosyasındaki her çalışma sayfasına erişim sağlar. Bir çalışma sayfası şununla temsil edilir:Çalışma kağıdı sınıf. buÇalışma kağıdıclass, Excel dosyalarına farklı köprüler eklemek için farklı yöntemler sağlar.

Bir URL’ye Bağlantı Ekleme

buÇalışma kağıdı sınıf bir içerirköprüler Toplamak. İçindeki her öğeköprüler koleksiyon temsil ederköprü . Çağırarak URL’lere köprüler ekleyinköprüler koleksiyonunEklemekyöntem. buEklemek yöntemi aşağıdaki parametreleri alır:

  • Cell adı, köprünün ekleneceği hücrenin adı.
  • Satır sayısı, bu köprü aralığındaki satır sayısı.
  • Sütun sayısı, bu köprü aralığının sütun sayısı
  • URL, URL adresi.
// 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.getSharedDataDir(AddingLinkToURL.class) + "data/";
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Obtaining the reference of the first worksheet.
WorksheetCollection worksheets = workbook.getWorksheets();
Worksheet sheet = worksheets.get(0);
HyperlinkCollection hyperlinks = sheet.getHyperlinks();
// Adding a hyperlink to a URL at "A1" cell
hyperlinks.add("A1", 1, 1, "http://www.aspose.com");
// Saving the Excel file
workbook.save(dataDir + "AddingLinkToURL_out.xls");
// Print message
System.out.println("Process completed successfully");

Yukarıdaki örnekte, boş bir hücredeki bir URL’ye köprü eklenir,A1Bu gibi durumlarda, bir hücre boşsa URL adresi de o boş hücreye değer olarak eklenir. Hücre boş değilse ve bir köprü eklenirse, hücrenin değeri düz metin gibi görünür. Köprü gibi görünmesini sağlamak için ilgili hücreye uygun biçimlendirme ayarlarını uygulayın.

// 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.getSharedDataDir(AddingLinkToURLNotEmpty.class) + "data/";
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Obtaining the reference of the first worksheet.
WorksheetCollection worksheets = workbook.getWorksheets();
Worksheet sheet = worksheets.get(0);
// Setting a value to the "A1" cell
Cells cells = sheet.getCells();
Cell cell = cells.get("A1");
cell.setValue("Visit Aspose");
// Setting the font color of the cell to Blue
Style style = cell.getStyle();
style.getFont().setColor(Color.getBlue());
// Setting the font of the cell to Single Underline
style.getFont().setUnderline(FontUnderlineType.SINGLE);
cell.setStyle(style);
HyperlinkCollection hyperlinks = sheet.getHyperlinks();
// Adding a hyperlink to a URL at "A1" cell
hyperlinks.add("A1", 1, 1, "http://www.aspose.com");
// Saving the Excel file
workbook.save(dataDir + "AddingLinkToURLNotEmpty_out.xls");

Aynı Dosyada Cell’e Bağlantı Ekleme

Aynı Excel dosyasındaki hücrelere köprüler eklemek mümkündür.köprüler koleksiyonunEklemekyöntem. buEklemek yöntemi hem iç hem de dış köprüler için çalışır. Aşırı yüklenmiş yöntemin bir sürümü aşağıdaki parametreleri alır:

  • Cell adı, köprünün ekleneceği hücrenin adı.
  • Satır sayısı, bu köprü aralığındaki satır sayısı.
  • Sütun sayısı, bu köprü aralığındaki sütun sayısı.
  • URL, hedef hücrenin adresi.
// 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.getSharedDataDir(AddingLinkToAnotherCell.class) + "data/";
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Obtaining the reference of the first worksheet.
WorksheetCollection worksheets = workbook.getWorksheets();
workbook.getWorksheets().add();
Worksheet sheet = worksheets.get(0);
// Setting a value to the "A1" cell
Cells cells = sheet.getCells();
Cell cell = cells.get("A1");
cell.setValue("Visit Aspose");
// Setting the font color of the cell to Blue
Style style = cell.getStyle();
style.getFont().setColor(Color.getBlue());
// Setting the font of the cell to Single Underline
style.getFont().setUnderline(FontUnderlineType.SINGLE);
cell.setStyle(style);
HyperlinkCollection hyperlinks = sheet.getHyperlinks();
// Adding an internal hyperlink to the "B9" cell of the other worksheet "Sheet2" in the same Excel file
hyperlinks.add("B3", 1, 1, "Sheet2!B9");
// Saving the Excel file
workbook.save(dataDir + "ALinkTACell_out.xls");
// Print message
System.out.println("Process completed successfully");

Harici Dosyaya Bağlantı Ekleme

Dış Excel dosyalarına köprüler eklemek mümkündür.köprüler koleksiyonunEklemekyöntem. buEklemek yöntemi aşağıdaki parametreleri alır:

  • Cell adı, köprünün ekleneceği hücrenin adı.
  • Satır sayısı, bu köprü aralığındaki satır sayısı.
  • Sütun sayısı, bu köprü aralığındaki sütun sayısı.
  • URL, hedefin adresi, harici Excel dosyası.
// 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.getSharedDataDir(AddingLinkToExternalFile.class) + "data/";
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Obtaining the reference of the first worksheet.
WorksheetCollection worksheets = workbook.getWorksheets();
Worksheet sheet = worksheets.get(0);
// Setting a value to the "A1" cell
Cells cells = sheet.getCells();
Cell cell = cells.get("A1");
cell.setValue("Visit Aspose");
// Setting the font color of the cell to Blue
Style style = cell.getStyle();
style.getFont().setColor(Color.getBlue());
// Setting the font of the cell to Single Underline
style.getFont().setUnderline(FontUnderlineType.SINGLE);
cell.setStyle(style);
HyperlinkCollection hyperlinks = sheet.getHyperlinks();
// Adding a link to the external file
hyperlinks.add("A5", 1, 1, dataDir + "book1.xls");
// Saving the Excel file
workbook.save(dataDir + "ALToEFile_out.xls");
// Print message
System.out.println("Process completed successfully");

ileri konular