Ten krótki samouczek zawiera instrukcje jak wstawić tabelę do slajdu przy użyciu języka Java. Udostępnia niezbędne szczegóły, aby ustawić IDE do pisania aplikacji i szczegółowe kroki, aby wykonać to zadanie. Na koniec otrzymasz działający przykładowy kod, który demonstruje jak utworzyć tabelę w PowerPoint przy użyciu Javy i zapisać wynikową prezentację na dysku jako PPTX, PPT lub w dowolnym innym obsługiwanego formatu bez instalowania programu MS PowerPoint ani żadnego innego narzędzia innej firmy.
Kroki, aby dodać tabelę w programie PowerPoint przy użyciu języka Java
- Ustaw IDE, aby używało Aspose.Slides do wstawiania tabeli
- Utwórz nową prezentację za pomocą klasy Presentation i uzyskaj dostęp do pierwszego slajdu
- Dodaj nową tabelę na wybranym slajdzie metodą addTable() i podając położenie tekstu oraz wysokość i szerokość komórek
- Przejrzyj wszystkie wiersze i ustaw tekst wraz z ustawieniami czcionki
- Zapisz prezentację na dysku z tabelą
Powyższe kroki wyjaśniają jak tworzyć tabele w programie PowerPoint przy użyciu języka Java. Zidentyfikowane są wszystkie niezbędne klasy i metody, które są wymagane do wykonania zadania. Proces jest prosty: tabela jest dodawana do slajdu, a następnie jej komórki są wypełniane przykładowym tekstem.
Kod do tworzenia tabeli w programie PowerPoint przy użyciu języka Java
/* | |
* 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"); | |
} | |
} |
Ten kod demonstruje jak utworzyć tabelę w programie PowerPoint przy użyciu języka Java. Wiele klas interfejsów jest używanych do korzystania z różnych funkcji, np. ISlide służy do uzyskiwania dostępu do slajdu, klasa ITable służy do pracy z tabelami, a klasy IRow i ICell służą do pracy z poszczególnymi komórkami. Klasa ITextFrame jest głównym interfejsem służącym do ustawiania tekstu w komórce i ustawiania formatowania komórek.
Ten samouczek nauczył nas * tworzenia tabeli w prezentacji PowerPoint przy użyciu języka Java *. Jeśli chcesz poznać proces tworzenia kodu HTML z prezentacji, zapoznaj się z artykułem na temat jak tworzyć slajdy programu PowerPoint w formacie HTML przy użyciu języka Java.