XSSFCellStyle getFont method; XSSFFont class added all methods to be implemented; tests
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@640934 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5b32d35fb6
commit
66d67ccab5
@ -29,6 +29,7 @@ import org.apache.poi.ss.usermodel.CellStyle;
|
||||
import org.apache.poi.ss.usermodel.Font;
|
||||
import org.apache.poi.ss.usermodel.StylesSource;
|
||||
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
|
||||
import org.apache.poi.xssf.usermodel.XSSFFont;
|
||||
import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder;
|
||||
import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill;
|
||||
import org.apache.xmlbeans.XmlException;
|
||||
@ -164,15 +165,13 @@ public class StylesTable implements StylesSource, XSSFModel {
|
||||
}
|
||||
|
||||
public Font getFontAt(long idx) {
|
||||
// TODO
|
||||
return null;
|
||||
return new XSSFFont(fonts.get((int) idx));
|
||||
}
|
||||
public synchronized long putFont(Font font) {
|
||||
// TODO
|
||||
return -1;
|
||||
return putFont((XSSFFont)font, fonts);
|
||||
}
|
||||
|
||||
public CellStyle getStyleAt(long idx) {
|
||||
public CellStyle getStyleAt(long idx) {
|
||||
CTXf mainXf = xfs.get((int)idx);
|
||||
CTXf styleXf = null;
|
||||
|
||||
@ -320,7 +319,12 @@ public class StylesTable implements StylesSource, XSSFModel {
|
||||
private long putBorder(XSSFCellBorder border, LinkedList<CTBorder> borders) {
|
||||
return border.putBorder(borders);
|
||||
}
|
||||
|
||||
private long putFill(XSSFCellFill fill, LinkedList<CTFill> fills) {
|
||||
return fill.putFill(fills);
|
||||
}
|
||||
|
||||
private long putFont(XSSFFont font, LinkedList<CTFont> fonts) {
|
||||
return font.putFont(fonts);
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ public class XSSFCellStyle implements CellStyle {
|
||||
private CTXf cellStyleXf;
|
||||
private XSSFCellBorder cellBorder;
|
||||
private XSSFCellFill cellFill;
|
||||
private XSSFFont font;
|
||||
|
||||
/**
|
||||
* Creates a Cell Style from the supplied parts
|
||||
@ -137,6 +138,13 @@ public class XSSFCellStyle implements CellStyle {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public Font getFont() {
|
||||
if (font == null) {
|
||||
font = (XSSFFont) ((StylesTable)stylesSource).getFontAt(getFontId());
|
||||
}
|
||||
return font;
|
||||
}
|
||||
|
||||
public short getFontIndex() {
|
||||
// TODO Auto-generated method stub
|
||||
@ -326,4 +334,11 @@ public class XSSFCellStyle implements CellStyle {
|
||||
return (short) getCellBorder().getBorderColor(side).getIndexed();
|
||||
}
|
||||
|
||||
private int getFontId() {
|
||||
if (cellXf.isSetFontId()) {
|
||||
return (int) cellXf.getFontId();
|
||||
}
|
||||
return (int) cellStyleXf.getFontId();
|
||||
}
|
||||
|
||||
}
|
||||
|
150
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java
Normal file
150
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java
Normal file
@ -0,0 +1,150 @@
|
||||
/* ====================================================================
|
||||
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.xssf.usermodel;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Font;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
|
||||
|
||||
public class XSSFFont implements Font {
|
||||
|
||||
private CTFont font;
|
||||
|
||||
public XSSFFont(CTFont font) {
|
||||
this.font = font;
|
||||
}
|
||||
|
||||
public XSSFFont() {
|
||||
this.font = CTFont.Factory.newInstance();
|
||||
}
|
||||
|
||||
public short getBoldweight() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
public byte getCharSet() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
public short getColor() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
public short getFontHeight() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
public short getFontHeightInPoints() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String getFontName() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public short getIndex() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean getItalic() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean getStrikeout() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
public short getTypeOffset() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
public byte getUnderline() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setBoldweight(short boldweight) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void setCharSet(byte charset) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void setColor(short color) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void setFontHeight(short height) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void setFontHeightInPoints(short height) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void setFontName(String name) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void setItalic(boolean italic) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void setStrikeout(boolean strikeout) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void setTypeOffset(short offset) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void setUnderline(byte underline) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public long putFont(LinkedList<CTFont> fonts) {
|
||||
if(fonts.contains(font)) {
|
||||
return fonts.indexOf(font);
|
||||
}
|
||||
fonts.add(font);
|
||||
return fonts.size() - 1;
|
||||
}
|
||||
|
||||
}
|
@ -25,6 +25,7 @@ import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPatternFill;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTStylesheet;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf;
|
||||
@ -37,6 +38,7 @@ public class TestXSSFCellStyle extends TestCase {
|
||||
private StylesTable stylesTable;
|
||||
private CTBorder ctBorderA;
|
||||
private CTFill ctFill;
|
||||
private CTFont ctFont;
|
||||
private CTXf cellStyleXf;
|
||||
private CTXf cellXf;
|
||||
private XSSFCellStyle cellStyle;
|
||||
@ -60,6 +62,11 @@ public class TestXSSFCellStyle extends TestCase {
|
||||
long fillId = stylesTable.putFill(fill);
|
||||
assertEquals(0, fillId);
|
||||
|
||||
ctFont = CTFont.Factory.newInstance();
|
||||
XSSFFont font = new XSSFFont(ctFont);
|
||||
long fontId = stylesTable.putFont(font);
|
||||
assertEquals(0, fontId);
|
||||
|
||||
cellStyleXf = ctStylesheet.addNewCellStyleXfs().addNewXf();
|
||||
cellStyleXf.setBorderId(0);
|
||||
cellXf = ctStylesheet.addNewCellXfs().addNewXf();
|
||||
@ -126,4 +133,8 @@ public class TestXSSFCellStyle extends TestCase {
|
||||
ctPatternFill.setPatternType(STPatternType.DARK_DOWN);
|
||||
assertEquals(8, cellStyle.getFillPattern());
|
||||
}
|
||||
|
||||
public void testGetFont() {
|
||||
assertNotNull(cellStyle.getFont());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user