You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Bengt Rodehav <be...@rodehav.com> on 2015/09/25 11:49:30 UTC

Diagonal border

I need to detect whether a cell has diagonal borders. In the Excel document
I receive, the customer indicates that a cell should be skipped by applying
both forward and backward diagonal border so that an "X" is drawn.

I've seen that the BorderFormatting class seems to support diagonal borders
in the way I need. However, I cannot find a way to get access to the
BorderFormatting for a cell. Is there such a way?

/Bengt

Re: Diagonal border

Posted by Bengt Rodehav <be...@rodehav.com>.
BTW, the mExcelReader is just an instance of a utility class of mine that
encapsulates a few things like the workbook.

/Bengt

2015-09-28 11:02 GMT+02:00 Bengt Rodehav <be...@rodehav.com>:

> I got it to work as follows:
>
> *  private boolean isCrossedOut(Sheet theSheet, int theRow, int theCol) {*
>
> *    Row row = theSheet.getRow(theRow - 1);*
> *    Cell cell = row.getCell(theCol - 1);*
> *    XSSFCellStyle style = (XSSFCellStyle) (cell.getCellStyle());*
> *    CTXf cxf = style.getCoreXf();*
> *    long borderIndex = cxf.getBorderId();*
>
> *    CTBorder ctBorder = mStylesTable.getBorderAt((int)
> borderIndex).getCTBorder();*
> *    boolean up = ctBorder.getDiagonalUp();*
> *    boolean down = ctBorder.getDiagonalDown();*
>
> *    if (up && down) {*
> *      return true;*
> *    } else {*
> *      return false;*
> *    }*
> *  }*
>
> The mStylesTable is initialized at program startup as follows:
>
> *  mStylesTable = null;*
> *  for (POIXMLDocumentPart part : ((XSSFWorkbook)
> mExcelReader.getWorkbook()).getRelations()) {*
> *    if (part instanceof StylesTable) {*
> *      mStylesTable = (StylesTable) part;*
> *      break;*
> *    }*
> *  }*
>
> *  if (mStylesTable == null) {*
> *    throw new RuntimeException("Could not find styles table");*
> *  }*
>
> Thanks for your help,
>
> /Bengt
>
>
> 2015-09-28 9:32 GMT+02:00 Bengt Rodehav <be...@rodehav.com>:
>
>> Thank you Mark and Dominik. I will try to get this information from the
>> cell style.
>>
>> /Bengt
>>
>> 2015-09-25 18:22 GMT+02:00 Dominik Stadler <do...@gmx.at>:
>>
>>> Hi,
>>>
>>> There was a discussion about how to set diagonal border styling a few
>>> weeks ago, see
>>> http://mail-archives.apache.org/mod_mbox/poi-user/201508.mbox/browser,
>>> it describes how to set a diagonal border, maybe you can use some of
>>> this for reading the information in your case.
>>>
>>> Dominik.
>>>
>>> On Fri, Sep 25, 2015 at 4:21 PM, Mark Beardsley
>>> <ma...@tiscali.co.uk> wrote:
>>> > The border is part of the style applied to the cell from POIs point of
>>> view.
>>> > What you will need to do is recover the style from the cell - call the
>>> > getCellStyle() method on the object - and then interrogate that to
>>> find out
>>> > what type of border has been applied. If you look at the CellStyle
>>> class,
>>> > you should see that manifest constants have been created that identify
>>> the
>>> > various attributes and they include THICK_BACKWARD_DIAG and
>>> > THIN_FORWARD_DIAG. A simple switch clause should allow you to filter
>>> out the
>>> > cells that are marked with diagonal borders; it is maybe wise to
>>> include
>>> > tests for all of the diagonal options unless you are confident in your
>>> user
>>> > body.
>>> >
>>> >
>>> >
>>> > --
>>> > View this message in context:
>>> http://apache-poi.1045710.n5.nabble.com/Diagonal-border-tp5720338p5720341.html
>>> > Sent from the POI - User mailing list archive at Nabble.com.
>>> >
>>> > ---------------------------------------------------------------------
>>> > To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>>> > For additional commands, e-mail: user-help@poi.apache.org
>>> >
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>>> For additional commands, e-mail: user-help@poi.apache.org
>>>
>>>
>>
>

Re: Diagonal border

Posted by Bengt Rodehav <be...@rodehav.com>.
I got it to work as follows:

*  private boolean isCrossedOut(Sheet theSheet, int theRow, int theCol) {*

*    Row row = theSheet.getRow(theRow - 1);*
*    Cell cell = row.getCell(theCol - 1);*
*    XSSFCellStyle style = (XSSFCellStyle) (cell.getCellStyle());*
*    CTXf cxf = style.getCoreXf();*
*    long borderIndex = cxf.getBorderId();*

*    CTBorder ctBorder = mStylesTable.getBorderAt((int)
borderIndex).getCTBorder();*
*    boolean up = ctBorder.getDiagonalUp();*
*    boolean down = ctBorder.getDiagonalDown();*

*    if (up && down) {*
*      return true;*
*    } else {*
*      return false;*
*    }*
*  }*

The mStylesTable is initialized at program startup as follows:

*  mStylesTable = null;*
*  for (POIXMLDocumentPart part : ((XSSFWorkbook)
mExcelReader.getWorkbook()).getRelations()) {*
*    if (part instanceof StylesTable) {*
*      mStylesTable = (StylesTable) part;*
*      break;*
*    }*
*  }*

*  if (mStylesTable == null) {*
*    throw new RuntimeException("Could not find styles table");*
*  }*

Thanks for your help,

/Bengt


2015-09-28 9:32 GMT+02:00 Bengt Rodehav <be...@rodehav.com>:

> Thank you Mark and Dominik. I will try to get this information from the
> cell style.
>
> /Bengt
>
> 2015-09-25 18:22 GMT+02:00 Dominik Stadler <do...@gmx.at>:
>
>> Hi,
>>
>> There was a discussion about how to set diagonal border styling a few
>> weeks ago, see
>> http://mail-archives.apache.org/mod_mbox/poi-user/201508.mbox/browser,
>> it describes how to set a diagonal border, maybe you can use some of
>> this for reading the information in your case.
>>
>> Dominik.
>>
>> On Fri, Sep 25, 2015 at 4:21 PM, Mark Beardsley
>> <ma...@tiscali.co.uk> wrote:
>> > The border is part of the style applied to the cell from POIs point of
>> view.
>> > What you will need to do is recover the style from the cell - call the
>> > getCellStyle() method on the object - and then interrogate that to find
>> out
>> > what type of border has been applied. If you look at the CellStyle
>> class,
>> > you should see that manifest constants have been created that identify
>> the
>> > various attributes and they include THICK_BACKWARD_DIAG and
>> > THIN_FORWARD_DIAG. A simple switch clause should allow you to filter
>> out the
>> > cells that are marked with diagonal borders; it is maybe wise to include
>> > tests for all of the diagonal options unless you are confident in your
>> user
>> > body.
>> >
>> >
>> >
>> > --
>> > View this message in context:
>> http://apache-poi.1045710.n5.nabble.com/Diagonal-border-tp5720338p5720341.html
>> > Sent from the POI - User mailing list archive at Nabble.com.
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>> > For additional commands, e-mail: user-help@poi.apache.org
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>> For additional commands, e-mail: user-help@poi.apache.org
>>
>>
>

Re: Diagonal border

Posted by Bengt Rodehav <be...@rodehav.com>.
Thank you Mark and Dominik. I will try to get this information from the
cell style.

/Bengt

2015-09-25 18:22 GMT+02:00 Dominik Stadler <do...@gmx.at>:

> Hi,
>
> There was a discussion about how to set diagonal border styling a few
> weeks ago, see
> http://mail-archives.apache.org/mod_mbox/poi-user/201508.mbox/browser,
> it describes how to set a diagonal border, maybe you can use some of
> this for reading the information in your case.
>
> Dominik.
>
> On Fri, Sep 25, 2015 at 4:21 PM, Mark Beardsley
> <ma...@tiscali.co.uk> wrote:
> > The border is part of the style applied to the cell from POIs point of
> view.
> > What you will need to do is recover the style from the cell - call the
> > getCellStyle() method on the object - and then interrogate that to find
> out
> > what type of border has been applied. If you look at the CellStyle class,
> > you should see that manifest constants have been created that identify
> the
> > various attributes and they include THICK_BACKWARD_DIAG and
> > THIN_FORWARD_DIAG. A simple switch clause should allow you to filter out
> the
> > cells that are marked with diagonal borders; it is maybe wise to include
> > tests for all of the diagonal options unless you are confident in your
> user
> > body.
> >
> >
> >
> > --
> > View this message in context:
> http://apache-poi.1045710.n5.nabble.com/Diagonal-border-tp5720338p5720341.html
> > Sent from the POI - User mailing list archive at Nabble.com.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> > For additional commands, e-mail: user-help@poi.apache.org
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>

Re: Diagonal border

Posted by Dominik Stadler <do...@gmx.at>.
Hi,

There was a discussion about how to set diagonal border styling a few
weeks ago, see http://mail-archives.apache.org/mod_mbox/poi-user/201508.mbox/browser,
it describes how to set a diagonal border, maybe you can use some of
this for reading the information in your case.

Dominik.

On Fri, Sep 25, 2015 at 4:21 PM, Mark Beardsley
<ma...@tiscali.co.uk> wrote:
> The border is part of the style applied to the cell from POIs point of view.
> What you will need to do is recover the style from the cell - call the
> getCellStyle() method on the object - and then interrogate that to find out
> what type of border has been applied. If you look at the CellStyle class,
> you should see that manifest constants have been created that identify the
> various attributes and they include THICK_BACKWARD_DIAG and
> THIN_FORWARD_DIAG. A simple switch clause should allow you to filter out the
> cells that are marked with diagonal borders; it is maybe wise to include
> tests for all of the diagonal options unless you are confident in your user
> body.
>
>
>
> --
> View this message in context: http://apache-poi.1045710.n5.nabble.com/Diagonal-border-tp5720338p5720341.html
> Sent from the POI - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Diagonal border

Posted by Mark Beardsley <ma...@tiscali.co.uk>.
The border is part of the style applied to the cell from POIs point of view.
What you will need to do is recover the style from the cell - call the
getCellStyle() method on the object - and then interrogate that to find out
what type of border has been applied. If you look at the CellStyle class,
you should see that manifest constants have been created that identify the
various attributes and they include THICK_BACKWARD_DIAG and
THIN_FORWARD_DIAG. A simple switch clause should allow you to filter out the
cells that are marked with diagonal borders; it is maybe wise to include
tests for all of the diagonal options unless you are confident in your user
body.



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Diagonal-border-tp5720338p5720341.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org