Ovaj kratki vodič vas vodi o tome kako umetnuti tablicu u slajd pomoću Jave. Dijeli potrebne pojedinosti za postavljanje IDE-a za pisanje aplikacije i detaljne korake za izvođenje ovog zadatka. Na kraju ćete dobiti primjer koda koji se može izvoditi i koji pokazuje kako napraviti tablicu u PowerPointu pomoću Jave i spremanje rezultirajuće prezentacije na disk kao PPTX, PPT ili na bilo koji drugi podržani format bez instaliranja MS PowerPointa ili bilo kojeg drugog alata treće strane.
Koraci za dodavanje tablice u PowerPoint pomoću Jave
- Postavite IDE da koristi Aspose.Slides za umetanje tablice
- Napravite novu prezentaciju pomoću klase Presentation i ostvarite pristup prvom slajdu
- Dodajte novu tablicu u odabrani slajd pomoću metode addTable() i navedite položaj teksta, te visinu i širinu ćelija
- Iterirajte kroz sve retke i postavite tekst zajedno s postavkama fonta
- Spremite prezentaciju na disk s tablicom
Prethodno navedeni koraci objašnjavaju kako stvoriti tablice u programu PowerPoint pomoću Jave. Identificirane su sve potrebne klase i metode koje su potrebne za postizanje zadatka. Proces je jednostavan kada se tablica dodaje na slajd, a zatim se njezine ćelije popune uzorkom teksta.
Kod za izradu tablice u programu PowerPoint pomoću Jave
/* | |
* 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"); | |
} | |
} |
Ovaj kôd pokazuje kako stvoriti tablicu u PowerPointu pomoću Jave. Više klasa sučelja koristi se za korištenje različitih značajki, npr. ISlide se koristi za pristup slajdu, klasa ITable koristi se za rad s tablicama, a klase IRow i ICell koriste se za rad s pojedinačnim ćelijama. Klasa ITextFrame je glavno sučelje koje se koristi za postavljanje teksta u ćeliju i postavljanje formatiranja ćelija.
Ovaj vodič nas je naučio kako napraviti tablicu u PowerPoint prezentaciji koristeći Javu. Ako želite naučiti postupak stvaranja HTML-a iz prezentacije, pogledajte članak na kako stvoriti PowerPoint slajdove u HTML-u pomoću Jave.