001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017: package org.apache.poi.hslf.examples;
018:
019: import org.apache.poi.hslf.usermodel.SlideShow;
020: import org.apache.poi.hslf.usermodel.RichTextRun;
021: import org.apache.poi.hslf.model.*;
022:
023: import java.awt.*;
024: import java.io.FileOutputStream;
025:
026: /**
027: * Demonstrates how to create tables
028: *
029: * @author Yegor Kozlov
030: */
031: public class TableDemo {
032:
033: public static void main(String[] args) throws Exception {
034:
035: //test data for the first taable
036: String[][] txt1 = {
037: { "INPUT FILE", "NUMBER OF RECORDS" },
038: { "Item File", "11,559" },
039: { "Vendor File", "502" },
040: {
041: "Purchase History File - # of PO\u2019s\r(12/01/04 - 05/31/06)",
042: "12,852" },
043: {
044: "Purchase History File - # of PO Lines\r(12/01/04 - 05/31/06)",
045: "53,523" },
046: { "Total PO History Spend", "$10,172,038" } };
047:
048: SlideShow ppt = new SlideShow();
049:
050: Slide slide = ppt.createSlide();
051:
052: //six rows, two columns
053: Table table1 = new Table(6, 2);
054: for (int i = 0; i < txt1.length; i++) {
055: for (int j = 0; j < txt1[i].length; j++) {
056: TableCell cell = table1.getCell(i, j);
057: cell.setText(txt1[i][j]);
058: RichTextRun rt = cell.getTextRun().getRichTextRuns()[0];
059: rt.setFontName("Arial");
060: rt.setFontSize(10);
061: if (i == 0) {
062: cell.getFill().setForegroundColor(
063: new Color(227, 227, 227));
064: } else {
065: rt.setBold(true);
066: }
067: cell.setVerticalAlignment(TextBox.AnchorMiddle);
068: cell.setHorizontalAlignment(TextBox.AlignCenter);
069: }
070: }
071:
072: Line border1 = table1.createBorder();
073: border1.setLineColor(Color.black);
074: border1.setLineWidth(1.0);
075: table1.setAllBorders(border1);
076:
077: table1.setColumnWidth(0, 300);
078: table1.setColumnWidth(1, 150);
079:
080: slide.addShape(table1);
081: int pgWidth = ppt.getPageSize().width;
082: table1.moveTo((pgWidth - table1.getAnchor().width) / 2, 100);
083:
084: //test data for the second taable
085: String[][] txt2 = {
086: { "Data Source" },
087: { "CAS Internal Metrics - Item Master Summary\r"
088: + "CAS Internal Metrics - Vendor Summary\r"
089: + "CAS Internal Metrics - PO History Summary" } };
090:
091: //two rows, one column
092: Table table2 = new Table(2, 1);
093: for (int i = 0; i < txt2.length; i++) {
094: for (int j = 0; j < txt2[i].length; j++) {
095: TableCell cell = table2.getCell(i, j);
096: cell.setText(txt2[i][j]);
097: RichTextRun rt = cell.getTextRun().getRichTextRuns()[0];
098: rt.setFontSize(10);
099: rt.setFontName("Arial");
100: if (i == 0) {
101: cell.getFill().setForegroundColor(
102: new Color(0, 51, 102));
103: rt.setFontColor(Color.white);
104: rt.setBold(true);
105: rt.setFontSize(14);
106: cell.setHorizontalAlignment(TextBox.AlignCenter);
107: } else {
108: rt.setBullet(true);
109: rt.setFontSize(12);
110: cell.setHorizontalAlignment(TextBox.AlignLeft);
111: }
112: cell.setVerticalAlignment(TextBox.AnchorMiddle);
113: }
114: }
115: table2.setColumnWidth(0, 300);
116: table2.setRowHeight(0, 30);
117: table2.setRowHeight(1, 70);
118:
119: Line border2 = table2.createBorder();
120: table2.setOutsideBorders(border2);
121:
122: slide.addShape(table2);
123: table2.moveTo(200, 400);
124:
125: FileOutputStream out = new FileOutputStream("hslf-table.ppt");
126: ppt.write(out);
127: out.close();
128:
129: }
130: }
|