com.hfg.xml.msofficexml.xlsx.spreadsheetml.SsmlCol Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com_hfg Show documentation
Show all versions of com_hfg Show documentation
com.hfg xml, html, svg, and bioinformatics utility library
package com.hfg.xml.msofficexml.xlsx.spreadsheetml;
//------------------------------------------------------------------------------
import com.hfg.graphics.TextUtil;
import com.hfg.graphics.units.GfxSize;
import com.hfg.graphics.units.GfxUnits;
import com.hfg.xml.msofficexml.xlsx.spreadsheetml.style.SsmlCellFormat;
/**
Represents an Office Open XML worksheet column (<ssml:col>) tag.
@author J. Alex Taylor, hairyfatguy.com
*/
//------------------------------------------------------------------------------
// com.hfg XML/HTML Coding Library
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
// [email protected]
//------------------------------------------------------------------------------
public class SsmlCol extends SsmlXMLTag
{
private SsmlWorksheet mParentWorksheet;
//---------------------------------------------------------------------------
public SsmlCol(SsmlWorksheet inParentWorksheet)
{
super(SsmlXML.COLUMN, inParentWorksheet.getParentDoc());
mParentWorksheet = inParentWorksheet;
}
//---------------------------------------------------------------------------
/**
Sets the style to apply to this column's cells.
@param inValue cell format to apply
@return this column instance
*/
public SsmlCol setStyle(SsmlCellFormat inValue)
{
setAttribute(SsmlXML.STYLE_ATT, inValue.getIndex());
return this;
}
//---------------------------------------------------------------------------
/**
Sets the 1-based index of the first column that this spec applies to.
@param inValue 1-based index of the first column that this spec applies to
@return this column instance
*/
public SsmlCol setMin(int inValue)
{
setAttribute(SsmlXML.MIN_ATT, inValue);
return this;
}
//---------------------------------------------------------------------------
/**
Sets the 1-based index of the last column that this spec applies to.
@param inValue 1-based index of the last column that this spec applies to
@return this column instance
*/
public SsmlCol setMax(int inValue)
{
setAttribute(SsmlXML.MAX_ATT, inValue);
return this;
}
//---------------------------------------------------------------------------
public SsmlCol setHidden(boolean inValue)
{
setAttribute(SsmlXML.HIDDEN_ATT, inValue);
return this;
}
//---------------------------------------------------------------------------
/**
Column width measured as the number of characters of the maximum digit width
of the numbers 0, 1, 2, …, 9 as rendered in the normal style's font. There
are 4 pixels of margin padding (two on each side), plus 1 pixel padding for the gridlines.
@param inValue width to use for the column display
@return this column instance
*/
// width = Truncate([{Number of Characters} * {Maximum Digit Width} + {5 pixel padding}] / {Maximum Digit Width} * 256) / 256
public SsmlCol setWidth(float inValue)
{
setAttribute(SsmlXML.WIDTH_ATT, inValue);
setAttribute(SsmlXML.CUSTOM_WIDTH_ATT, "1");
return this;
}
//---------------------------------------------------------------------------
/**
Column width measured as the number of characters of the maximum digit width
of the numbers 0, 1, 2, …, 9 as rendered in the normal style's font. There
are 4 pixels of margin padding (two on each side), plus 1 pixel padding for the gridlines.
@param inValue width to use for the column display
@return this column instance
*/
// width = Truncate([{Number of Characters} * {Maximum Digit Width} + {5 pixel padding}] / {Maximum Digit Width} * 256) / 256
public SsmlCol setWidth(GfxSize inValue)
{
float digitWidth = (float) TextUtil.getStringRect("9", getParentDoc().getStylesPart().getCellFormats().get(0).getFont().toFont()).getWidth();
float pixels = inValue.to(GfxUnits.pixels) - 5;
return setWidth(pixels / digitWidth);
}
}