kiwiwings

Sample code for POI XSLFTable

Dec 13th, 2015
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.32 KB | None | 0 0
  1. package poijartest;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Rectangle;
  5. import java.io.FileOutputStream;
  6. import java.io.IOException;
  7.  
  8. import org.apache.poi.xslf.usermodel.XMLSlideShow;
  9. import org.apache.poi.xslf.usermodel.XSLFSlide;
  10. import org.apache.poi.xslf.usermodel.XSLFTable;
  11. import org.apache.poi.xslf.usermodel.XSLFTableCell;
  12. import org.apache.poi.xslf.usermodel.XSLFTableRow;
  13.  
  14. public class TableTest {
  15.     public static void main(String[] args) throws IOException {
  16.         XMLSlideShow ppt = new XMLSlideShow();
  17.         XSLFSlide sl = ppt.createSlide();
  18.         XSLFTable tab = sl.createTable();
  19.         XSLFTableRow r2 = tab.addRow();
  20.         r2.addCell();
  21.         r2.addCell();
  22.         r2 = tab.addRow();
  23.         r2.addCell();
  24.         r2.addCell();
  25.  
  26.         tab.setAnchor(new Rectangle(100,100,100,100));
  27.         int rIdx = 0;
  28.         for (XSLFTableRow r : tab.getRows()) {
  29.             rIdx++;
  30.             int cIdx = 0;
  31.             for (XSLFTableCell tc : r.getCells()) {
  32.                 cIdx++;
  33.                 tc.setBorderBottom(2);
  34.                 tc.setBorderBottomColor(Color.BLACK);
  35.                 tc.setBorderTop(2);
  36.                 tc.setBorderTopColor(Color.BLACK);
  37.                 tc.setBorderLeft(2);
  38.                 tc.setBorderLeftColor(Color.BLACK);
  39.                 tc.setBorderRight(2);
  40.                 tc.setBorderRightColor(Color.BLACK);
  41.                 tc.setText("r"+rIdx+" c"+cIdx);
  42.             }
  43.         }
  44.  
  45.         FileOutputStream fos = new FileOutputStream("bla.pptx");
  46.         ppt.write(fos);
  47.         fos.close();
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment