Bu kısa öğretici, Java kullanarak bir slayda nasıl tablo ekleyeceğiniz konusunda size yol gösterir. Uygulamayı yazmak için IDE’yi ayarlamak için gerekli ayrıntıları ve bu görevi gerçekleştirmek için ayrıntılı adımları paylaşır. Sonunda, Java kullanarak PowerPoint’te nasıl tablo oluşturulacağını ve elde edilen sunumu PPTX, PPT olarak diske veya herhangi başka bir diske kaydetmeyi gösteren çalıştırılabilir bir örnek kod alacaksınız. MS PowerPoint veya başka herhangi bir üçüncü taraf aracı yüklemeden desteklenen biçim.
Java kullanarak PowerPoint’te Tablo Ekleme Adımları
- Tablo eklemek için IDE’yi Aspose.Slides kullanacak şekilde ayarlayın
- Presentation sınıfını kullanarak yeni bir sunu oluşturun ve ilk slayda erişin
- addTable() yöntemini kullanarak ve metin konumunu, hücrelerin yüksekliğini ve genişliğini sağlayarak seçili slayda yeni bir tablo ekleyin
- Tüm satırları yineleyin ve yazı tipi ayarlarıyla birlikte metni ayarlayın
- Sunumu, içinde bir tablo bulunan diske kaydedin
Yukarıda belirtilen adımlar, Java kullanılarak PowerPoint’te tabloların nasıl oluşturulacağını açıklar. Görevi gerçekleştirmek için gerekli olan tüm gerekli sınıflar ve yöntemler tanımlanır. Bir tablonun slayda eklendiği ve ardından hücrelerinin bazı örnek metinlerle doldurulduğu işlem basittir.
Java kullanarak PowerPoint’te Tablo Oluşturma Kodu
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package testslides; | |
import com.aspose.slides.BulletType; | |
import com.aspose.slides.ICell; | |
import com.aspose.slides.IRow; | |
import com.aspose.slides.ISlide; | |
import com.aspose.slides.ITable; | |
import com.aspose.slides.ITextFrame; | |
import com.aspose.slides.License; | |
import com.aspose.slides.Presentation; | |
public class AddTable { | |
public static void main(String[] args) throws Exception {//handle exception during adding any tablle | |
String path = "/Users/mudassirkhan/Documents/KnowledgeBase/TestData/"; | |
// Load the product license to create a table | |
License slidesTablelic = new License(); | |
slidesTablelic.setLicense(path + "Conholdate.Total.Product.Family.lic"); | |
// Create a new presentation | |
Presentation presentationForTable = new Presentation(); | |
// Access the first slide in the presentation | |
ISlide slide = presentationForTable.getSlides().get_Item(0); | |
// Define the arrays containing column widths and row heights | |
double[] dColumnsWidths = { 55, 55, 55 }; | |
double[] dRowsHeights = { 55, 36, 36, 36, 36 }; | |
// Add a new table with desired rows and columns | |
ITable newTable = slide.getShapes().addTable(60, 60, dColumnsWidths, dRowsHeights); | |
// Traverse through all the rows | |
for (IRow tableRow : newTable.getRows()) | |
{ | |
// Traverse through all the cells in the current row | |
for (ICell tableCell : tableRow) | |
{ | |
// Access the respective text frame of the cell | |
ITextFrame txtFormat = tableCell.getTextFrame(); | |
// Add some text to the cell | |
int iFirstRowIndex = tableCell.getFirstRowIndex(); | |
int iFirstColumnIndex = tableCell.getFirstColumnIndex(); | |
txtFormat.setText( "Text " + iFirstRowIndex + " " + iFirstColumnIndex); | |
// Set the font related property for the newly added text | |
txtFormat.getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat().setFontHeight(10); | |
txtFormat.getParagraphs().get_Item(0).getParagraphFormat().getBullet().setType(BulletType.None); | |
} | |
} | |
// Save the presentation with table | |
presentationForTable.save("PresentationTable.pptx", com.aspose.slides.SaveFormat.Pptx); | |
System.out.println("Done"); | |
} | |
} |
Bu kod, Java kullanılarak PowerPoint’te nasıl tablo oluşturulacağını gösterir. Farklı özellikleri kullanmak için çoklu arabirim sınıfları kullanılır, örneğin, slayda erişmek için ISlide, tablolarla çalışmak için ITable sınıfı ve tek tek hücrelerle çalışmak için IRow ve ICell sınıfları kullanılır. ITextFrame sınıfı, bir hücredeki metni ayarlamak ve hücrelerin biçimlendirmesini ayarlamak için kullanılan ana arabirimdir.
Bu öğretici bize *Java kullanarak PowerPoint sunumunda nasıl tablo yapılacağını öğretti. Bir sunumdan HTML oluşturma sürecini öğrenmek istiyorsanız, Java kullanarak HTML’de PowerPoint slaytları nasıl oluşturulur? ile ilgili makaleye bakın.