support for tables in HSLF
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@608386 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ebc731a087
commit
608392128b
@ -36,6 +36,8 @@
|
|||||||
|
|
||||||
<!-- Don't forget to update status.xml too! -->
|
<!-- Don't forget to update status.xml too! -->
|
||||||
<release version="3.0.2-FINAL" date="2008-??-??">
|
<release version="3.0.2-FINAL" date="2008-??-??">
|
||||||
|
<action dev="POI-DEVELOPERS" type="add">Support for tables in HSLF</action>
|
||||||
|
<action dev="POI-DEVELOPERS" type="fix">43781 - Fix for extracting text from TextBoxes HSLF in</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">Improve JavaDocs relating to hssf font and fill colourings</action>
|
<action dev="POI-DEVELOPERS" type="fix">Improve JavaDocs relating to hssf font and fill colourings</action>
|
||||||
<action dev="POI-DEVELOPERS" type="add">44095, 44097, 44099 - [PATCH] Support for Mid, Replace and Substitute excel functions</action>
|
<action dev="POI-DEVELOPERS" type="add">44095, 44097, 44099 - [PATCH] Support for Mid, Replace and Substitute excel functions</action>
|
||||||
<action dev="POI-DEVELOPERS" type="add">44055 - [PATCH] Support for getting the from field from HSMF messages</action>
|
<action dev="POI-DEVELOPERS" type="add">44055 - [PATCH] Support for getting the from field from HSMF messages</action>
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
<li><link href="#Fill">How to work with slide/shape background</link></li>
|
<li><link href="#Fill">How to work with slide/shape background</link></li>
|
||||||
<li><link href="#Bullets">How to create bulleted lists</link></li>
|
<li><link href="#Bullets">How to create bulleted lists</link></li>
|
||||||
<li><link href="#Hyperlinks">Hyperlinks</link></li>
|
<li><link href="#Hyperlinks">Hyperlinks</link></li>
|
||||||
|
<li><link href="#Tables">Tables</link></li>
|
||||||
</ul>
|
</ul>
|
||||||
</section>
|
</section>
|
||||||
<section><title>Features</title>
|
<section><title>Features</title>
|
||||||
@ -387,6 +388,57 @@
|
|||||||
}
|
}
|
||||||
</source>
|
</source>
|
||||||
</section>
|
</section>
|
||||||
|
<anchor id="Tables"/>
|
||||||
|
<section><title>How to create tables</title>
|
||||||
|
<source>
|
||||||
|
//table data
|
||||||
|
String[][] data = {
|
||||||
|
{"INPUT FILE", "NUMBER OF RECORDS"},
|
||||||
|
{"Item File", "11,559"},
|
||||||
|
{"Vendor File", "300"},
|
||||||
|
{"Purchase History File", "10,000"},
|
||||||
|
{"Total # of requisitions", "10,200,038"}
|
||||||
|
};
|
||||||
|
|
||||||
|
SlideShow ppt = new SlideShow();
|
||||||
|
|
||||||
|
Slide slide = ppt.createSlide();
|
||||||
|
//create a table of 5 rows and 2 columns
|
||||||
|
Table table = new Table(5, 2);
|
||||||
|
for (int i = 0; i < data.length; i++) {
|
||||||
|
for (int j = 0; j < data[i].length; j++) {
|
||||||
|
TableCell cell = table.getCell(i, j);
|
||||||
|
cell.setText(data[i][j]);
|
||||||
|
|
||||||
|
RichTextRun rt = cell.getTextRun().getRichTextRuns()[0];
|
||||||
|
rt.setFontName("Arial");
|
||||||
|
rt.setFontSize(10);
|
||||||
|
|
||||||
|
cell.setVerticalAlignment(TextBox.AnchorMiddle);
|
||||||
|
cell.setHorizontalAlignment(TextBox.AlignCenter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//set table borders
|
||||||
|
Line border = table.createBorder();
|
||||||
|
border.setLineColor(Color.black);
|
||||||
|
border.setLineWidth(1.0);
|
||||||
|
table.setAllBorders(border);
|
||||||
|
|
||||||
|
//set width of the 1st column
|
||||||
|
table.setColumnWidth(0, 300);
|
||||||
|
//set width of the 2nd column
|
||||||
|
table.setColumnWidth(1, 150);
|
||||||
|
|
||||||
|
slide.addShape(table);
|
||||||
|
table.moveTo(100, 100);
|
||||||
|
|
||||||
|
FileOutputStream out = new FileOutputStream("hslf-table.ppt");
|
||||||
|
ppt.write(out);
|
||||||
|
out.close();
|
||||||
|
|
||||||
|
</source>
|
||||||
|
</section>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
</section>
|
</section>
|
||||||
|
@ -33,6 +33,8 @@
|
|||||||
<!-- Don't forget to update changes.xml too! -->
|
<!-- Don't forget to update changes.xml too! -->
|
||||||
<changes>
|
<changes>
|
||||||
<release version="3.0.2-FINAL" date="2008-??-??">
|
<release version="3.0.2-FINAL" date="2008-??-??">
|
||||||
|
<action dev="POI-DEVELOPERS" type="add">Support for tables in HSLF</action>
|
||||||
|
<action dev="POI-DEVELOPERS" type="fix">43781 - Fix for extracting text from TextBoxes HSLF in</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">Improve JavaDocs relating to hssf font and fill colourings</action>
|
<action dev="POI-DEVELOPERS" type="fix">Improve JavaDocs relating to hssf font and fill colourings</action>
|
||||||
<action dev="POI-DEVELOPERS" type="add">44095, 44097, 44099 - [PATCH] Support for Mid, Replace and Substitute excel functions</action>
|
<action dev="POI-DEVELOPERS" type="add">44095, 44097, 44099 - [PATCH] Support for Mid, Replace and Substitute excel functions</action>
|
||||||
<action dev="POI-DEVELOPERS" type="add">44055 - [PATCH] Support for getting the from field from HSMF messages</action>
|
<action dev="POI-DEVELOPERS" type="add">44055 - [PATCH] Support for getting the from field from HSMF messages</action>
|
||||||
|
127
src/scratchpad/examples/src/org/apache/poi/hslf/examples/TableDemo.java
Executable file
127
src/scratchpad/examples/src/org/apache/poi/hslf/examples/TableDemo.java
Executable file
@ -0,0 +1,127 @@
|
|||||||
|
|
||||||
|
/* ====================================================================
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
==================================================================== */
|
||||||
|
package org.apache.poi.hslf.examples;
|
||||||
|
|
||||||
|
import org.apache.poi.hslf.usermodel.SlideShow;
|
||||||
|
import org.apache.poi.hslf.usermodel.RichTextRun;
|
||||||
|
import org.apache.poi.hslf.model.*;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Demonstrates how to create tables
|
||||||
|
*
|
||||||
|
* @author Yegor Kozlov
|
||||||
|
*/
|
||||||
|
public class TableDemo {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
|
||||||
|
//test data for the first taable
|
||||||
|
String[][] txt1 = {
|
||||||
|
{"INPUT FILE", "NUMBER OF RECORDS"},
|
||||||
|
{"Item File", "11,559"},
|
||||||
|
{"Vendor File", "502"},
|
||||||
|
{"Purchase History File - # of PO\u2019s\r(12/01/04 - 05/31/06)", "12,852"},
|
||||||
|
{"Purchase History File - # of PO Lines\r(12/01/04 - 05/31/06)", "53,523" },
|
||||||
|
{"Total PO History Spend", "$10,172,038"}
|
||||||
|
};
|
||||||
|
|
||||||
|
SlideShow ppt = new SlideShow();
|
||||||
|
|
||||||
|
Slide slide = ppt.createSlide();
|
||||||
|
|
||||||
|
//six rows, two columns
|
||||||
|
Table table1 = new Table(6, 2);
|
||||||
|
for (int i = 0; i < txt1.length; i++) {
|
||||||
|
for (int j = 0; j < txt1[i].length; j++) {
|
||||||
|
TableCell cell = table1.getCell(i, j);
|
||||||
|
cell.setText(txt1[i][j]);
|
||||||
|
RichTextRun rt = cell.getTextRun().getRichTextRuns()[0];
|
||||||
|
rt.setFontName("Arial");
|
||||||
|
rt.setFontSize(10);
|
||||||
|
if(i == 0){
|
||||||
|
cell.getFill().setForegroundColor(new Color(227, 227, 227));
|
||||||
|
} else {
|
||||||
|
rt.setBold(true);
|
||||||
|
}
|
||||||
|
cell.setVerticalAlignment(TextBox.AnchorMiddle);
|
||||||
|
cell.setHorizontalAlignment(TextBox.AlignCenter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Line border1 = table1.createBorder();
|
||||||
|
border1.setLineColor(Color.black);
|
||||||
|
border1.setLineWidth(1.0);
|
||||||
|
table1.setAllBorders(border1);
|
||||||
|
|
||||||
|
table1.setColumnWidth(0, 300);
|
||||||
|
table1.setColumnWidth(1, 150);
|
||||||
|
|
||||||
|
slide.addShape(table1);
|
||||||
|
int pgWidth = ppt.getPageSize().width;
|
||||||
|
table1.moveTo((pgWidth - table1.getAnchor().width)/2, 100);
|
||||||
|
|
||||||
|
//test data for the second taable
|
||||||
|
String[][] txt2 = {
|
||||||
|
{"Data Source"},
|
||||||
|
{"CAS Internal Metrics - Item Master Summary\r" +
|
||||||
|
"CAS Internal Metrics - Vendor Summary\r" +
|
||||||
|
"CAS Internal Metrics - PO History Summary"}
|
||||||
|
};
|
||||||
|
|
||||||
|
//two rows, one column
|
||||||
|
Table table2 = new Table(2, 1);
|
||||||
|
for (int i = 0; i < txt2.length; i++) {
|
||||||
|
for (int j = 0; j < txt2[i].length; j++) {
|
||||||
|
TableCell cell = table2.getCell(i, j);
|
||||||
|
cell.setText(txt2[i][j]);
|
||||||
|
RichTextRun rt = cell.getTextRun().getRichTextRuns()[0];
|
||||||
|
rt.setFontSize(10);
|
||||||
|
rt.setFontName("Arial");
|
||||||
|
if(i == 0){
|
||||||
|
cell.getFill().setForegroundColor(new Color(0, 51, 102));
|
||||||
|
rt.setFontColor(Color.white);
|
||||||
|
rt.setBold(true);
|
||||||
|
rt.setFontSize(14);
|
||||||
|
cell.setHorizontalAlignment(TextBox.AlignCenter);
|
||||||
|
} else {
|
||||||
|
rt.setBullet(true);
|
||||||
|
rt.setFontSize(12);
|
||||||
|
cell.setHorizontalAlignment(TextBox.AlignLeft);
|
||||||
|
}
|
||||||
|
cell.setVerticalAlignment(TextBox.AnchorMiddle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
table2.setColumnWidth(0, 300);
|
||||||
|
table2.setRowHeight(0, 30);
|
||||||
|
table2.setRowHeight(1, 70);
|
||||||
|
|
||||||
|
Line border2 = table2.createBorder();
|
||||||
|
table2.setOutsideBorders(border2);
|
||||||
|
|
||||||
|
slide.addShape(table2);
|
||||||
|
table2.moveTo(200, 400);
|
||||||
|
|
||||||
|
FileOutputStream out = new FileOutputStream("hslf-table.ppt");
|
||||||
|
ppt.write(out);
|
||||||
|
out.close();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -150,10 +150,12 @@ public class Fill {
|
|||||||
EscherOptRecord opt = (EscherOptRecord)Shape.getEscherChild(shape.getSpContainer(), EscherOptRecord.RECORD_ID);
|
EscherOptRecord opt = (EscherOptRecord)Shape.getEscherChild(shape.getSpContainer(), EscherOptRecord.RECORD_ID);
|
||||||
if (color == null) {
|
if (color == null) {
|
||||||
Shape.setEscherProperty(opt, EscherProperties.FILL__FILLCOLOR, -1);
|
Shape.setEscherProperty(opt, EscherProperties.FILL__FILLCOLOR, -1);
|
||||||
|
Shape.setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 0x150010);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 0).getRGB();
|
int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 0).getRGB();
|
||||||
Shape.setEscherProperty(opt, EscherProperties.FILL__FILLCOLOR, rgb);
|
Shape.setEscherProperty(opt, EscherProperties.FILL__FILLCOLOR, rgb);
|
||||||
|
Shape.setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 0x150011);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,8 +124,10 @@ public class SimpleShape extends Shape {
|
|||||||
int rgb = p1.getPropertyValue();
|
int rgb = p1.getPropertyValue();
|
||||||
if (rgb >= 0x8000000) {
|
if (rgb >= 0x8000000) {
|
||||||
int idx = rgb % 0x8000000;
|
int idx = rgb % 0x8000000;
|
||||||
ColorSchemeAtom ca = getSheet().getColorScheme();
|
if(getSheet() != null) {
|
||||||
if(idx >= 0 && idx <= 7) rgb = ca.getColor(idx);
|
ColorSchemeAtom ca = getSheet().getColorScheme();
|
||||||
|
if(idx >= 0 && idx <= 7) rgb = ca.getColor(idx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Color tmp = new Color(rgb, true);
|
Color tmp = new Color(rgb, true);
|
||||||
clr = new Color(tmp.getBlue(), tmp.getGreen(), tmp.getRed());
|
clr = new Color(tmp.getBlue(), tmp.getGreen(), tmp.getRed());
|
||||||
@ -192,8 +194,10 @@ public class SimpleShape extends Shape {
|
|||||||
int rgb = p1.getPropertyValue();
|
int rgb = p1.getPropertyValue();
|
||||||
if (rgb >= 0x8000000) {
|
if (rgb >= 0x8000000) {
|
||||||
int idx = rgb % 0x8000000;
|
int idx = rgb % 0x8000000;
|
||||||
ColorSchemeAtom ca = getSheet().getColorScheme();
|
if(getSheet() != null) {
|
||||||
rgb = ca.getColor(idx);
|
ColorSchemeAtom ca = getSheet().getColorScheme();
|
||||||
|
rgb = ca.getColor(idx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Color tmp = new Color(rgb, true);
|
Color tmp = new Color(rgb, true);
|
||||||
clr = new Color(tmp.getBlue(), tmp.getGreen(), tmp.getRed());
|
clr = new Color(tmp.getBlue(), tmp.getGreen(), tmp.getRed());
|
||||||
|
291
src/scratchpad/src/org/apache/poi/hslf/model/Table.java
Executable file
291
src/scratchpad/src/org/apache/poi/hslf/model/Table.java
Executable file
@ -0,0 +1,291 @@
|
|||||||
|
|
||||||
|
/* ====================================================================
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
==================================================================== */
|
||||||
|
package org.apache.poi.hslf.model;
|
||||||
|
|
||||||
|
import org.apache.poi.ddf.*;
|
||||||
|
import org.apache.poi.util.LittleEndian;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a table in a PowerPoint presentation
|
||||||
|
*
|
||||||
|
* @author Yegor Kozlov
|
||||||
|
*/
|
||||||
|
public class Table extends ShapeGroup {
|
||||||
|
|
||||||
|
protected static final int BORDER_TOP = 1;
|
||||||
|
protected static final int BORDER_RIGHT = 2;
|
||||||
|
protected static final int BORDER_BOTTOM = 3;
|
||||||
|
protected static final int BORDER_LEFT = 4;
|
||||||
|
|
||||||
|
protected static final int BORDERS_ALL = 5;
|
||||||
|
protected static final int BORDERS_OUTSIDE = 6;
|
||||||
|
protected static final int BORDERS_INSIDE = 7;
|
||||||
|
protected static final int BORDERS_NONE = 8;
|
||||||
|
|
||||||
|
|
||||||
|
protected TableCell[][] cells;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Table of the given number of rows and columns
|
||||||
|
*
|
||||||
|
* @param numrows the number of rows
|
||||||
|
* @param numcols the number of columns
|
||||||
|
*/
|
||||||
|
public Table(int numrows, int numcols) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
int x=0, y=0, tblWidth=0, tblHeight=0;
|
||||||
|
cells = new TableCell[numrows][numcols];
|
||||||
|
for (int i = 0; i < cells.length; i++) {
|
||||||
|
x = 0;
|
||||||
|
for (int j = 0; j < cells[i].length; j++) {
|
||||||
|
cells[i][j] = new TableCell(this);
|
||||||
|
Rectangle anchor = new Rectangle(x, y, TableCell.DEFAULT_WIDTH, TableCell.DEFAULT_HEIGHT);
|
||||||
|
cells[i][j].setAnchor(anchor);
|
||||||
|
x += TableCell.DEFAULT_WIDTH;
|
||||||
|
}
|
||||||
|
y += TableCell.DEFAULT_HEIGHT;
|
||||||
|
}
|
||||||
|
tblWidth = x;
|
||||||
|
tblHeight = y;
|
||||||
|
setAnchor(new Rectangle(0, 0, tblWidth, tblHeight));
|
||||||
|
|
||||||
|
EscherContainerRecord spCont = (EscherContainerRecord) getSpContainer().getChild(0);
|
||||||
|
List lst = spCont.getChildRecords();
|
||||||
|
EscherOptRecord opt = new EscherOptRecord();
|
||||||
|
opt.setRecordId((short)0xF122);
|
||||||
|
opt.addEscherProperty(new EscherSimpleProperty((short)0x39F, 1));
|
||||||
|
EscherArrayProperty p = new EscherArrayProperty((short)0x43A0, false, null);
|
||||||
|
p.setSizeOfElements(0x0004);
|
||||||
|
p.setNumberOfElementsInArray(numrows);
|
||||||
|
p.setNumberOfElementsInMemory(numrows);
|
||||||
|
opt.addEscherProperty(p);
|
||||||
|
lst.add(lst.size()-1, opt);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a Table object and initilize it from the supplied Record container.
|
||||||
|
*
|
||||||
|
* @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
|
||||||
|
* @param parent the parent of the shape
|
||||||
|
*/
|
||||||
|
protected Table(EscherContainerRecord escherRecord, Shape parent) {
|
||||||
|
super(escherRecord, parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a cell
|
||||||
|
*
|
||||||
|
* @param row the row index (0-based)
|
||||||
|
* @param col the column index (0-based)
|
||||||
|
* @return the cell
|
||||||
|
*/
|
||||||
|
public TableCell getCell(int row, int col) {
|
||||||
|
return cells[row][col];
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNumberOfColumns() {
|
||||||
|
return cells[0].length;
|
||||||
|
}
|
||||||
|
public int getNumberOfRows() {
|
||||||
|
return cells.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void afterInsert(Sheet sh){
|
||||||
|
EscherContainerRecord spCont = (EscherContainerRecord) getSpContainer().getChild(0);
|
||||||
|
List lst = spCont.getChildRecords();
|
||||||
|
EscherOptRecord opt = (EscherOptRecord)lst.get(lst.size()-2);
|
||||||
|
EscherArrayProperty p = (EscherArrayProperty)opt.getEscherProperty(1);
|
||||||
|
for (int i = 0; i < cells.length; i++) {
|
||||||
|
TableCell cell = cells[i][0];
|
||||||
|
int rowHeight = cell.getAnchor().height*MASTER_DPI/POINT_DPI;
|
||||||
|
byte[] val = new byte[4];
|
||||||
|
LittleEndian.putInt(val, rowHeight);
|
||||||
|
p.setElement(i, val);
|
||||||
|
for (int j = 0; j < cells[i].length; j++) {
|
||||||
|
TableCell c = cells[i][j];
|
||||||
|
addShape(c);
|
||||||
|
|
||||||
|
Line bt = c.getBorderTop();
|
||||||
|
if(bt != null) addShape(bt);
|
||||||
|
|
||||||
|
Line br = c.getBorderRight();
|
||||||
|
if(br != null) addShape(br);
|
||||||
|
|
||||||
|
Line bb = c.getBorderBottom();
|
||||||
|
if(bb != null) addShape(bb);
|
||||||
|
|
||||||
|
Line bl = c.getBorderLeft();
|
||||||
|
if(bl != null) addShape(bl);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the row height.
|
||||||
|
*
|
||||||
|
* @param row the row index (0-based)
|
||||||
|
* @param height the height to set (in pixels)
|
||||||
|
*/
|
||||||
|
public void setRowHeight(int row, int height){
|
||||||
|
int currentHeight = cells[row][0].getAnchor().height;
|
||||||
|
int dy = height - currentHeight;
|
||||||
|
|
||||||
|
for (int i = row; i < cells.length; i++) {
|
||||||
|
for (int j = 0; j < cells[i].length; j++) {
|
||||||
|
Rectangle anchor = cells[i][j].getAnchor();
|
||||||
|
if(i == row) anchor.height = height;
|
||||||
|
else anchor.y += dy;
|
||||||
|
cells[i][j].setAnchor(anchor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Rectangle tblanchor = getAnchor();
|
||||||
|
tblanchor.height += dy;
|
||||||
|
setAnchor(tblanchor);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the column width.
|
||||||
|
*
|
||||||
|
* @param col the column index (0-based)
|
||||||
|
* @param width the width to set (in pixels)
|
||||||
|
*/
|
||||||
|
public void setColumnWidth(int col, int width){
|
||||||
|
int currentWidth = cells[0][col].getAnchor().width;
|
||||||
|
int dx = width - currentWidth;
|
||||||
|
for (int i = 0; i < cells.length; i++) {
|
||||||
|
Rectangle anchor = cells[i][col].getAnchor();
|
||||||
|
anchor.width = width;
|
||||||
|
cells[i][col].setAnchor(anchor);
|
||||||
|
|
||||||
|
if(col < cells[i].length - 1) for (int j = col+1; j < cells[i].length; j++) {
|
||||||
|
anchor = cells[i][j].getAnchor();
|
||||||
|
anchor.x += dx;
|
||||||
|
cells[i][j].setAnchor(anchor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Rectangle tblanchor = getAnchor();
|
||||||
|
tblanchor.width += dx;
|
||||||
|
setAnchor(tblanchor);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format the table and apply the specified Line to all cell boundaries,
|
||||||
|
* both outside and inside
|
||||||
|
*
|
||||||
|
* @param line the border line
|
||||||
|
*/
|
||||||
|
public void setAllBorders(Line line){
|
||||||
|
for (int i = 0; i < cells.length; i++) {
|
||||||
|
for (int j = 0; j < cells[i].length; j++) {
|
||||||
|
TableCell cell = cells[i][j];
|
||||||
|
cell.setBorderTop(cloneBorder(line));
|
||||||
|
cell.setBorderLeft(cloneBorder(line));
|
||||||
|
if(j == cells[i].length - 1) cell.setBorderRight(cloneBorder(line));
|
||||||
|
if(i == cells.length - 1) cell.setBorderBottom(cloneBorder(line));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format the outside border using the specified Line object
|
||||||
|
*
|
||||||
|
* @param line the border line
|
||||||
|
*/
|
||||||
|
public void setOutsideBorders(Line line){
|
||||||
|
for (int i = 0; i < cells.length; i++) {
|
||||||
|
for (int j = 0; j < cells[i].length; j++) {
|
||||||
|
TableCell cell = cells[i][j];
|
||||||
|
|
||||||
|
if(j == 0) cell.setBorderLeft(cloneBorder(line));
|
||||||
|
if(j == cells[i].length - 1) cell.setBorderRight(cloneBorder(line));
|
||||||
|
else {
|
||||||
|
cell.setBorderLeft(null);
|
||||||
|
cell.setBorderLeft(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(i == 0) cell.setBorderTop(cloneBorder(line));
|
||||||
|
else if(i == cells.length - 1) cell.setBorderBottom(cloneBorder(line));
|
||||||
|
else {
|
||||||
|
cell.setBorderTop(null);
|
||||||
|
cell.setBorderBottom(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format the inside border using the specified Line object
|
||||||
|
*
|
||||||
|
* @param line the border line
|
||||||
|
*/
|
||||||
|
public void setInsideBorders(Line line){
|
||||||
|
for (int i = 0; i < cells.length; i++) {
|
||||||
|
for (int j = 0; j < cells[i].length; j++) {
|
||||||
|
TableCell cell = cells[i][j];
|
||||||
|
|
||||||
|
if(j != cells[i].length - 1)
|
||||||
|
cell.setBorderRight(cloneBorder(line));
|
||||||
|
else {
|
||||||
|
cell.setBorderLeft(null);
|
||||||
|
cell.setBorderLeft(null);
|
||||||
|
}
|
||||||
|
if(i != cells.length - 1) cell.setBorderBottom(cloneBorder(line));
|
||||||
|
else {
|
||||||
|
cell.setBorderTop(null);
|
||||||
|
cell.setBorderBottom(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Line cloneBorder(Line line){
|
||||||
|
Line border = createBorder();
|
||||||
|
border.setLineWidth(line.getLineWidth());
|
||||||
|
border.setLineStyle(line.getLineStyle());
|
||||||
|
border.setLineDashing(line.getLineDashing());
|
||||||
|
border.setLineColor(line.getLineColor());
|
||||||
|
return border;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a border to format this table
|
||||||
|
*
|
||||||
|
* @return the created border
|
||||||
|
*/
|
||||||
|
public Line createBorder(){
|
||||||
|
Line line = new Line(this);
|
||||||
|
|
||||||
|
EscherOptRecord opt = (EscherOptRecord)getEscherChild(line.getSpContainer(), EscherOptRecord.RECORD_ID);
|
||||||
|
setEscherProperty(opt, EscherProperties.GEOMETRY__SHAPEPATH, -1);
|
||||||
|
setEscherProperty(opt, EscherProperties.GEOMETRY__FILLOK, -1);
|
||||||
|
setEscherProperty(opt, EscherProperties.SHADOWSTYLE__SHADOWOBSURED, 0x20000);
|
||||||
|
setEscherProperty(opt, EscherProperties.THREED__LIGHTFACE, 0x80000);
|
||||||
|
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
}
|
155
src/scratchpad/src/org/apache/poi/hslf/model/TableCell.java
Executable file
155
src/scratchpad/src/org/apache/poi/hslf/model/TableCell.java
Executable file
@ -0,0 +1,155 @@
|
|||||||
|
|
||||||
|
/* ====================================================================
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
==================================================================== */
|
||||||
|
package org.apache.poi.hslf.model;
|
||||||
|
|
||||||
|
import org.apache.poi.ddf.*;
|
||||||
|
import org.apache.poi.hslf.record.EscherTextboxWrapper;
|
||||||
|
import org.apache.poi.hslf.record.TextHeaderAtom;
|
||||||
|
import org.apache.poi.hslf.usermodel.RichTextRun;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a cell in a ppt table
|
||||||
|
*
|
||||||
|
* @author Yegor Kozlov
|
||||||
|
*/
|
||||||
|
public class TableCell extends TextBox {
|
||||||
|
protected static final int DEFAULT_WIDTH = 100;
|
||||||
|
protected static final int DEFAULT_HEIGHT = 40;
|
||||||
|
|
||||||
|
private Line borderLeft;
|
||||||
|
private Line borderRight;
|
||||||
|
private Line borderTop;
|
||||||
|
private Line borderBottom;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a TableCell object and initialize it from the supplied Record container.
|
||||||
|
*
|
||||||
|
* @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
|
||||||
|
* @param parent the parent of the shape
|
||||||
|
*/
|
||||||
|
protected TableCell(EscherContainerRecord escherRecord, Shape parent){
|
||||||
|
super(escherRecord, parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new TableCell. This constructor is used when a new shape is created.
|
||||||
|
*
|
||||||
|
* @param parent the parent of this Shape. For example, if this text box is a cell
|
||||||
|
* in a table then the parent is Table.
|
||||||
|
*/
|
||||||
|
public TableCell(Shape parent){
|
||||||
|
super(parent);
|
||||||
|
|
||||||
|
setShapeType(ShapeTypes.Rectangle);
|
||||||
|
_txtrun.setRunType(TextHeaderAtom.HALF_BODY_TYPE);
|
||||||
|
_txtrun.getRichTextRuns()[0].setFlag(false, 0, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected EscherContainerRecord createSpContainer(boolean isChild){
|
||||||
|
EscherContainerRecord spContainer = super.createSpContainer(isChild);
|
||||||
|
EscherOptRecord opt = (EscherOptRecord)getEscherChild(spContainer, EscherOptRecord.RECORD_ID);
|
||||||
|
setEscherProperty(opt, EscherProperties.TEXT__TEXTID, 0);
|
||||||
|
setEscherProperty(opt, EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 0x20000);
|
||||||
|
setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 0x150001);
|
||||||
|
setEscherProperty(opt, EscherProperties.SHADOWSTYLE__SHADOWOBSURED, 0x20000);
|
||||||
|
setEscherProperty(opt, EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 0x40000);
|
||||||
|
|
||||||
|
return spContainer;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void anchorBorder(int type, Line line){
|
||||||
|
Rectangle cellAnchor = getAnchor();
|
||||||
|
Rectangle lineAnchor = new Rectangle();
|
||||||
|
switch(type){
|
||||||
|
case Table.BORDER_TOP:
|
||||||
|
lineAnchor.x = cellAnchor.x;
|
||||||
|
lineAnchor.y = cellAnchor.y;
|
||||||
|
lineAnchor.width = cellAnchor.width;
|
||||||
|
lineAnchor.height = 0;
|
||||||
|
break;
|
||||||
|
case Table.BORDER_RIGHT:
|
||||||
|
lineAnchor.x = cellAnchor.x + cellAnchor.width;
|
||||||
|
lineAnchor.y = cellAnchor.y;
|
||||||
|
lineAnchor.width = 0;
|
||||||
|
lineAnchor.height = cellAnchor.height;
|
||||||
|
break;
|
||||||
|
case Table.BORDER_BOTTOM:
|
||||||
|
lineAnchor.x = cellAnchor.x;
|
||||||
|
lineAnchor.y = cellAnchor.y + cellAnchor.height;
|
||||||
|
lineAnchor.width = cellAnchor.width;
|
||||||
|
lineAnchor.height = 0;
|
||||||
|
break;
|
||||||
|
case Table.BORDER_LEFT:
|
||||||
|
lineAnchor.x = cellAnchor.x;
|
||||||
|
lineAnchor.y = cellAnchor.y;
|
||||||
|
lineAnchor.width = 0;
|
||||||
|
lineAnchor.height = cellAnchor.height;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Unknown border type: " + type);
|
||||||
|
}
|
||||||
|
line.setAnchor(lineAnchor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Line getBorderLeft() {
|
||||||
|
return borderLeft;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBorderLeft(Line line) {
|
||||||
|
if(line != null) anchorBorder(Table.BORDER_LEFT, line);
|
||||||
|
this.borderLeft = line;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Line getBorderRight() {
|
||||||
|
return borderRight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBorderRight(Line line) {
|
||||||
|
if(line != null) anchorBorder(Table.BORDER_RIGHT, line);
|
||||||
|
this.borderRight = line;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Line getBorderTop() {
|
||||||
|
return borderTop;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBorderTop(Line line) {
|
||||||
|
if(line != null) anchorBorder(Table.BORDER_TOP, line);
|
||||||
|
this.borderTop = line;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Line getBorderBottom() {
|
||||||
|
return borderBottom;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBorderBottom(Line line) {
|
||||||
|
if(line != null) anchorBorder(Table.BORDER_BOTTOM, line);
|
||||||
|
this.borderBottom = line;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAnchor(Rectangle anchor){
|
||||||
|
super.setAnchor(anchor);
|
||||||
|
|
||||||
|
if(borderTop != null) anchorBorder(Table.BORDER_TOP, borderTop);
|
||||||
|
if(borderRight != null) anchorBorder(Table.BORDER_RIGHT, borderRight);
|
||||||
|
if(borderBottom != null) anchorBorder(Table.BORDER_BOTTOM, borderBottom);
|
||||||
|
if(borderLeft != null) anchorBorder(Table.BORDER_LEFT, borderLeft);
|
||||||
|
}
|
||||||
|
}
|
@ -490,9 +490,6 @@ public class TextBox extends SimpleShape {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(_txtrun == null) {
|
|
||||||
logger.log(POILogger.WARN, "text run not found for shapeId=" + shapeId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -198,7 +198,7 @@ public class RichTextRun
|
|||||||
setFlag(true, index, value);
|
setFlag(true, index, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setFlag(boolean isCharacter, int index, boolean value) {
|
public void setFlag(boolean isCharacter, int index, boolean value) {
|
||||||
TextPropCollection props;
|
TextPropCollection props;
|
||||||
String propname;
|
String propname;
|
||||||
if (isCharacter){
|
if (isCharacter){
|
||||||
@ -282,7 +282,7 @@ public class RichTextRun
|
|||||||
* @param propName The name of the Character TextProp
|
* @param propName The name of the Character TextProp
|
||||||
* @param val The value to set for the TextProp
|
* @param val The value to set for the TextProp
|
||||||
*/
|
*/
|
||||||
private void setParaTextPropVal(String propName, int val) {
|
public void setParaTextPropVal(String propName, int val) {
|
||||||
// Ensure we have the StyleTextProp atom we're going to need
|
// Ensure we have the StyleTextProp atom we're going to need
|
||||||
if(paragraphStyle == null) {
|
if(paragraphStyle == null) {
|
||||||
parentRun.ensureStyleAtomPresent();
|
parentRun.ensureStyleAtomPresent();
|
||||||
@ -297,7 +297,7 @@ public class RichTextRun
|
|||||||
* @param propName The name of the Paragraph TextProp
|
* @param propName The name of the Paragraph TextProp
|
||||||
* @param val The value to set for the TextProp
|
* @param val The value to set for the TextProp
|
||||||
*/
|
*/
|
||||||
private void setCharTextPropVal(String propName, int val) {
|
public void setCharTextPropVal(String propName, int val) {
|
||||||
// Ensure we have the StyleTextProp atom we're going to need
|
// Ensure we have the StyleTextProp atom we're going to need
|
||||||
if(characterStyle == null) {
|
if(characterStyle == null) {
|
||||||
parentRun.ensureStyleAtomPresent();
|
parentRun.ensureStyleAtomPresent();
|
||||||
|
Loading…
Reference in New Issue
Block a user