Kaip įterpti lentelę į skaidrę naudojant Java

Ši trumpa pamoka padės kaip įterpti lentelę skaidrėje naudojant Java. Jame dalijamasi reikalinga informacija, kad būtų galima nustatyti IDE programai rašyti, ir išsamiais šios užduoties atlikimo veiksmais. Galų gale gausite paleidžiamo kodo pavyzdį, kuris parodys kaip sukurti lentelę PowerPoint naudojant Java ir išsaugoti gautą pristatymą diske kaip PPTX, PPT arba bet kurioje kitoje. palaikomą formatą neįdiegę MS PowerPoint ar bet kokio kito trečiosios šalies įrankio.

Veiksmai, kaip pridėti lentelę „PowerPoint“ naudojant „Java“.

  1. Nustatykite IDE, kad įterpiant lentelę naudotų Aspose.Slides
  2. Sukurkite naują pristatymą naudodami Presentation klasę ir gaukite prieigą prie pirmosios skaidrės
  3. Pridėkite naują lentelę pasirinktoje skaidrėje naudodami addTable() metodą ir nurodydami teksto padėtį bei langelių aukštį ir plotį
  4. Pakartokite visas eilutes ir nustatykite tekstą kartu su šrifto nustatymais
  5. Išsaugokite pristatymą diske, kuriame yra lentelė

Pirmiau minėti veiksmai paaiškina kaip kurti lenteles PowerPoint naudojant Java. Nurodytos visos reikalingos klasės ir metodai, kurių reikia užduočiai atlikti. Procesas yra paprastas, kai prie skaidrės pridedama lentelė, o tada jos langeliai užpildomi pavyzdiniu tekstu.

Kodas, skirtas sukurti lentelę PowerPoint naudojant 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");
}
}

Šis kodas parodo kaip sukurti lentelę PowerPoint naudojant Java. Skirtingoms funkcijoms naudoti naudojamos kelios sąsajos klasės, pvz., skaidrėms pasiekti naudojama ISlide, darbui su lentelėmis naudojama ITable klasė, o atskiroms ląstelėms dirbti naudojamos IRow ir ICell klasės. ITextFrame klasė yra pagrindinė sąsaja, kuri naudojama tekstui langelyje nustatyti ir langelių formatavimui nustatyti.

Ši pamoka mus išmokė kaip sukurti lentelę PowerPoint pristatyme naudojant Java. Jei norite sužinoti, kaip sukurti HTML iš pristatymo, žr. straipsnį kaip sukurti PowerPoint skaidres HTML naudojant Java.

 Latviski